Ver código fonte

优化:修改dev工具脚本

haiyang 1 semana atrás
pai
commit
98b90f55b1
5 arquivos alterados com 183 adições e 167 exclusões
  1. 2 1
      env/.env
  2. 1 0
      package.json
  3. 66 56
      scripts/open-dev-tools.js
  4. 13 9
      src/pages/home/home.vue
  5. 101 101
      uno.config.ts

+ 2 - 1
env/.env

@@ -10,7 +10,6 @@ VITE_WX_APPID = 'wx23776edbfe90d642'
 VITE_APP_PUBLIC_BASE=/
 
 # 后台请求地址
-#VITE_SERVER_BASEURL = 'http://192.168.1.28:8082/jeecg-boot'
 VITE_SERVER_BASEURL = 'https://life.baoxianzhanggui.com/locallive-pro-java'
 # 后台静态资源请求地址
 VITE_SERVER_RESOURCE_BASEURL ='/sys/common/static'
@@ -32,3 +31,5 @@ VITE_AUTH_MODE = 'single'
 # 原生插件资源复制开关,控制是否启用 copy-native-resources 插件
 VITE_COPY_NATIVE_RES_ENABLE = false
 
+#微信开发者工具项目路径
+VITE_WECHAT_DEV_TOOL_PROJECT_PATH = 'E:\\developmentKit\\WeChatDeveloperTools\\微信web开发者工具'

+ 1 - 0
package.json

@@ -163,6 +163,7 @@
     "@vue/tsconfig": "^0.1.3",
     "autoprefixer": "^10.4.20",
     "cross-env": "^10.0.0",
+    "dotenv": "^17.2.3",
     "eslint": "^9.31.0",
     "eslint-plugin-format": "^1.0.1",
     "husky": "^9.1.7",

+ 66 - 56
scripts/open-dev-tools.js

@@ -2,82 +2,92 @@ import { exec } from 'node:child_process'
 import fs from 'node:fs'
 import path from 'node:path'
 import process from 'node:process'
+import dotenv from 'dotenv'
+
+dotenv.config({ path: path.resolve(process.cwd(), 'env/.env') })
 
 /**
  * 打开开发者工具
  */
 function _openDevTools() {
-  const platform = process.platform // darwin, win32, linux
-  const { UNI_PLATFORM } = process.env //  mp-weixin, mp-alipay
+    const platform = process.platform // darwin, win32, linux
+    const { UNI_PLATFORM } = process.env //  mp-weixin, mp-alipay
 
-  const uniPlatformText = UNI_PLATFORM === 'mp-weixin' ? '微信小程序' : UNI_PLATFORM === 'mp-alipay' ? '支付宝小程序' : '小程序'
+    const uniPlatformText = UNI_PLATFORM === 'mp-weixin' ? '微信小程序' : UNI_PLATFORM === 'mp-alipay' ? '支付宝小程序' : '小程序'
 
-  // 项目路径(构建输出目录)
-  const projectPath = path.resolve(process.cwd(), `dist/dev/${UNI_PLATFORM}`)
+    // 项目路径(构建输出目录)
+    const projectPath = path.resolve(process.cwd(), `dist/dev/${UNI_PLATFORM}`)
 
-  // 检查构建输出目录是否存在
-  if (!fs.existsSync(projectPath)) {
-    console.log(`❌ ${uniPlatformText}构建目录不存在:`, projectPath)
-    return
-  }
+    // 检查构建输出目录是否存在
+    if (!fs.existsSync(projectPath)) {
+        console.log(`❌ ${uniPlatformText}构建目录不存在:`, projectPath)
+        return
+    }
 
-  console.log(`🚀 正在打开${uniPlatformText}开发者工具...`)
+    console.log(`🚀 正在打开${uniPlatformText}开发者工具...`)
 
-  // 根据不同操作系统执行不同命令
-  let command = ''
+    // 根据不同操作系统执行不同命令
+    let command = ''
 
-  if (platform === 'darwin') {
-    // macOS
-    if (UNI_PLATFORM === 'mp-weixin') {
-      command = `/Applications/wechatwebdevtools.app/Contents/MacOS/cli -o "${projectPath}"`
+    if (platform === 'darwin') {
+        // macOS
+        if (UNI_PLATFORM === 'mp-weixin') {
+            command = `/Applications/wechatwebdevtools.app/Contents/MacOS/cli -o --project "${projectPath}"`
+        }
+        else if (UNI_PLATFORM === 'mp-alipay') {
+            command = `/Applications/小程序开发者工具.app/Contents/MacOS/小程序开发者工具 --p "${projectPath}"`
+        }
     }
-    else if (UNI_PLATFORM === 'mp-alipay') {
-      command = `/Applications/小程序开发者工具.app/Contents/MacOS/小程序开发者工具 --p "${projectPath}"`
+    else if (platform === 'win32' || platform === 'win64') {
+        // Windows
+        if (UNI_PLATFORM === 'mp-weixin') {
+            // 获取微信开发者工具路径,添加默认值或错误处理
+            const wechatDevToolPath = process.env.VITE_WECHAT_DEV_TOOL_PROJECT_PATH || 'C:\\Program Files (x86)\\Tencent\\微信web开发者工具'
+            if (!wechatDevToolPath) {
+                console.log('❌ 未配置微信开发者工具路径,请在 .env 文件中设置 VITE_WECHAT_DEV_TOOL_PROJECT_PATH')
+                return
+            }
+            const cliPath = path.join(wechatDevToolPath, 'cli.bat')
+            command = `${cliPath} open --project "${projectPath}"`
+        }
     }
-  }
-  else if (platform === 'win32' || platform === 'win64') {
-    // Windows
-    if (UNI_PLATFORM === 'mp-weixin') {
-      command = `E:\developmentKit\WeChatDeveloperTools\微信web开发者工具\cli.bat -o "${projectPath}"`
+    else {
+        // Linux 或其他系统
+        console.log('❌ 当前系统不支持自动打开微信开发者工具')
+        return
     }
-  }
-  else {
-    // Linux 或其他系统
-    console.log('❌ 当前系统不支持自动打开微信开发者工具')
-    return
-  }
 
-  exec(command, (error, stdout, stderr) => {
-    if (error) {
-      console.log(`❌ 打开${uniPlatformText}开发者工具失败:`, error.message)
-      console.log(`💡 请确保${uniPlatformText}开发者工具服务端口已启用`)
-      console.log(`💡 可以手动打开${uniPlatformText}开发者工具并导入项目:`, projectPath)
-      return
-    }
+    exec(command, (error, stdout, stderr) => {
+        if (error) {
+            console.log(`❌ 打开${uniPlatformText}开发者工具失败:`, error.message)
+            console.log(`💡 请确保${uniPlatformText}开发者工具服务端口已启用`)
+            console.log(`💡 可以手动打开${uniPlatformText}开发者工具并导入项目:`, projectPath)
+            return
+        }
 
-    if (stderr) {
-      console.log('⚠️ 警告:', stderr)
-    }
+        if (stderr) {
+            console.log('⚠️ 警告:', stderr)
+        }
 
-    console.log(`✅ ${uniPlatformText}开发者工具已打开`)
+        console.log(`✅ ${uniPlatformText}开发者工具已打开`)
 
-    if (stdout) {
-      console.log(stdout)
-    }
-  })
+        if (stdout) {
+            console.log(stdout)
+        }
+    })
 }
 
 export default function openDevTools() {
-  // 首次构建标记
-  let isFirstBuild = true
+    // 首次构建标记
+    let isFirstBuild = true
 
-  return {
-    name: 'uni-devtools',
-    writeBundle() {
-      if (isFirstBuild && process.env.UNI_PLATFORM?.includes('mp')) {
-        isFirstBuild = false
-        _openDevTools()
-      }
-    },
-  }
+    return {
+        name: 'uni-devtools',
+        writeBundle() {
+            if (isFirstBuild && process.env.UNI_PLATFORM?.includes('mp')) {
+                isFirstBuild = false
+                _openDevTools()
+            }
+        },
+    }
 }

+ 13 - 9
src/pages/home/home.vue

@@ -68,8 +68,13 @@ onShareAppMessage(() => {
 })
 
 // 分享到朋友圈生命周期函数
-onShareTimeline(async () => {
-    return await getTimelineShareConfig()
+onShareTimeline(() => {
+    const promise = new Promise((resolve, reject) => {
+        getTimelineShareConfig().then(resolve).catch(reject)
+    })
+    return {
+        promise,
+    }
 })
 
 // #endif
@@ -80,8 +85,6 @@ onShow((options) => {
     // 登录后查询收益数据
     if (hasLogin.value) {
         Promise.allSettled([getAccountCountRequest(), getCouponSituationRequest()])
-        // getAccountCountRequest()
-        // getCouponSituationRequest()
     }
 })
 
@@ -128,12 +131,13 @@ function toCouponRedemptionList(state) {
 
 async function onRefresh() {
     refreshing.value = true
-    await userStore.fetchUserInfo()
     await couponStore.getCouponListByType()
-
-    setTimeout(() => {
-        refreshing.value = false
-    }, 1000)
+    if (hasLogin.value) {
+        await userStore.fetchUserInfo()
+        await getAccountCountRequest()
+        await getCouponSituationRequest()
+    }
+    refreshing.value = false
 }
 </script>
 

+ 101 - 101
uno.config.ts

@@ -1,5 +1,5 @@
 import type {
-  Preset,
+    Preset,
 } from 'unocss'
 import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders'
 
@@ -8,112 +8,112 @@ import { presetUni } from '@uni-helper/unocss-preset-uni'
 // @see https://unocss.dev/presets/legacy-compat
 import { presetLegacyCompat } from '@unocss/preset-legacy-compat'
 import {
-  defineConfig,
-  presetIcons,
-  transformerDirectives,
-  transformerVariantGroup,
+    defineConfig,
+    presetIcons,
+    transformerDirectives,
+    transformerVariantGroup,
 } from 'unocss'
 
 export default defineConfig({
-  presets: [
-    presetUni({
-      attributify: false,
-    }),
-    presetIcons({
-      scale: 1.2,
-      warn: true,
-      extraProperties: {
-        'display': 'inline-block',
-        'vertical-align': 'middle',
-      },
-      collections: {
-        // 注册本地 SVG 图标集合, 从本地文件系统加载图标
-        // 在 './src/static/my-icons' 目录下的所有 svg 文件将被注册为图标,
-        // my-icons 是图标集合名称,使用 `i-my-icons-图标名` 调用
-        'my-icons': FileSystemIconLoader(
-          './src/static/my-icons',
-          // 可选的,你可以提供一个 transform 回调来更改每个图标
-          (svg) => {
-            let svgStr = svg
+    presets: [
+        presetUni({
+            attributify: false,
+        }),
+        presetIcons({
+            scale: 1.2,
+            warn: true,
+            extraProperties: {
+                'display': 'inline-block',
+                'vertical-align': 'middle',
+            },
+            collections: {
+                // 注册本地 SVG 图标集合, 从本地文件系统加载图标
+                // 在 './src/static/my-icons' 目录下的所有 svg 文件将被注册为图标,
+                // my-icons 是图标集合名称,使用 `i-my-icons-图标名` 调用
+                'my-icons': FileSystemIconLoader(
+                    './src/static/my-icons',
+                    // 可选的,你可以提供一个 transform 回调来更改每个图标
+                    (svg) => {
+                        let svgStr = svg
 
-            // 如果 SVG 文件未定义 `fill` 属性,则默认填充 `currentColor`, 这样图标颜色会继承文本颜色,方便在不同场景下适配
-            svgStr = svgStr.includes('fill="') ? svgStr : svgStr.replace(/^<svg /, '<svg fill="currentColor" ')
+                        // 如果 SVG 文件未定义 `fill` 属性,则默认填充 `currentColor`, 这样图标颜色会继承文本颜色,方便在不同场景下适配
+                        svgStr = svgStr.includes('fill="') ? svgStr : svgStr.replace(/^<svg /, '<svg fill="currentColor" ')
 
-            // 如果 svg 有 width, 和 height 属性,将这些属性改为 1em,否则无法显示图标
-            svgStr = svgStr.replace(/(<svg.*?width=)"(.*?)"/, '$1"1em"').replace(/(<svg.*?height=)"(.*?)"/, '$1"1em"')
+                        // 如果 svg 有 width, 和 height 属性,将这些属性改为 1em,否则无法显示图标
+                        svgStr = svgStr.replace(/(<svg.*?width=)"(.*?)"/, '$1"1em"').replace(/(<svg.*?height=)"(.*?)"/, '$1"1em"')
 
-            return svgStr
-          },
-        ),
-      },
-    }),
-    // TODO: check 是否会有别的影响
-    // 处理低端安卓机的样式问题
-    // 将颜色函数 (rgb()和hsl()) 从空格分隔转换为逗号分隔,更好的兼容性app端,example:
-    // `rgb(255 0 0)` -> `rgb(255, 0, 0)`
-    // `rgba(255 0 0 / 0.5)` -> `rgba(255, 0, 0, 0.5)`
-    presetLegacyCompat({
-      commaStyleColorFunction: true,
-      legacyColorSpace: true, // by QQ4群-量子蔷薇
-      // @菲鸽 unocss 配置中,建议在 presetLegacyCompat 中添加 legacyColorSpace: true,以去除生成的颜色样式中的 in oklch 关键字,现在发现有些渐变色生成不符合预期
-    }) as Preset,
-  ],
-  transformers: [
-    // 启用指令功能:主要用于支持 @apply、@screen 和 theme() 等 CSS 指令
-    transformerDirectives(),
-    // 启用 () 分组功能
-    // 支持css class组合,eg: `<div class="hover:(bg-gray-400 font-medium) font-(light mono)">测试 unocss</div>`
-    transformerVariantGroup(),
-  ],
-  shortcuts: [
-    {
-      center: 'flex justify-center items-center',
-    },
-  ],
-  // 动态图标需要在这里配置,或者写在vue页面中注释掉
-  safelist: ['i-carbon-home', 'i-carbon-user', 'i-carbon-chart-line'],
-  rules: [
-    [
-      'p-safe',
-      {
-        padding:
-          'env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)',
-      },
+                        return svgStr
+                    },
+                ),
+            },
+        }),
+        // TODO: check 是否会有别的影响
+        // 处理低端安卓机的样式问题
+        // 将颜色函数 (rgb()和hsl()) 从空格分隔转换为逗号分隔,更好的兼容性app端,example:
+        // `rgb(255 0 0)` -> `rgb(255, 0, 0)`
+        // `rgba(255 0 0 / 0.5)` -> `rgba(255, 0, 0, 0.5)`
+        presetLegacyCompat({
+            commaStyleColorFunction: true,
+            legacyColorSpace: true, // by QQ4群-量子蔷薇
+            // @菲鸽 unocss 配置中,建议在 presetLegacyCompat 中添加 legacyColorSpace: true,以去除生成的颜色样式中的 in oklch 关键字,现在发现有些渐变色生成不符合预期
+        }) as Preset,
     ],
-    ['pt-safe', { 'padding-top': 'env(safe-area-inset-top)' }],
-    ['pb-safe', { 'padding-bottom': 'env(safe-area-inset-bottom)' }],
-  ],
-  theme: {
-    colors: {
-      /** 主题色,用法如: text-primary */
-      primary: 'var(--wot-color-theme,#0957DE)',
-    },
-    fontSize: {
-      /** 提供更小号的字体,用法如:text-2xs */
-      '2xs': ['20rpx', '28rpx'],
-      '3xs': ['18rpx', '26rpx'],
+    transformers: [
+        // 启用指令功能:主要用于支持 @apply、@screen 和 theme() 等 CSS 指令
+        transformerDirectives(),
+        // 启用 () 分组功能
+        // 支持css class组合,eg: `<div class="hover:(bg-gray-400 font-medium) font-(light mono)">测试 unocss</div>`
+        transformerVariantGroup(),
+    ],
+    shortcuts: [
+        {
+            center: 'flex justify-center items-center',
+        },
+    ],
+    // 动态图标需要在这里配置,或者写在vue页面中注释掉
+    safelist: ['i-carbon-home', 'i-carbon-user', 'i-carbon-chart-line'],
+    rules: [
+        [
+            'p-safe',
+            {
+                padding:
+                    'env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)',
+            },
+        ],
+        ['pt-safe', { 'padding-top': 'env(safe-area-inset-top)' }],
+        ['pb-safe', { 'padding-bottom': 'env(safe-area-inset-bottom)' }],
+    ],
+    theme: {
+        colors: {
+            /** 主题色,用法如: text-primary */
+            primary: 'var(--wot-color-theme,#0957DE)',
+        },
+        fontSize: {
+            /** 提供更小号的字体,用法如:text-2xs */
+            '2xs': ['20rpx', '28rpx'],
+            '3xs': ['18rpx', '26rpx'],
+        },
     },
-  },
-  // windows 系统会报错:[plugin:unocss:transformers:pre] Cannot overwrite a zero-length range - use append Left or prependRight instead.
-  // 去掉下面的就正常了
-  // content: {
-  //   /**
-  //    * 解决小程序报错 `./app.wxss(78:2814): unexpected unexpected at pos 5198`
-  //    * 为什么同时使用include和exclude?虽然看起来多余,但同时配置两者是一种常见的 `防御性编程` 做法。
-  //      1. 结构变化保障 : 如果未来项目结构发生变化,某些排除目录可能被移动到包含路径下,exclude配置可以确保它们仍被排除
-  //      2. 明确性 : 明确列出要排除的目录使配置意图更加清晰
-  //      3. 性能优化 : 避免处理不必要的文件,提高构建性能
-  //      4. 防止冲突 : 排除第三方库和构建输出目录,避免潜在的CSS冲突
-  //    */
-  //   pipeline: {
-  //     exclude: [
-  //       'node_modules/**/*',
-  //       'public/**/*',
-  //       'dist/**/*',
-  //     ],
-  //     include: [
-  //       './src/**/*',
-  //     ],
-  //   },
-  // },
+    // windows 系统会报错:[plugin:unocss:transformers:pre] Cannot overwrite a zero-length range - use append Left or prependRight instead.
+    // 去掉下面的就正常了
+    // content: {
+    //   /**
+    //    * 解决小程序报错 `./app.wxss(78:2814): unexpected unexpected at pos 5198`
+    //    * 为什么同时使用include和exclude?虽然看起来多余,但同时配置两者是一种常见的 `防御性编程` 做法。
+    //      1. 结构变化保障 : 如果未来项目结构发生变化,某些排除目录可能被移动到包含路径下,exclude配置可以确保它们仍被排除
+    //      2. 明确性 : 明确列出要排除的目录使配置意图更加清晰
+    //      3. 性能优化 : 避免处理不必要的文件,提高构建性能
+    //      4. 防止冲突 : 排除第三方库和构建输出目录,避免潜在的CSS冲突
+    //    */
+    //   pipeline: {
+    //     exclude: [
+    //       'node_modules/**/*',
+    //       'public/**/*',
+    //       'dist/**/*',
+    //     ],
+    //     include: [
+    //       './src/**/*',
+    //     ],
+    //   },
+    // },
 })