浏览代码

🚧 增加导出AI数据脚本

快乐的梦鱼 3 周之前
父节点
当前提交
95bf4879a5
共有 10 个文件被更改,包括 1698 次插入105 次删除
  1. 4 0
      api/CommonContent.ts
  2. 7 9
      api/RequestModules.ts
  3. 0 24
      api/Test.ts
  4. 9 10
      common/config/AppCofig.ts
  5. 1257 26
      package-lock.json
  6. 8 2
      package.json
  7. 323 34
      scripts/ExportToAi/ich.ts
  8. 27 0
      tsconfig.ich.json
  9. 19 0
      tsconfig.node.json
  10. 44 0
      webpack.ich.config.js

+ 4 - 0
api/CommonContent.ts

@@ -182,6 +182,7 @@ export class GetContentListItem extends DataModel<GetContentListItem> {
   content = '!content';
   type = 0;
   keywords ?: string[];
+  images ?: string[];
   flag ?: string[];
   tags ?: string[];
   views = 0;
@@ -268,9 +269,12 @@ export class GetContentDetailItem extends DataModel<GetContentDetailItem> {
   isLike = false;
   isCollect = false;
   content = '';
+  inheritor = '';
   value = '';
   intro = '';
   publishAt = new Date();
+  inheritorsList = [] as GetContentDetailItem[];
+  ichSitesList = [] as GetContentDetailItem[];
   associationMeList = [] as {
     id: number,
     title: string,

+ 7 - 9
api/RequestModules.ts

@@ -6,10 +6,9 @@
  * * 自定义错误报告处理函数。
  */
 
-import AppCofig from "@/common/config/AppCofig";
+import AppCofig, { isDev } from "@/common/config/AppCofig";
 import ApiCofig from "@/common/config/ApiCofig";
 import { 
-  RequestApiConfig,
   RequestApiError, RequestApiResult, type RequestApiErrorType, 
   RequestCoreInstance, RequestOptions, 
   defaultResponseDataGetErrorInfo, defaultResponseDataHandlerCatch, 
@@ -19,9 +18,8 @@ import {
   appendGetUrlParams, 
   appendPostParams,
 } from "@imengyu/imengyu-utils";
-import { logError } from "@/components/error/ErrorReporterIs";
 import type { DataModel, KeyValue, NewDataModel } from "@imengyu/js-request-transform";
-import { useAuthStore } from "@/stores/auth";
+//import { useAuthStore } from "@/stores/auth";
 import { Modal } from "ant-design-vue";
 
 /**
@@ -42,11 +40,11 @@ function matchNotReportMessage(str: string) {
 //请求拦截器
 function requestInceptor(url: string, req: RequestOptions) {
   //获取store中的token,追加到头;
-  const autoStore = useAuthStore();
+  /*const autoStore = useAuthStore();
   if (StringUtils.isNullOrEmpty((req.header as KeyValue).token as string)) {
     req.header['token'] = autoStore.token;
     req.header['__token__'] = autoStore.token;
-  }
+  }*/
   if (req.method == 'GET') {
     //追加GET参数
     url = appendGetUrlParams(url, 'main_body_id', ApiCofig.mainBodyId);
@@ -172,9 +170,9 @@ function responseErrReoprtInceptor<T extends DataModel>(instance: RequestCoreIns
 
 //错误报告处理
 export function reportError<T extends DataModel>(instance: RequestCoreInstance<T>, response: RequestApiError | Error) {
-  if (import.meta.env.DEV) {
+  if (isDev) {
     if (response instanceof RequestApiError) {
-      logError({
+      (globalThis as any).$error({
         message: `请求错误 ${response.apiName} : ${response.errorMessage}`,
         detail: response.toString() +
           '\r\n请求接口:' + response.apiName +
@@ -186,7 +184,7 @@ export function reportError<T extends DataModel>(instance: RequestCoreInstance<T
         type: 'error',
       });
     } else {
-      logError({
+      (globalThis as any).$error({
         message: '错误报告 代码错误',
         detail: response?.stack || ('' + response),
         type: 'error',

+ 0 - 24
api/Test.ts

@@ -1,24 +0,0 @@
-import { DataModel } from '@imengyu/js-request-transform';
-import { DefaultRequestModule } from '../common/request';
-
-export class Test extends DataModel {
-  public constructor() {
-    super();
-    this._convertTable = {
-    };
-  }
-}
-
-export class TestApi extends DefaultRequestModule<Test> {
-
-  constructor() {
-    super();
-    this.config.modelClassCreator = Test;
-  }
-
-  getDataTest() {
-    return this.get('http://127.0.0.1', 'getDataTest');
-  }
-}
-
-export default new TestApi();

+ 9 - 10
common/config/AppCofig.ts

@@ -5,16 +5,15 @@
 export default {
   version: '0.0.1',
 }
-
-/**
- * 图炫地图配置
- */
-export function configAiMap() {
-  aimap.accessToken = 'UFJGhyFdSzvm0ZbecYglp6CssgnDK7PZ';
-  aimap.baseApiUrl = 'https://location-dev.newayz.com';
-}
-
 /**
  * 是否是开发环境
  */
-export const isDev = import.meta.env.DEV;
+export const isDev = (() => {
+  /*if (typeof import.meta !== 'undefined' && import.meta.env) {
+    return import.meta.env.DEV;
+  }*/
+  if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV) {
+    return process.env.NODE_ENV === 'development';
+  }
+  return false;
+})();

文件差异内容过多而无法显示
+ 1257 - 26
package-lock.json


+ 8 - 2
package.json

@@ -11,7 +11,8 @@
     "nuxt-postinstall": "nuxt prepare",
     "dev": "nuxt dev",
     "build": "nuxt build",
-    "updater": "node scripts/UpdateScript/index.mjs"
+    "updater": "node scripts/UpdateScript/index.mjs",
+    "build:ich": "webpack --config webpack.ich.config.js"
   },
   "dependencies": {
     "@ant-design-vue/nuxt": "^1.4.6",
@@ -38,6 +39,7 @@
     "@inquirer/prompts": "^7.5.3",
     "@tsconfig/node22": "^22.0.1",
     "@types/node": "^22.14.0",
+    "@types/webpack": "^5.28.5",
     "@vitejs/plugin-vue": "^5.2.3",
     "@vitejs/plugin-vue-jsx": "^4.1.2",
     "@vue/tsconfig": "^0.7.0",
@@ -49,9 +51,13 @@
     "npm-run-all2": "^7.0.2",
     "sass": "^1.87.0",
     "terser": "^5.44.1",
+    "ts-loader": "^9.5.4",
+    "ts-node": "^10.9.2",
     "typescript": "~5.8.0",
     "vite": "^6.2.4",
     "vite-plugin-vue-devtools": "^7.7.2",
-    "vue-tsc": "^2.2.8"
+    "vue-tsc": "^2.2.8",
+    "webpack": "^5.104.1",
+    "webpack-cli": "^6.0.1"
   }
 }

+ 323 - 34
scripts/ExportToAi/ich.ts

@@ -1,12 +1,17 @@
 
 import { writeFile } from 'fs/promises';
-import { GetContentListParams, type GetContentDetailItem, type GetContentListItem } from '~/api/CommonContent';
-import ProjectsContent from '~/api/inheritor/ProjectsContent';
+import CommonContent, { GetContentListParams, type GetContentDetailItem, type GetContentListItem } from '../../api/CommonContent';
+import ProjectsContent from '../../api/inheritor/ProjectsContent';
+import InheritorContent from '../../api/inheritor/InheritorContent';
+import SeminarContent from '../../api/inheritor/SeminarContent';
+import UnitContent from '../../api/inheritor/UnitContent';
+import UnmoveableContent from '../../api/inheritor/UnmoveableContent';
+import path from 'path';
+import fs from 'fs';
+import { argv, cwd } from 'process';
 
 const data = [] as Array<GetContentListItem & { detail?: GetContentDetailItem }>;
 
-const markdownText = ref('');
-
 // HTML转Markdown的简单实现
 function htmlToMarkdown(html: string): string {
   if (!html) return '';
@@ -57,24 +62,37 @@ function htmlToMarkdown(html: string): string {
   return html.trim();
 }
 // 生成Markdown文本
-function generateMarkdown(): string {
-  let md = '';
+async function generateMarkdownIch(subDir: string, type: string) {
   
-  data.forEach((item, index) => {
-    if (index > 0) {
-      md += '\n\n---\n\n';
-    }
+  for (const item of data) {
     
+    let md = '';
     // 基本信息
     md += `# ${item.title}\n\n`;
-    md += `${item.desc || '无描述'}\n\n`;
+    if (item.desc)
+      md += `${item.desc}\n\n`;
     md += `## 基本信息\n\n`;
-    md += `- 非遗级别: ${item.levelText || '无'}\n`;
-    md += `- 非遗类别: ${item.ichTypeText || '无'}\n`;
-    md += `- 地区: ${item.district || '无'}\n`;
-    md += `- 批次: ${item.batchText || '无'}\n`;
-    md += `- 保护单位: ${item.unit || '无'}\n\n`;
+    md += `类型:${type}\n\n`;
+
+    function addRow(key: string, value: any) {
+      if (value)
+        md += `- ${key}: ${value}\n`;
+    }
+
+    addRow('级别', item.levelText);
+    addRow('类别', item.ichTypeText);
+    addRow('地区', item.regionText);
+    addRow('批次', item.batchText);
+    addRow('保护单位', item.unit);
+    addRow('地址', item.address);
+    addRow('字号名称', item.fontName);
+    addRow('认定类型', item.brandType);
+    addRow('其他级别保护单位', item.detail?.otherLevel && item.detail.otherLevel.length > 0 ? `${item.detail.otherLevel.length}个` : '');
     
+    md += `\n## 数据库索引ID\n\n`;
+    md += `- 类型: intangible\n`;
+    md += `- ID: ${item.id || '无'}\n\n`;
+
     // 图片
     if (item.images && item.images.length > 0) {
       md += `## 图片\n\n`;
@@ -85,22 +103,45 @@ function generateMarkdown(): string {
     
     // 详细信息
     if (item.detail) {
+      const detail = item.detail as GetContentDetailItem;
       // 简介
-      if (item.detail.intro) {
+      if (detail.intro) {
         md += `## 简介\n\n`;
-        md += htmlToMarkdown(item.detail.intro) + '\n\n';
+        md += htmlToMarkdown(detail.intro) + '\n\n';
+      }
+      // 内容
+      if (detail.content) {
+        md += `## 内容\n\n`;
+        md += htmlToMarkdown(detail.content) + '\n\n';
       }
+      // 传承谱系
+      if (detail.pedigree) {
+        md += `## 传承谱系\n\n`;
+        md += htmlToMarkdown(detail.pedigree as string) + '\n\n';
+      }
+      // 视频
+      if (detail.video) {
+        md += `## 视频\n\n`;
+        md += `[视频](${detail.video})\n\n`;
+      }
+      if (detail.publishVideo)
+        md += `[介绍视频](${detail.publishVideo})\n\n`;
       
       // 传承人
-      if (item.detail.inheritorsList && item.detail.inheritorsList.length > 0) {
+      if (detail.inheritorsList && detail.inheritorsList.length > 0) {
         md += `## 相关传承人\n\n`;
-        if (item.detail.inheritor) {
-          md += htmlToMarkdown(item.detail.inheritor) + '\n\n';
+        if (detail.inheritor) {
+          md += htmlToMarkdown(detail.inheritor) + '\n\n';
         }
         
-        item.detail.inheritorsList.forEach(inheritor => {
+        detail.inheritorsList.forEach(inheritor => {
           md += `### ${inheritor.title}\n\n`;
           md += `级别:${inheritor.levelLext || '无'}\n\n`;
+
+          md += `#### 数据库索引ID\n\n`;
+          md += `- 类型: inheritor\n`;
+          md += `- ID: ${inheritor.id || '无'}\n\n`;
+
           if (inheritor.image) {
             md += `![传承人头像](${inheritor.image})\n\n`;
           }
@@ -108,29 +149,277 @@ function generateMarkdown(): string {
       }
       
       // 传习所
-      if (item.detail.ichSitesList && item.detail.ichSitesList.length > 0) {
+      if (detail.ichSitesList && detail.ichSitesList.length > 0) {
         md += `## 相关传习所\n\n`;
-        item.detail.ichSitesList.forEach(site => {
+        detail.ichSitesList.forEach(site => { 
           md += `### ${site.title}\n\n`;
           md += `级别:${site.levelLext || '无'}\n\n`;
           md += `地址:${site.address || '无'}\n\n`;
+
+          md += `#### 数据库索引ID\n\n`;
+          md += `- 类型: seminar\n`;
+          md += `- ID: ${site.id || '无'}\n\n`;
+
           if (site.image) {
             md += `![传习所图片](${site.image})\n\n`;
           }
         });
       }
+
+      // 同级别项目
+      if (detail.otherLevel && detail.otherLevel.length > 0) {
+        md += `## 其他级别非遗项目\n\n`;
+        detail.otherLevel.forEach(project => { 
+          md += `### ${project.title}\n\n`;
+          md += `级别:${project.levelLext || '无'}\n\n`;
+          md += `保护单位:${project.unit || '无'}\n\n`;
+
+          md += `#### 数据库索引ID\n\n`;
+          md += `- 类型: intangible\n`;
+          md += `- ID: ${project.id || '无'}\n\n`;
+        });
+      }
     }
-  });
+
+    await writeFile(path.join(subDir, `${item.id}.md`), md);
+  }
+}
+async function generateMarkdownInheritor(subDir: string) {
   
-  return md;
+  for (const item of data) {
+    
+    let md = '';
+    // 基本信息
+    md += `# ${item.title}\n\n`;
+    if (item.desc)
+      md += `${item.desc}\n\n`;
+    md += `## 基本信息\n\n`;
+    md += `类型:非遗传承人\n\n`;
+
+    function addRow(key: string, value: any) {
+      if (value)
+        md += `- ${key}: ${value}\n`;
+    }
+    addRow('民族', item.detail?.nation);
+    addRow('性别', item.detail?.gender == '1'? '男' : '女');
+    addRow('出生日期', item.detail?.dateBirth);
+    addRow('出生地区', item.detail?.birthplace);
+    addRow('单位', item.detail?.unit);
+    addRow('传承项目', item.detail?.associationMeList[0]?.title);
+    addRow('传承人级别', item.detail?.batchText);
+    addRow('公布批次', item.detail?.batchText);
+
+    md += `\n## 数据库索引ID\n\n`;
+    md += `- 类型: inheritor\n`;
+    md += `- ID: ${item.id || '无'}\n\n`;
+
+    // 图片
+    if (item.images && item.images.length > 0) {
+      md += `## 图片\n\n`;
+      item.images.forEach(image => {
+        md += `![${item.title}图片](${image})\n\n`;
+      });
+    }
+    
+    // 详细信息
+    if (item.detail) {
+      const detail = item.detail as GetContentDetailItem;
+      // 简介
+      if (detail.intro) {
+        md += `## 简介\n\n`;
+        md += htmlToMarkdown(detail.intro) + '\n\n';
+      }
+      if (detail.content) {
+        md += `## 详情\n\n`;
+        md += htmlToMarkdown(detail.content) + '\n\n';
+      }
+      // 奖项
+      if (detail.prize) {
+        md += `## 奖项\n\n`;
+        md += htmlToMarkdown(detail.prize as string) + '\n\n';
+      }
+      // 相关项目
+      if (detail.associationMeList && detail.associationMeList.length > 0) {
+        md += `## 相关项目\n\n`;        
+        detail.associationMeList.forEach(inheritor => {
+          md += `### ${inheritor.title}\n\n`;
+
+          md += `#### 数据库索引ID\n\n`;
+          md += `- 类型: intangible\n`;
+          md += `- ID: ${inheritor.id || '无'}\n\n`;
+        });
+      }   
+      // 传习所
+      if (detail.ichSitesList && detail.ichSitesList.length > 0) {
+        md += `## 相关传习所\n\n`;
+        detail.ichSitesList.forEach(site => { 
+          md += `### ${site.title}\n\n`;
+          md += `级别:${site.levelLext || '无'}\n\n`;
+          md += `地址:${site.address || '无'}\n\n`;
+
+          md += `##### 数据库索引ID\n\n`;
+          md += `- 类型: seminar\n`;
+          md += `- ID: ${site.id || '无'}\n\n`;
+
+          if (site.image) {
+            md += `![传习所图片](${site.image})\n\n`;
+          }
+        });
+      }
+    }
+
+    await writeFile(path.join(subDir, `${item.id}.md`), md);
+  }
 }
+async function generateMarkdownArtifact(subDir: string) {
+  
+  for (const item of data) {
+    
+    let md = '';
+    // 基本信息
+    md += `# ${item.title}\n\n`;
+    if (item.desc)
+      md += `${item.desc}\n\n`;
+    md += `## 基本信息\n\n`;
+    md += `类型:非遗传承人\n\n`;
+
+    function addRow(key: string, value: any) {
+      if (value)
+        md += `- ${key}: ${value}\n`;
+    }
+    addRow('开放时间', item.detail?.openStatusText);
+    addRow('年代', item.age);
+    addRow('级别', item.levelText);
+    addRow('所属区域', item.regionText);
+    addRow('文物类型', item.crTypeText);
+    addRow('单位', item.detail?.unit);
+
+    md += `\n## 数据库索引ID\n\n`;
+    md += `- 类型: artifact\n`;
+    md += `- ID: ${item.id || '无'}\n\n`;
 
-(await ProjectsContent.getContentList(new GetContentListParams(), 1, 1000)).list.forEach(item => {
-  data.push(item);
-});
-for (const item of data) {
-  item.detail = (await ProjectsContent.getContentDetail(item.id)) as GetContentDetailItem;
+    // 图片
+    if (item.images && item.images.length > 0) {
+      md += `## 图片\n\n`;
+      item.images.forEach(image => {
+        md += `![${item.title}图片](${image})\n\n`;
+      });
+    }
+    if (item.video) {
+      md += `## 视频\n\n`;
+      md += `![${item.title}视频](${item.video})\n\n`;
+    }
+    
+    // 详细信息
+    if (item.detail) {
+      const detail = item.detail as GetContentDetailItem;
+      // 简介
+      if (detail.intro) {
+        md += `## 简介\n\n`;
+        md += htmlToMarkdown(detail.intro) + '\n\n';
+      }
+      if (detail.content) {
+        md += `## 详情\n\n`;
+        md += htmlToMarkdown(detail.content) + '\n\n';
+      }
+      // 奖项
+      if (detail.protectedArea) {
+        md += `## 保护范围\n\n`;
+        md += htmlToMarkdown(detail.protectedArea as string) + '\n\n';
+      }
+      if (detail.environment) {
+        md += `## 建筑环境\n\n`;
+        md += htmlToMarkdown(detail.environment as string) + '\n\n';
+      }
+      if (detail.价值评估) {
+        md += `## 价值评估\n\n`;
+        md += htmlToMarkdown(detail.价值评估 as string) + '\n\n';
+      }
+    }
+
+    await writeFile(path.join(subDir, `${item.id}.md`), md);
+  }
 }
-// 生成Markdown文本
-markdownText.value = generateMarkdown();
-await writeFile('非遗项目数据.md', markdownText.value);
+
+async function main() {
+
+  const type = argv[2];
+
+  function makeDir(nanme: string) {
+    const dir = path.join(cwd(), `dist/${nanme}`);
+    if (!fs.existsSync(dir)) 
+      fs.mkdirSync(dir, { recursive: true });
+    return dir;
+  }
+
+  switch (type) {
+    case 'ich': {
+      const dir = makeDir('ich');
+      (await ProjectsContent.getContentList(new GetContentListParams(), 1, 1000)).list.forEach(item => {
+        data.push(item);
+      });
+      for (const item of data)
+        item.detail = (await ProjectsContent.getContentDetail(item.id)) as GetContentDetailItem;
+      generateMarkdownIch(dir, '非遗项目');
+      break;
+    }
+    case 'seminar': {
+      const dir = makeDir('seminar');
+      (await SeminarContent.getContentList(new GetContentListParams(), 1, 1000)).list.forEach(item => {
+        data.push(item);
+      });
+      for (const item of data)
+        item.detail = (await SeminarContent.getContentDetail(item.id)) as GetContentDetailItem;
+      generateMarkdownIch(dir, '非遗传习所');
+      break;
+    }
+    case 'old': {
+      const dir = makeDir('old');
+      (await CommonContent.getContentList(new GetContentListParams()
+        .setModelId(17)
+        .setMainBodyColumnId(312)
+      , 1, 1000)).list.forEach(item => {
+        data.push(item);
+      });
+      for (const item of data)
+        item.detail = (await CommonContent.getContentDetail(item.id)) as GetContentDetailItem;
+      generateMarkdownIch(dir, '老字号');
+      break;
+    }
+    case 'unit': {
+      const dir = makeDir('unit');
+      (await UnitContent.getContentList(new GetContentListParams(), 1, 1000)).list.forEach(item => {
+        data.push(item);
+      });
+      for (const item of data)
+        item.detail = (await UnitContent.getContentDetail(item.id)) as GetContentDetailItem;
+      generateMarkdownIch(dir, '非遗保护单位');
+      break;
+    }
+    case 'inheritor': {
+      const dir = makeDir('inheritor');
+      (await InheritorContent.getContentList(new GetContentListParams(), 1, 1000)).list.forEach(item => {
+        data.push(item);
+      });
+      for (const item of data)
+        item.detail = (await InheritorContent.getContentDetail(item.id)) as GetContentDetailItem;
+      generateMarkdownInheritor(dir);
+      break;
+    }
+    case 'artifact': {
+      const dir = makeDir('artifact');
+      (await UnmoveableContent.getContentList(new GetContentListParams(), 1, 1000)).list.forEach(item => {
+        data.push(item);
+      });
+      for (const item of data)
+        item.detail = (await UnmoveableContent.getContentDetail(item.id)) as GetContentDetailItem;
+      generateMarkdownArtifact(dir);
+      break;
+    }
+    default:
+      console.log('不支持的类型');
+      break;
+  }
+}
+
+main();

+ 27 - 0
tsconfig.ich.json

@@ -0,0 +1,27 @@
+{
+  "extends": "./tsconfig.node.json",
+  "compilerOptions": {
+    "target": "ES2020",
+    "module": "ES2020",
+    "moduleResolution": "node",
+    "esModuleInterop": true,
+    "skipLibCheck": true,
+    "strict": true,
+    "outDir": "./dist",
+    "lib": ["ES2020"],
+    "baseUrl": ".",
+    "paths": {
+      "@/*": ["./*"]
+    },
+    "resolveJsonModule": true,
+    "allowSyntheticDefaultImports": true,
+    "experimentalDecorators": true,
+    "emitDecoratorMetadata": true
+  },
+  "include": [
+    "scripts/ExportToAi/**/*", "api/**/*"
+  ],
+  "exclude": [
+    "node_modules"
+  ]
+}

+ 19 - 0
tsconfig.node.json

@@ -0,0 +1,19 @@
+{
+  "compilerOptions": {
+    "target": "ES2020",
+    "module": "CommonJS",
+    "moduleResolution": "node",
+    "esModuleInterop": true,
+    "skipLibCheck": true,
+    "strict": true,
+    "outDir": "./dist",
+    "lib": ["ES2020"],
+    "baseUrl": ".",
+    "paths": {
+      "@/*": ["./*"]
+    },
+    "resolveJsonModule": true
+  },
+  "include": ["scripts/ExportToAi/**/*"],
+  "exclude": ["node_modules"]
+}

+ 44 - 0
webpack.ich.config.js

@@ -0,0 +1,44 @@
+import path from 'path';
+import { fileURLToPath } from 'url';
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+
+export default {
+  entry: './scripts/ExportToAi/ich.ts',
+  target: 'node',
+  mode: 'production',
+  output: {
+    path: path.resolve(__dirname, 'dist'),
+    filename: 'ich-bundle.cjs',
+    clean: true,
+  },
+  resolve: {
+    extensions: ['.ts', '.js'],
+    alias: {
+      '@': path.resolve(__dirname),
+    }
+  },
+  module: {
+    rules: [
+      {
+        test: /\.ts$/,
+        use: {
+          loader: 'ts-loader',
+          options: {
+            configFile: 'tsconfig.ich.json',
+          },
+        },
+        exclude: /node_modules/,
+      },
+    ],
+  },
+  externals: {
+    fs: 'commonjs fs',
+    path: 'commonjs path',
+  },
+  node: {
+    __dirname: true,
+    __filename: true,
+  },
+};