Pārlūkot izejas kodu

feat: 调整打包体积限制提示,使用tiny-pinyin替换了pinyin-pro,减小打包体积;

liujia 1 mēnesi atpakaļ
vecāks
revīzija
30bd39bd83
4 mainītis faili ar 42 papildinājumiem un 14 dzēšanām
  1. 1 1
      package.json
  2. 8 8
      pnpm-lock.yaml
  3. 14 5
      src/views/community/components/add/index.vue
  4. 19 0
      vite.config.ts

+ 1 - 1
package.json

@@ -40,8 +40,8 @@
     "nanoid": "^5.1.5",
     "pinia": "^3.0.3",
     "pinia-plugin-persistedstate": "^4.4.1",
-    "pinyin-pro": "^3.26.0",
     "three": "^0.179.1",
+    "tiny-pinyin": "^1.3.2",
     "vue": "^3.5.17",
     "vue-router": "^4.5.1"
   },

+ 8 - 8
pnpm-lock.yaml

@@ -53,12 +53,12 @@ importers:
       pinia-plugin-persistedstate:
         specifier: ^4.4.1
         version: 4.4.1(pinia@3.0.3(typescript@5.8.3)(vue@3.5.17(typescript@5.8.3)))
-      pinyin-pro:
-        specifier: ^3.26.0
-        version: 3.26.0
       three:
         specifier: ^0.179.1
         version: 0.179.1
+      tiny-pinyin:
+        specifier: ^1.3.2
+        version: 1.3.2
       vue:
         specifier: ^3.5.17
         version: 3.5.17(typescript@5.8.3)
@@ -2356,9 +2356,6 @@ packages:
       typescript:
         optional: true
 
-  pinyin-pro@3.26.0:
-    resolution: {integrity: sha512-HcBZZb0pvm0/JkPhZHWA5Hqp2cWHXrrW/WrV+OtaYYM+kf35ffvZppIUuGmyuQ7gDr1JDJKMkbEE+GN0wfMoGg==}
-
   pkg-types@1.3.1:
     resolution: {integrity: sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ==}
 
@@ -2680,6 +2677,9 @@ packages:
     resolution: {integrity: sha512-B71/4oyj61iNH0KeCamLuE2rmKuTO5byTOSVwECM5FA7TiAiAW+UqTKZ9ERueC4qvgSttUhdmq1mXC3kJqGX7A==}
     engines: {node: '>=12.22'}
 
+  tiny-pinyin@1.3.2:
+    resolution: {integrity: sha512-uHNGu4evFt/8eNLldazeAM1M8JrMc1jshhJJfVRARTN3yT8HEEibofeQ7QETWQ5ISBjd6fKtTVBCC/+mGS6FpA==}
+
   tinyglobby@0.2.14:
     resolution: {integrity: sha512-tX5e7OM1HnYr2+a2C/4V0htOcSQcoSTH9KgJnVvNm5zm/cyEWKJ7j7YutsH9CxMdtOkkLFy2AHrMci9IM8IPZQ==}
     engines: {node: '>=12.0.0'}
@@ -5348,8 +5348,6 @@ snapshots:
     optionalDependencies:
       typescript: 5.8.3
 
-  pinyin-pro@3.26.0: {}
-
   pkg-types@1.3.1:
     dependencies:
       confbox: 0.1.8
@@ -5728,6 +5726,8 @@ snapshots:
 
   throttle-debounce@5.0.2: {}
 
+  tiny-pinyin@1.3.2: {}
+
   tinyglobby@0.2.14:
     dependencies:
       fdir: 6.4.6(picomatch@4.0.2)

+ 14 - 5
src/views/community/components/add/index.vue

@@ -144,7 +144,7 @@ import { message, type FormInstance } from 'ant-design-vue'
 import * as tenantApi from '@/api/tenant'
 import pcdCascader from '../pcdCascader/index.vue'
 import { InfoCircleOutlined } from '@ant-design/icons-vue'
-import { pinyin } from 'pinyin-pro'
+import TinyPinyin from 'tiny-pinyin'
 import * as systemApi from '@/api/system'
 import { useDict } from '@/hooks/useDict'
 
@@ -320,14 +320,23 @@ const cancel = () => {
 // 添加小区
 const addCommunity = async () => {
   try {
-    const tenantCodes = pinyin(formState.tenantName, { toneType: 'none', type: 'array' })
-      .map((word) => word.charAt(0))
-      .join('')
+    const getTenantCode = (name: string): string => {
+      if (!TinyPinyin.isSupported()) return ''
+      return name
+        .split('')
+        .map((char) => {
+          const py = TinyPinyin.convertToPinyin(char)
+          return py.charAt(0)
+        })
+        .join('')
+    }
+
+    const tenantCodes = getTenantCode(formState.tenantName)
     const res = await tenantApi.queryTenantAdd({
       tenantId: formState.tenantId || '',
       tenantCode: tenantCodes,
       tenantName: formState.tenantName,
-      tenantType: formState.tenantType! || '', // 'residential_property'
+      tenantType: formState.tenantType! || '',
       province: formState.pcdStrs[0] || '',
       city: formState.pcdStrs[1] || '',
       district: formState.pcdStrs[2] || '',

+ 19 - 0
vite.config.ts

@@ -67,5 +67,24 @@ export default defineConfig(({ mode }) => {
       },
       cors: true,
     },
+    build: {
+      chunkSizeWarningLimit: 1000,
+
+      rollupOptions: {
+        output: {
+          manualChunks(id) {
+            if (id.includes('node_modules')) {
+              if (id.includes('three')) return 'threejs'
+              if (id.includes('echarts')) return 'echarts'
+              if (id.includes('ant-design-vue')) return 'antdv'
+              if (id.includes('tiny-pinyin')) return 'pinyin'
+              if (id.includes('lodash-es')) return 'lodash'
+              if (id.includes('vue')) return 'vue'
+              return 'vendor'
+            }
+          },
+        },
+      },
+    },
   }
 })