verce-vue-test 0.0.57 → 0.0.58
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,4 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { hideWebViewTitle } from '@/core/mxApi'
|
|
3
|
+
|
|
2
4
|
defineOptions({ name: 'AnnouncementTitleBar' })
|
|
3
5
|
|
|
4
6
|
withDefaults(
|
|
@@ -19,6 +21,10 @@ const emit = defineEmits<{
|
|
|
19
21
|
capsuleMore: []
|
|
20
22
|
capsuleClose: []
|
|
21
23
|
}>()
|
|
24
|
+
|
|
25
|
+
onMounted(() => {
|
|
26
|
+
hideWebViewTitle()
|
|
27
|
+
})
|
|
22
28
|
</script>
|
|
23
29
|
|
|
24
30
|
<template>
|
|
@@ -84,6 +84,54 @@ interface NXCommonHost {
|
|
|
84
84
|
ajax?: (options: MXAjaxParams) => void
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
export type MXWebuiSideSlot = {
|
|
88
|
+
default?: boolean
|
|
89
|
+
hidden?: boolean
|
|
90
|
+
disable?: boolean
|
|
91
|
+
content?: string | 'default'
|
|
92
|
+
action?: (() => void) | 'default' | 'custom' | 'native' | 'both'
|
|
93
|
+
preventDefault?: boolean
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type MXWebuiTitleSlot = {
|
|
97
|
+
default?: boolean
|
|
98
|
+
hidden?: boolean
|
|
99
|
+
title?: string
|
|
100
|
+
subtitle?: string
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type MXWebuiInteractiveSlot = {
|
|
104
|
+
default?: boolean
|
|
105
|
+
hidden?: boolean
|
|
106
|
+
title: string[]
|
|
107
|
+
action?: (idx: number) => void
|
|
108
|
+
active?: number
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type MXWebuiHeaderSlot = {
|
|
112
|
+
left?: MXWebuiSideSlot
|
|
113
|
+
left_1?: MXWebuiSideSlot
|
|
114
|
+
left_2?: MXWebuiSideSlot
|
|
115
|
+
middle?: MXWebuiTitleSlot | MXWebuiInteractiveSlot
|
|
116
|
+
right_1?: MXWebuiSideSlot
|
|
117
|
+
right_2?: MXWebuiSideSlot
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type MXWebuiCustomHeaderOptions = {
|
|
121
|
+
slot: MXWebuiHeaderSlot
|
|
122
|
+
onSuccess?: () => void
|
|
123
|
+
onFail?: (error: unknown) => void
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
interface MXWebuiHost {
|
|
127
|
+
hideWebViewTitle?: () => void
|
|
128
|
+
showWebViewTitle?: (title?: string) => void
|
|
129
|
+
setWebViewTitle?: (title: string) => void
|
|
130
|
+
setNavBgColor?: (bgColor: string) => void
|
|
131
|
+
setCustomHeader?: (options: MXWebuiCustomHeaderOptions) => void
|
|
132
|
+
updateCustomHeader?: (options: MXWebuiCustomHeaderOptions) => void
|
|
133
|
+
}
|
|
134
|
+
|
|
87
135
|
const DEFAULT_NATIVE_TIMEOUT = 5000
|
|
88
136
|
const NATIVE_POLL_INTERVAL = 100
|
|
89
137
|
|
|
@@ -92,12 +140,16 @@ declare global {
|
|
|
92
140
|
const MXCommon: MXCommonHost | undefined
|
|
93
141
|
/** 敏行新宿主命名空间,部分客户端使用 NXCommon。 */
|
|
94
142
|
const NXCommon: NXCommonHost | undefined
|
|
143
|
+
/** 敏行原生 UI 宿主命名空间。 */
|
|
144
|
+
const MXWebui: MXWebuiHost | undefined
|
|
95
145
|
|
|
96
146
|
interface Window {
|
|
97
147
|
/** 敏行旧宿主命名空间。 */
|
|
98
148
|
MXCommon?: MXCommonHost
|
|
99
149
|
/** 敏行新宿主命名空间,部分客户端使用 NXCommon。 */
|
|
100
150
|
NXCommon?: NXCommonHost
|
|
151
|
+
/** 敏行原生 UI 宿主命名空间。 */
|
|
152
|
+
MXWebui?: MXWebuiHost
|
|
101
153
|
}
|
|
102
154
|
}
|
|
103
155
|
|
|
@@ -115,11 +167,16 @@ const getMXCommon = () => (typeof MXCommon !== 'undefined' ? MXCommon : undefine
|
|
|
115
167
|
|
|
116
168
|
const getNXCommon = () => (typeof NXCommon !== 'undefined' ? NXCommon : undefined)
|
|
117
169
|
|
|
170
|
+
const getMXWebui = () => (typeof MXWebui !== 'undefined' ? MXWebui : undefined)
|
|
171
|
+
|
|
118
172
|
const getNativeSnapshot = () => ({
|
|
119
173
|
是否存在MXCommon: typeof MXCommon !== 'undefined',
|
|
120
174
|
是否存在NXCommon: typeof NXCommon !== 'undefined',
|
|
175
|
+
是否存在MXWebui: typeof MXWebui !== 'undefined',
|
|
121
176
|
是否存在MXCommonAjax: typeof MXCommon !== 'undefined' && typeof MXCommon.ajax === 'function',
|
|
122
177
|
是否存在NXCommonAjax: typeof NXCommon !== 'undefined' && typeof NXCommon.ajax === 'function',
|
|
178
|
+
是否存在隐藏原生标题栏方法:
|
|
179
|
+
typeof MXWebui !== 'undefined' && typeof MXWebui.hideWebViewTitle === 'function',
|
|
123
180
|
是否存在获取Token方法:
|
|
124
181
|
typeof MXCommon !== 'undefined' && typeof MXCommon.getEncryptString === 'function',
|
|
125
182
|
})
|
|
@@ -259,13 +316,58 @@ export function getAppToken(): Promise<string> {
|
|
|
259
316
|
*/
|
|
260
317
|
export const getEncryptString = getAppToken
|
|
261
318
|
|
|
319
|
+
function callMXWebui(method: keyof MXWebuiHost, ...args: unknown[]) {
|
|
320
|
+
const host = getMXWebui()
|
|
321
|
+
const api = host?.[method]
|
|
322
|
+
|
|
323
|
+
if (typeof api !== 'function') {
|
|
324
|
+
return false
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
try {
|
|
328
|
+
;(api as (...params: unknown[]) => unknown)(...args)
|
|
329
|
+
return true
|
|
330
|
+
} catch (error) {
|
|
331
|
+
console.error(`[敏行UI] ${String(method)} 调用失败`, error)
|
|
332
|
+
return false
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export function hideWebViewTitle() {
|
|
337
|
+
return callMXWebui('hideWebViewTitle')
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export function showWebViewTitle(title?: string) {
|
|
341
|
+
return typeof title === 'string'
|
|
342
|
+
? callMXWebui('showWebViewTitle', title)
|
|
343
|
+
: callMXWebui('showWebViewTitle')
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export function setWebViewTitle(title: string) {
|
|
347
|
+
return callMXWebui('setWebViewTitle', title)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export function setNavBgColor(bgColor: string) {
|
|
351
|
+
return callMXWebui('setNavBgColor', bgColor)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export function setCustomHeader(options: MXWebuiCustomHeaderOptions) {
|
|
355
|
+
return callMXWebui('setCustomHeader', options)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export function updateCustomHeader(options: MXWebuiCustomHeaderOptions) {
|
|
359
|
+
return callMXWebui('updateCustomHeader', options)
|
|
360
|
+
}
|
|
361
|
+
|
|
262
362
|
/**
|
|
263
363
|
* 判断当前页面是否运行在敏行宿主环境中。
|
|
264
364
|
*
|
|
265
365
|
* 只要宿主注入了 MXCommon 或 NXCommon,就认为是原生环境。
|
|
266
366
|
*/
|
|
267
367
|
export const isNativeApp = (): boolean =>
|
|
268
|
-
typeof MXCommon !== 'undefined' ||
|
|
368
|
+
typeof MXCommon !== 'undefined' ||
|
|
369
|
+
typeof NXCommon !== 'undefined' ||
|
|
370
|
+
typeof MXWebui !== 'undefined'
|
|
269
371
|
|
|
270
372
|
/**
|
|
271
373
|
* 等待敏行宿主完成注入后再判断是否为 APP 环境。
|
|
@@ -5,6 +5,7 @@ import { showToast } from 'vant'
|
|
|
5
5
|
import { useAppStore } from '@/stores/app'
|
|
6
6
|
import { useUserStore } from '@/stores/user'
|
|
7
7
|
import { getAppToken } from '@/core/mxApi'
|
|
8
|
+
import { appEnv } from '@/config/env'
|
|
8
9
|
import { saveAuthTokens, type AuthTokenResponse } from '@/utils/auth-token'
|
|
9
10
|
|
|
10
11
|
const router = useRouter()
|
|
@@ -20,6 +21,8 @@ const loading = ref(false)
|
|
|
20
21
|
const appVersion = __APP_VERSION__
|
|
21
22
|
const APP_TOKEN_TIMEOUT = 30000
|
|
22
23
|
const LOGIN_UNAVAILABLE_MESSAGE = '抱歉暂时无法登录'
|
|
24
|
+
const MOCK_APP_TOKEN = 'mock_token'
|
|
25
|
+
const isDevelopment = appEnv === 'development'
|
|
23
26
|
|
|
24
27
|
onMounted(() => {
|
|
25
28
|
if (!appStore.isNative) return
|
|
@@ -30,11 +33,7 @@ onMounted(() => {
|
|
|
30
33
|
async function loginWithAppToken() {
|
|
31
34
|
loading.value = true
|
|
32
35
|
try {
|
|
33
|
-
|
|
34
|
-
const res = await loginByAppTokenApi(appToken)
|
|
35
|
-
await saveBusinessTokenAndOrg(res)
|
|
36
|
-
showToast('登录成功')
|
|
37
|
-
router.push('/')
|
|
36
|
+
await loginByAppToken(await getLoginAppToken())
|
|
38
37
|
} catch (error) {
|
|
39
38
|
console.error('[登录页] APP token 自动登录失败', error)
|
|
40
39
|
if (!isLoginUnavailableError(error)) {
|
|
@@ -46,6 +45,10 @@ async function loginWithAppToken() {
|
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
|
|
48
|
+
function getLoginAppToken() {
|
|
49
|
+
return isDevelopment ? Promise.resolve(MOCK_APP_TOKEN) : getAppTokenWithTimeout()
|
|
50
|
+
}
|
|
51
|
+
|
|
49
52
|
function getAppTokenWithTimeout() {
|
|
50
53
|
return Promise.race([
|
|
51
54
|
getAppToken(),
|
|
@@ -60,10 +63,12 @@ function getAppTokenWithTimeout() {
|
|
|
60
63
|
async function onSubmit() {
|
|
61
64
|
loading.value = true
|
|
62
65
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
if (isDevelopment) {
|
|
67
|
+
await loginByAppToken(MOCK_APP_TOKEN)
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
await loginByPassword()
|
|
67
72
|
} catch (error) {
|
|
68
73
|
if (!isLoginUnavailableError(error)) {
|
|
69
74
|
console.error('[登录页] 账号密码登录失败', error)
|
|
@@ -74,6 +79,20 @@ async function onSubmit() {
|
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
|
|
82
|
+
async function loginByAppToken(appToken: string) {
|
|
83
|
+
const res = await loginByAppTokenApi(appToken)
|
|
84
|
+
await saveBusinessTokenAndOrg(res)
|
|
85
|
+
showToast('登录成功')
|
|
86
|
+
router.push('/')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function loginByPassword() {
|
|
90
|
+
const res = await loginApi(form.value)
|
|
91
|
+
await saveBusinessTokenAndOrg(res)
|
|
92
|
+
showToast('登录成功')
|
|
93
|
+
router.push('/')
|
|
94
|
+
}
|
|
95
|
+
|
|
77
96
|
async function saveBusinessTokenAndOrg(response: unknown) {
|
|
78
97
|
// 先保存 token,后续机构接口需要携带 Authorization 访问。
|
|
79
98
|
saveAuthTokens(response as AuthTokenResponse)
|