verce-vue-test 0.0.27 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  /// <reference types="vite/client" />
2
2
 
3
3
  interface ImportMetaEnv {
4
+ readonly BASE_URL: string
4
5
  readonly VITE_APP_ENV: 'development' | 'test' | 'production'
5
6
  readonly VITE_API_BASE_URL: string
6
7
  readonly VITE_PROXY_TARGET?: string
@@ -23,10 +23,14 @@ export function bumpVersion(mode: string): Plugin {
23
23
  const oldCode = Number(match[1])
24
24
  const newCode = oldCode + 1
25
25
 
26
- const major = Math.floor(newCode / 100000)
27
- const minor = Math.floor((newCode % 100000) / 1000)
28
- const patch = String(newCode % 1000).padStart(3, '0')
29
- const versionName = `${major}.${minor}.${patch}`
26
+ // 版本号规则:5位 version_code 4位版本名
27
+ // version_code: ABCDD A=major B=minor C=patch DD=hotfix
28
+ // version_name: A.B.C.DD 示例 66102 6.6.1.02
29
+ const major = Math.floor(newCode / 10000)
30
+ const minor = Math.floor((newCode / 1000) % 10)
31
+ const patch = Math.floor((newCode / 100) % 10)
32
+ const hotfix = String(newCode % 100).padStart(2, '0')
33
+ const versionName = `${major}.${minor}.${patch}.${hotfix}`
30
34
 
31
35
  content = content
32
36
  .replace(/version_code=\d+/, `version_code=${newCode}`)
@@ -1,7 +1,20 @@
1
- <script setup lang="ts"></script>
1
+ <script setup lang="ts">
2
+ import { useAppStore } from '@/stores/app'
3
+
4
+ const appStore = useAppStore()
5
+
6
+ onMounted(async () => {
7
+ await appStore.initNativeDetection()
8
+
9
+ // 测试环境 + 原生设备:加载 vConsole 调试面板
10
+ if (import.meta.env.VITE_APP_ENV === 'test' && appStore.isNative) {
11
+ import('vconsole').then(({ default: VConsole }) => new VConsole())
12
+ }
13
+ })
14
+ </script>
2
15
 
3
16
  <template>
4
- <router-view v-slot="{ Component }">
17
+ <router-view v-if="appStore.ready" v-slot="{ Component }">
5
18
  <keep-alive include="Home">
6
19
  <component :is="Component" />
7
20
  </keep-alive>
@@ -1,6 +1,6 @@
1
1
  app_id=vue_demo;
2
- version_code=315015;
3
- version_name=3.15.015;
2
+ version_code=10000;
3
+ version_name=1.0.0.00;
4
4
  type=html5;
5
5
  frame=vue;
6
6
  platform=[mac,win,ios,android];
@@ -1,6 +1,6 @@
1
1
  app_id=vue_demo;
2
- version_code=315026;
3
- version_name=3.15.026;
2
+ version_code=10000;
3
+ version_name=1.0.0.00;
4
4
  type=html5;
5
5
  frame=vue;
6
6
  platform=[mac,win,ios,android];
@@ -232,6 +232,33 @@ export const ajaxPut = <T = unknown>(url: string, data?: unknown): Promise<MXAja
232
232
  export const ajaxDelete = <T = unknown>(url: string, id: string): Promise<MXAjaxResponse<T>> =>
233
233
  ajax<T>({ type: 'DELETE', url: `${url}/${id}` })
234
234
 
235
- /** 检测是否在原生环境 */
235
+ let nativeReady = false
236
+ let resolveNativeReady: (() => void) | null = null
237
+
238
+ const nativeReadyPromise = new Promise<void>((resolve) => {
239
+ resolveNativeReady = resolve
240
+ })
241
+
242
+ document.addEventListener('deviceready', () => {
243
+ nativeReady = true
244
+ resolveNativeReady?.()
245
+ }, false)
246
+
247
+ /**
248
+ * 等待原生设备就绪(deviceready 事件触发后 resolve)
249
+ *
250
+ * native 环境下 deviceready 触发后 window.MXCommon 才注入完成,
251
+ * 之后 isNativeApp() 才能拿到正确结果。
252
+ */
253
+ export const whenNativeReady = (): Promise<boolean> => {
254
+ if (nativeReady) return Promise.resolve(isNativeApp())
255
+
256
+ return Promise.race([
257
+ nativeReadyPromise.then(() => isNativeApp()),
258
+ new Promise<boolean>((resolve) => setTimeout(() => resolve(false), 3000)),
259
+ ])
260
+ }
261
+
262
+ /** 检测是否在原生环境(需在 deviceready 之后调用才准确) */
236
263
  export const isNativeApp = (): boolean =>
237
264
  typeof window.MXCommon !== 'undefined'
@@ -1,15 +1,10 @@
1
1
  import { createApp } from 'vue'
2
2
  import { createPinia } from 'pinia'
3
3
  import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
4
- import 'vant/lib/index.css' // Vant 基础样式,必须引入否则组件无样式
4
+ import 'vant/lib/index.css'
5
5
 
6
6
  import App from './App.vue'
7
7
  import router from './router'
8
- import { isNativeApp } from '@/core/mxApi'
9
-
10
- if (import.meta.env.VITE_APP_ENV === 'test' && isNativeApp()) {
11
- import('vconsole').then(({ default: VConsole }) => new VConsole())
12
- }
13
8
 
14
9
  const app = createApp(App)
15
10
  const pinia = createPinia()
@@ -0,0 +1,29 @@
1
+ import { defineStore } from 'pinia'
2
+ import { whenNativeReady } from '@/core/mxApi'
3
+
4
+ /**
5
+ * 应用级状态 Store
6
+ *
7
+ * 存放全局共享的运行时状态,不持久化。
8
+ */
9
+ export const useAppStore = defineStore('app', () => {
10
+ /** 原生环境检测是否已完成(App.vue onMounted 后变为 true) */
11
+ const ready = ref(false)
12
+
13
+ /** 是否在原生 APP WebView 环境中(由 App.vue 初始化时检测并写入) */
14
+ const isNative = ref(false)
15
+
16
+ /**
17
+ * 初始化原生环境检测
18
+ *
19
+ * 等待 deviceready 事件后判断 window.MXCommon 是否存在,
20
+ * 浏览器环境下 3 秒超时后返回 false。
21
+ * 应在 App.vue onMounted 中调用,全局只需一次。
22
+ */
23
+ async function initNativeDetection() {
24
+ isNative.value = await whenNativeReady()
25
+ ready.value = true
26
+ }
27
+
28
+ return { ready, isNative, initNativeDetection }
29
+ })
@@ -7,44 +7,44 @@ type HomeFeature = {
7
7
 
8
8
  defineOptions({ name: 'HomePage' })
9
9
 
10
- const bannerImage = '/images/img.png'
10
+ const bannerImage = `${import.meta.env.BASE_URL}images/img.png`
11
11
 
12
12
  const router = useRouter()
13
13
 
14
14
  const features: HomeFeature[] = [
15
15
  {
16
16
  title: ['人民币头寸', '预报及查询'],
17
- image: '/images/f5876785-b927-4347-ba19-999114240649.png',
17
+ image: `${import.meta.env.BASE_URL}images/f5876785-b927-4347-ba19-999114240649.png`,
18
18
  route: '/rmb-position',
19
19
  },
20
20
  {
21
21
  title: ['外币头寸', '预报及查询'],
22
- image: '/images/12a73787-86a9-4891-a65f-66104746f6a8.png',
22
+ image: `${import.meta.env.BASE_URL}images/12a73787-86a9-4891-a65f-66104746f6a8.png`,
23
23
  route: '/foreign-position',
24
24
  },
25
25
  {
26
26
  title: ['人行头寸', '余额查询'],
27
- image: '/images/73fef1e4-0fd0-4a1a-9b8b-a70a5b6acbbc.png',
27
+ image: `${import.meta.env.BASE_URL}images/73fef1e4-0fd0-4a1a-9b8b-a70a5b6acbbc.png`,
28
28
  route: '/pbc-position',
29
29
  },
30
30
  {
31
31
  title: ['头寸匡算'],
32
- image: '/images/ea745a10-42aa-4f44-8d7f-3ab02cc0adcd.png',
32
+ image: `${import.meta.env.BASE_URL}images/ea745a10-42aa-4f44-8d7f-3ab02cc0adcd.png`,
33
33
  route: '/position-estimate',
34
34
  },
35
35
  {
36
36
  title: ['人民币净借记', '可用额度管理'],
37
- image: '/images/5798d7aa-ba8b-4605-8079-58b35495ac55.png',
37
+ image: `${import.meta.env.BASE_URL}images/5798d7aa-ba8b-4605-8079-58b35495ac55.png`,
38
38
  route: '/net-debit',
39
39
  },
40
40
  {
41
41
  title: ['人民币小额网银', '清算场次明细'],
42
- image: '/images/c3dbbd9d-be56-490e-b9f4-6ee17ebefffc.png',
42
+ image: `${import.meta.env.BASE_URL}images/c3dbbd9d-be56-490e-b9f4-6ee17ebefffc.png`,
43
43
  route: '/clearing-detail',
44
44
  },
45
45
  {
46
46
  title: ['预警信息'],
47
- image: '/images/bc685b4c-0cca-4a79-924c-a8ee10e6f8eb.png',
47
+ image: `${import.meta.env.BASE_URL}images/bc685b4c-0cca-4a79-924c-a8ee10e6f8eb.png`,
48
48
  route: '/warning',
49
49
  },
50
50
  ]
@@ -3,11 +3,12 @@ import { useRouter } from 'vue-router'
3
3
  import { login } from '@/api/user'
4
4
  import { showToast } from 'vant'
5
5
  import { useUserStore } from '@/stores/user'
6
- import { isNativeApp, getEncryptString } from '@/core/mxApi'
6
+ import { useAppStore } from '@/stores/app'
7
+ import { getEncryptString } from '@/core/mxApi'
7
8
 
8
9
  const router = useRouter()
9
10
  const userStore = useUserStore()
10
- const isNative = isNativeApp()
11
+ const appStore = useAppStore()
11
12
 
12
13
  const form = ref({
13
14
  username: '',
@@ -18,12 +19,12 @@ const loading = ref(false)
18
19
 
19
20
  // 原生环境:从客户端获取密钥,直接交换 token
20
21
  onMounted(async () => {
21
- if (!isNativeApp()) return
22
+ if (!appStore.isNative) return
22
23
 
23
24
  loading.value = true
24
25
  try {
25
26
  const secret = await getEncryptString()
26
- console.log(secret)
27
+ console.log(secret)
27
28
  } catch {
28
29
  // 错误已由 request.ts 拦截器统一处理
29
30
  } finally {
@@ -49,7 +50,7 @@ async function onSubmit() {
49
50
  <template>
50
51
  <div class="login-page">
51
52
  <!-- 原生环境:自动登录,只显示加载状态 -->
52
- <van-loading v-if="isNative" vertical class="native-loading">
53
+ <van-loading v-if="appStore.isNative" vertical class="native-loading">
53
54
  正在登录...
54
55
  </van-loading>
55
56
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verce-vue-test",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {