Browse Source

feat: 添加应用版本显示功能

liujia 2 tháng trước cách đây
mục cha
commit
5da1efde3c
6 tập tin đã thay đổi với 32 bổ sung13 xóa
  1. 0 11
      components.d.ts
  2. 1 1
      deploy.ps1
  3. 4 0
      env.d.ts
  4. 10 1
      src/layout/index.vue
  5. 10 0
      src/utils/index.ts
  6. 7 0
      vite.config.ts

+ 0 - 11
components.d.ts

@@ -12,12 +12,10 @@ declare module 'vue' {
     AButton: typeof import('ant-design-vue/es')['Button']
     ACascader: typeof import('ant-design-vue/es')['Cascader']
     AConfigProvider: typeof import('ant-design-vue/es')['ConfigProvider']
-    ADrawer: typeof import('ant-design-vue/es')['Drawer']
     ADropdown: typeof import('ant-design-vue/es')['Dropdown']
     AForm: typeof import('ant-design-vue/es')['Form']
     AFormItem: typeof import('ant-design-vue/es')['FormItem']
     AInput: typeof import('ant-design-vue/es')['Input']
-    AInputNumber: typeof import('ant-design-vue/es')['InputNumber']
     AInputPassword: typeof import('ant-design-vue/es')['InputPassword']
     ALayout: typeof import('ant-design-vue/es')['Layout']
     ALayoutContent: typeof import('ant-design-vue/es')['LayoutContent']
@@ -29,20 +27,11 @@ declare module 'vue' {
     AModal: typeof import('ant-design-vue/es')['Modal']
     APageHeader: typeof import('ant-design-vue/es')['PageHeader']
     APagination: typeof import('ant-design-vue/es')['Pagination']
-    ARadioButton: typeof import('ant-design-vue/es')['RadioButton']
-    ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
     ARangePicker: typeof import('ant-design-vue/es')['RangePicker']
     ASelect: typeof import('ant-design-vue/es')['Select']
-    ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
-    ASkeleton: typeof import('ant-design-vue/es')['Skeleton']
     ASpace: typeof import('ant-design-vue/es')['Space']
-    ASpin: typeof import('ant-design-vue/es')['Spin']
-    ASwitch: typeof import('ant-design-vue/es')['Switch']
     ATable: typeof import('ant-design-vue/es')['Table']
-    ATag: typeof import('ant-design-vue/es')['Tag']
     ATooltip: typeof import('ant-design-vue/es')['Tooltip']
-    ATree: typeof import('ant-design-vue/es')['Tree']
-    AUploadDragger: typeof import('ant-design-vue/es')['UploadDragger']
     BaseCard: typeof import('./src/components/baseCard/index.vue')['default']
     BasePagination: typeof import('./src/components/basePagination/index.vue')['default']
     BaseWeather: typeof import('./src/components/baseWeather/index.vue')['default']

+ 1 - 1
deploy.ps1

@@ -5,7 +5,7 @@
 $sourceDir = "D:\project\ln-web\dist"
 $remoteUser = "liujia"
 $remoteIP = "43.137.10.199"
-$remotePath = "/work/web/test" # 实际路径  /work/web/dist
+$remotePath = "/work/web/dist" # 实际路径  /work/web/dist
 $sshPort = 22
 
 # === 准备文件 ===

+ 4 - 0
env.d.ts

@@ -1,6 +1,10 @@
 /// <reference types="vite/client" />
 /// <reference types="@vue/compiler-sfc" />
 
+// 声明全局变量
+declare const __APP_VERSION__: string
+declare const __BUILD_TIME__: string
+
 interface ImportMetaEnv {
   // 基础配置
   readonly NODE_ENV: 'development' | 'production' | 'test'

+ 10 - 1
src/layout/index.vue

@@ -54,7 +54,11 @@
         <slot></slot>
       </a-layout-content>
       <a-layout-footer>
-        <slot name="footer">合肥雷能信息技术有限公司 © 2025 All Rights Reserved.</slot>
+        <slot name="footer">
+          <span>合肥雷能信息技术有限公司 © 2025 All Rights Reserved.</span>
+          <span>&nbsp;&nbsp;&nbsp;&nbsp;版本号:{{ version }}</span>
+          <!-- <span>&nbsp;&nbsp;&nbsp;&nbsp;构建时间:{{ buildTime }}</span> -->
+        </slot>
       </a-layout-footer>
     </a-layout>
 
@@ -76,6 +80,8 @@ import { ArrowLeftOutlined } from '@ant-design/icons-vue'
 
 const userStore = useUserStore()
 const userId = ref(userStore?.userInfo?.userId || '')
+const version = __APP_VERSION__
+// const buildTime = __BUILD_TIME__
 
 let mqttClient: MqttClient | null = null
 let mqttTimeout: number | null = null
@@ -415,6 +421,9 @@ const backHandler = async () => {
     text-align: center;
     background-color: transparent;
     color: #4774a7;
+    display: flex;
+    justify-content: center;
+    align-items: center;
   }
 }
 

+ 10 - 0
src/utils/index.ts

@@ -42,3 +42,13 @@ export function formatSeconds(seconds: number) {
   // 处理所有单位都是0的情况(当seconds为小数时可能发生)
   return parts.length > 0 ? parts.join('') : '0秒'
 }
+
+/**
+ *
+ * @param d 日期对象
+ * @returns 格式化后的日期时间字符串,例如:"2025-01-01 12:00:00"
+ */
+export function formatDateTime(d: Date) {
+  const pad = (n: number) => String(n).padStart(2, '0')
+  return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
+}

+ 7 - 0
vite.config.ts

@@ -5,6 +5,8 @@ import vue from '@vitejs/plugin-vue'
 import vueDevTools from 'vite-plugin-vue-devtools'
 import Components from 'unplugin-vue-components/vite'
 import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
+import { readFileSync } from 'fs'
+import { formatDateTime } from './src/utils'
 
 // https://vite.dev/config/
 export default defineConfig(({ mode }) => {
@@ -17,6 +19,7 @@ export default defineConfig(({ mode }) => {
   console.log(`🚀HostAPI: ${apiHost}`)
   console.log(`🚀ProxyAPI: ${apiHost}`)
 
+  const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'))
   return {
     plugins: [
       vue(),
@@ -29,6 +32,10 @@ export default defineConfig(({ mode }) => {
         ],
       }),
     ],
+    define: {
+      __APP_VERSION__: JSON.stringify(pkg.version),
+      __BUILD_TIME__: JSON.stringify(formatDateTime(new Date())),
+    },
     resolve: {
       alias: {
         '@': fileURLToPath(new URL('./src', import.meta.url)),