Преглед изворни кода

feat: 1、设备列表新增设备先在离线数量;2、发布脚本更新;

liujia пре 2 месеци
родитељ
комит
e0a3081642
2 измењених фајлова са 73 додато и 19 уклоњено
  1. 32 16
      scripts/release.js
  2. 41 3
      src/views/device/list/index.vue

+ 32 - 16
scripts/release.js

@@ -3,18 +3,29 @@ import { execSync } from 'child_process'
 import inquirer from 'inquirer'
 import fs from 'fs'
 
-function run(cmd) {
-  execSync(cmd, { stdio: 'inherit' })
+function run(cmd, opts = {}) {
+  execSync(cmd, { stdio: 'inherit', ...opts })
+}
+function runOut(cmd) {
+  return execSync(cmd, { encoding: 'utf8' }).trim()
 }
-
 function getVersion() {
   return JSON.parse(fs.readFileSync('package.json', 'utf8')).version
 }
+function isGitClean() {
+  return runOut('git status --porcelain') === ''
+}
 
 async function main() {
   console.log('🚀 开始发布流程...')
 
-  // 1. 选择版本类型(默认 patch)
+  // 0. 保护:工作区必须干净(否则 npm version 会报错)
+  if (!isGitClean()) {
+    console.error('❌ Git 工作区有未提交的改动,请先提交/暂存后再发版!')
+    process.exit(1)
+  }
+
+  // 1) 选择版本类型(默认 patch)
   const { versionType } = await inquirer.prompt([
     {
       type: 'list',
@@ -29,7 +40,7 @@ async function main() {
     },
   ])
 
-  // 2. 选择日志生成模式(默认 incremental
+  // 2) 选择日志生成模式(默认增量
   const { changelogMode } = await inquirer.prompt([
     {
       type: 'list',
@@ -37,32 +48,37 @@ async function main() {
       message: '请选择 changelog 生成模式:',
       default: 'incremental',
       choices: [
-        { name: '全量生成(会覆盖整个文件)', value: 'full' },
         { name: '增量生成(只追加本次更新的内容)', value: 'incremental' },
+        { name: '全量生成(会覆盖整个文件)', value: 'full' },
       ],
     },
   ])
 
-  // 3. 先生成 changelog
+  // 3) 先只更新 package.json 版本,不提交、不打 tag(确保 changelog 标题用到新版本)
+  run(`npm version ${versionType} --no-git-tag-version`)
+  const version = getVersion()
+
+  // 4) 生成 changelog(增量/全量)
   console.log('📝 正在生成 changelog...')
+  // 确保文件存在,避免第一次运行时 in-place 报错
+  if (!fs.existsSync('CHANGELOG.md')) fs.writeFileSync('CHANGELOG.md', '')
   if (changelogMode === 'full') {
     run('npx conventional-changelog -p angular -i CHANGELOG.md -s -r 0')
   } else {
     run('npx conventional-changelog -p angular -i CHANGELOG.md -s')
   }
 
-  // 4. 提交 changelog
+  // 5) 一次性提交:把 package.json + CHANGELOG.md 一起提交,并打 tag(保证日志与版本同步)
+  run('git add package.json package-lock.json 2> NUL || :')
   run('git add CHANGELOG.md')
-  run('git commit -m "chore: update changelog"')
-
-  // 5. 更新版本号并生成 tag
-  run(`npm version ${versionType} -m "new version published: v%s"`)
-  const version = getVersion()
+  run(`git commit -m "chore(release): v${version}"`)
+  run(`git tag v${version}`)
 
-  // 6. 推送代码 & tag
-  run('git push --follow-tags')
+  // 6) 推送代码 & tag
+  run('git push')
+  run('git push --tags')
 
-  // 7. 提示
+  // 7) 提示
   console.log('\x1b[36m=========================\x1b[0m')
   console.log('\x1b[32m🎉 发布成功!\x1b[0m')
   console.log(`\x1b[33m📦 版本号:v${version}\x1b[0m`)

+ 41 - 3
src/views/device/list/index.vue

@@ -49,7 +49,12 @@
 
     <div class="tableCard">
       <div class="tableCard-header">
-        <div class="tableCard-header-title">设备列表</div>
+        <div class="tableCard-header-title">
+          <span>设备列表</span>
+          <span class="subtitle"
+            >设备在线数量:{{ onlineDeviceTotal }} / {{ allDeviceTotal }} (台)
+          </span>
+        </div>
         <div class="tableCard-header-extra">
           <a-space>
             <a-button @click="addDeviceHandler">添加设备</a-button>
@@ -154,6 +159,10 @@ const paginationSizeChange = (current: number, pageSize: number) => {
   console.log('showSizeChange', current, pageSize)
 }
 
+const allDeviceTotal = ref(0) // 所以设备数量
+const onlineDeviceTotal = ref(0) // 在线设备数量
+const offlineDeviceTotal = ref(0) // 离线设备数量
+
 const loading = ref(false)
 // 获取设备信息
 const fetchList = async () => {
@@ -167,9 +176,33 @@ const fetchList = async () => {
       createTimeStart: searchState.createTimeStart,
       createTimeEnd: searchState.createTimeEnd,
       online: searchState.deviceStatus,
-      // tenantId: (route?.query?.tenantId as string) || null,
     })
-    console.log('✅获取到设备信息', res)
+    const allDeviceRes = await deviceAPI.getDeviceList({
+      pageNo: current.value,
+      pageSize: pageSize.value,
+      clientId: searchState.deviceId,
+      devName: searchState.deviceName,
+      createTimeStart: searchState.createTimeStart,
+      createTimeEnd: searchState.createTimeEnd,
+      online: null,
+    })
+    const onlineDeviceRes = await deviceAPI.getDeviceList({
+      pageNo: current.value,
+      pageSize: pageSize.value,
+      clientId: searchState.deviceId,
+      devName: searchState.deviceName,
+      createTimeStart: searchState.createTimeStart,
+      createTimeEnd: searchState.createTimeEnd,
+      online: 1,
+    })
+    allDeviceTotal.value = Number(allDeviceRes.data.total) || 0 // 所以设备数量
+    onlineDeviceTotal.value = Number(onlineDeviceRes.data.total) || 0 // 在线设备数量
+    offlineDeviceTotal.value = allDeviceTotal.value - onlineDeviceTotal.value // 离线设备数量
+    console.log('✅获取到设备信息', res, {
+      allDeviceTotal: allDeviceTotal.value,
+      onlineDeviceTotal: onlineDeviceTotal.value,
+      offlineDeviceTotal: offlineDeviceTotal.value,
+    })
     const { rows, total } = res.data
     deviceList.value = rows
     deviceTotal.value = Number(total)
@@ -274,6 +307,11 @@ const uploadDeviceHandler = () => {
         font-size: 18px;
         font-weight: 600;
       }
+      .subtitle {
+        font-size: 14px;
+        color: #999;
+        margin-left: 10px;
+      }
     }
   }
 }