af-mobile-client-vue3 1.6.31 → 1.6.32
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.
package/package.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import type { SignatureComponentExpose, SignatureComponentProps } from './signature'
|
|
3
3
|
import XSignature from '@af-mobile-client-vue3/components/data/XSignature/index.vue'
|
|
4
4
|
import { upload } from '@af-mobile-client-vue3/services/api/common'
|
|
5
|
-
import {
|
|
5
|
+
import { isNativeApp } from '@af-mobile-client-vue3/utils/environment'
|
|
6
6
|
import { showFailToast, Field as VanField } from 'vant'
|
|
7
|
-
import { ref, watch } from 'vue'
|
|
7
|
+
import { onMounted, ref, watch } from 'vue'
|
|
8
8
|
import SignatureComponent from './SignatureComponent.vue'
|
|
9
9
|
|
|
10
10
|
const props = withDefaults(defineProps<SignatureComponentProps & {
|
|
@@ -24,8 +24,12 @@ const emit = defineEmits<{
|
|
|
24
24
|
signatureComplete: [data: any]
|
|
25
25
|
}>()
|
|
26
26
|
|
|
27
|
-
//
|
|
28
|
-
const isApp =
|
|
27
|
+
// App / Flutter 壳走原生签字板;浏览器、微信等走 H5 签名
|
|
28
|
+
const isApp = ref(isNativeApp())
|
|
29
|
+
onMounted(() => {
|
|
30
|
+
// 部分 WebView 桥接注入略晚于首屏,挂载后再判一次
|
|
31
|
+
isApp.value = isNativeApp()
|
|
32
|
+
})
|
|
29
33
|
|
|
30
34
|
const nativeSignatureRef = ref<InstanceType<typeof SignatureComponent>>()
|
|
31
35
|
const webSignatureImage = ref('')
|
|
@@ -37,7 +41,7 @@ const serviceName = props.serviceName || import.meta.env.VITE_APP_SYSTEM_NAME
|
|
|
37
41
|
watch(
|
|
38
42
|
() => props.imageList,
|
|
39
43
|
(list) => {
|
|
40
|
-
if (isApp || !Array.isArray(list) || !list[0]?.url)
|
|
44
|
+
if (isApp.value || !Array.isArray(list) || !list[0]?.url)
|
|
41
45
|
return
|
|
42
46
|
webSignatureImage.value = list[0].url
|
|
43
47
|
},
|
|
@@ -99,18 +103,18 @@ function handleWebSignatureClear() {
|
|
|
99
103
|
|
|
100
104
|
defineExpose<SignatureComponentExpose>({
|
|
101
105
|
clearSignature() {
|
|
102
|
-
if (isApp)
|
|
106
|
+
if (isApp.value)
|
|
103
107
|
nativeSignatureRef.value?.clearSignature()
|
|
104
108
|
else
|
|
105
109
|
handleWebSignatureClear()
|
|
106
110
|
},
|
|
107
111
|
hasSignature() {
|
|
108
|
-
if (isApp)
|
|
112
|
+
if (isApp.value)
|
|
109
113
|
return nativeSignatureRef.value?.hasSignature() ?? false
|
|
110
114
|
return !!webSignatureData.value?.id || !!webSignatureImage.value
|
|
111
115
|
},
|
|
112
116
|
getSignatureData() {
|
|
113
|
-
if (isApp)
|
|
117
|
+
if (isApp.value)
|
|
114
118
|
return nativeSignatureRef.value?.getSignatureData() ?? ''
|
|
115
119
|
return webSignatureImage.value.replace(/^data:image\/\w+;base64,/, '')
|
|
116
120
|
},
|
|
@@ -118,7 +122,7 @@ defineExpose<SignatureComponentExpose>({
|
|
|
118
122
|
nativeSignatureRef.value?.previewSignature()
|
|
119
123
|
},
|
|
120
124
|
getSignatureList() {
|
|
121
|
-
if (isApp)
|
|
125
|
+
if (isApp.value)
|
|
122
126
|
return nativeSignatureRef.value?.getSignatureList() ?? []
|
|
123
127
|
if (!webSignatureData.value)
|
|
124
128
|
return []
|
|
@@ -134,7 +138,7 @@ defineExpose<SignatureComponentExpose>({
|
|
|
134
138
|
<template>
|
|
135
139
|
<!-- App:原生签字板 -->
|
|
136
140
|
<SignatureComponent
|
|
137
|
-
v-if="isApp"
|
|
141
|
+
v-if="isApp.value"
|
|
138
142
|
ref="nativeSignatureRef"
|
|
139
143
|
:label="label"
|
|
140
144
|
:required="required"
|
package/src/utils/environment.ts
CHANGED
|
@@ -44,6 +44,33 @@ function inferPlatformFromUserAgent(userAgent: string): string {
|
|
|
44
44
|
return 'unknown'
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* 获取 Flutter / 原生桥接所在的 window(微前端子应用需用 rawWindow)
|
|
49
|
+
*/
|
|
50
|
+
export function getNativeBridgeWindow(): Record<string, any> {
|
|
51
|
+
if (typeof window === 'undefined')
|
|
52
|
+
return {}
|
|
53
|
+
const w = window as any
|
|
54
|
+
if (w.__MICRO_APP_ENVIRONMENT__ && w.rawWindow)
|
|
55
|
+
return w.rawWindow
|
|
56
|
+
return w
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 是否已注入 Flutter JS Bridge(如 showSignaturePad.postMessage)
|
|
61
|
+
*/
|
|
62
|
+
export function hasFlutterBridge(bridgeName = 'showSignaturePad'): boolean {
|
|
63
|
+
const win = getNativeBridgeWindow()
|
|
64
|
+
return typeof win[bridgeName]?.postMessage === 'function'
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 是否在 App 原生壳内(含 Flutter WebView)
|
|
69
|
+
*/
|
|
70
|
+
export function isNativeApp(): boolean {
|
|
71
|
+
return detectEnvironment().isApp || hasFlutterBridge()
|
|
72
|
+
}
|
|
73
|
+
|
|
47
74
|
/**
|
|
48
75
|
* 检测当前运行环境
|
|
49
76
|
*/
|
|
@@ -63,10 +90,11 @@ export function detectEnvironment(): EnvironmentInfo {
|
|
|
63
90
|
// 检测微信小程序环境
|
|
64
91
|
const isMiniprogram = isWechat && /miniprogram/i.test(userAgent)
|
|
65
92
|
|
|
66
|
-
// 检测App
|
|
93
|
+
// 检测App环境:UA 标识 / iOS WKWebView / Flutter JS Bridge
|
|
67
94
|
const isApp = (
|
|
68
|
-
/myapp|customapp|afmobileview
|
|
95
|
+
/myapp|customapp|afmobileview|flutter/i.test(userAgent)
|
|
69
96
|
|| (Object.prototype.hasOwnProperty.call(window, 'webkit') && !!(window as any).webkit?.messageHandlers)
|
|
97
|
+
|| hasFlutterBridge()
|
|
70
98
|
)
|
|
71
99
|
|
|
72
100
|
// 检测浏览器环境
|