af-mobile-client-vue3 1.3.41 → 1.3.43

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "af-mobile-client-vue3",
3
3
  "type": "module",
4
- "version": "1.3.41",
4
+ "version": "1.3.43",
5
5
  "packageManager": "pnpm@10.13.1",
6
6
  "description": "Vue + Vite component lib",
7
7
  "engines": {
@@ -43,7 +43,8 @@
43
43
  "vue": "^3.5.17",
44
44
  "vue-i18n": "^11.1.10",
45
45
  "vue-router": "^4.5.1",
46
- "vue3-hash-calendar": "^1.1.3"
46
+ "vue3-hash-calendar": "^1.1.3",
47
+ "weixin-js-sdk": "^1.6.5"
47
48
  },
48
49
  "devDependencies": {
49
50
  "@antfu/eslint-config": "4.17.0",
@@ -39,6 +39,7 @@ interface GroupFormItems {
39
39
  tableName?: string
40
40
  paramLogicName?: string
41
41
  isGroupForm?: boolean
42
+ isKeyHandle?: boolean
42
43
  }
43
44
 
44
45
  interface InitParams {
@@ -85,6 +86,7 @@ const loaded = ref(false)
85
86
  const form = ref({})
86
87
  const rules = reactive({})
87
88
  const myGetDataParams = ref({})
89
+ const isKeyHandle = ref(false)
88
90
 
89
91
  // 配置相关状态
90
92
  const formConfig = ref<GroupFormItems | null>(null)
@@ -92,7 +94,7 @@ const formGroupName = ref<string>('default')
92
94
  const myServiceName = ref('')
93
95
  const tableName = ref('')
94
96
 
95
- // 计算属性
97
+ // 计算属性(获取全部表单项信息)
96
98
  const realJsonData = computed(() => {
97
99
  const sourceFormItems = formConfig.value?.formJson
98
100
  if (!sourceFormItems)
@@ -103,6 +105,13 @@ const realJsonData = computed(() => {
103
105
  })
104
106
  })
105
107
 
108
+ // 过滤出用于新增/修改/只读场景的表单项
109
+ const addOrEditJsonData = computed(() => {
110
+ return realJsonData.value.filter((item) => {
111
+ return item.addOrEdit === 'all' || item.addOrEdit === 'add' || item.addOrEdit === 'edit' || item.addOrEdit === 'readonly'
112
+ })
113
+ })
114
+
106
115
  // 过滤出用于静默新增场景的表单项
107
116
  const silenceAddJsonData = computed(() => {
108
117
  return realJsonData.value.filter((item) => {
@@ -208,6 +217,7 @@ async function initWithGroupFormItems() {
208
217
  function setupFormConfig(config: GroupFormItems) {
209
218
  loadParamLogicNameData(config.paramLogicName)
210
219
  formConfig.value = config
220
+ isKeyHandle.value = config.isKeyHandle
211
221
  myServiceName.value = props.serviceName || undefined
212
222
  formGroupName.value = config.groupName || 'default'
213
223
  form.value = props.formData || {}
@@ -388,9 +398,10 @@ function getRealKey(key: string, mustHandleKey = false) {
388
398
  async function asyncSubmit() {
389
399
  return new Promise((resolve, reject) => {
390
400
  validate().then(async () => {
391
- const cleanedForm = prepareForm()
392
- await appendSilenceAddFields(cleanedForm)
393
- const realForm = handleFormKeys(cleanedForm)
401
+ let realForm = prepareForm()
402
+ await appendSilenceAddFields(realForm)
403
+ if (isKeyHandle.value)
404
+ realForm = handleFormKeys(realForm)
394
405
  resolve({
395
406
  realForm,
396
407
  mode: props.mode,
@@ -545,11 +556,11 @@ function getFormData() {
545
556
  async function onSubmit() {
546
557
  await validate()
547
558
  // 清理表单数据
548
- const cleanedForm = prepareForm()
559
+ let realForm = prepareForm()
560
+ await appendSilenceAddFields(realForm)
549
561
  if (!props.configName && props.groupFormItems) {
550
562
  // 只有单表才可以成功,多表关联或者自定义sql不行
551
- await appendSilenceAddFields(cleanedForm)
552
- const realForm = handleFormKeys(cleanedForm)
563
+ realForm = handleFormKeys(realForm)
553
564
 
554
565
  try {
555
566
  addOrModifyEntity(realForm, tableName.value, props.serviceName || import.meta.env.VITE_APP_SYSTEM_NAME).then(() => {
@@ -566,8 +577,10 @@ async function onSubmit() {
566
577
  }
567
578
  }
568
579
  else {
580
+ if (isKeyHandle.value)
581
+ realForm = handleFormKeys(realForm)
569
582
  // 使用清理后的数据
570
- emits('onSubmit', cleanedForm)
583
+ emits('onSubmit', realForm)
571
584
  }
572
585
  }
573
586
  async function validate() {
@@ -586,7 +599,7 @@ defineExpose({ init, form, formGroupName, validate, asyncSubmit, setForm, getFor
586
599
  <div class="form-fields-scrollable">
587
600
  <VanCellGroup :title="groupTitle">
588
601
  <XFormItem
589
- v-for="(item, index) in realJsonData"
602
+ v-for="(item, index) in addOrEditJsonData"
590
603
  :key="index"
591
604
  v-model="form[item.model]"
592
605
  :mode="props.mode"
@@ -250,6 +250,21 @@ export const useUserStore = defineStore('app-user', () => {
250
250
  return Promise.reject(error)
251
251
  }
252
252
  }
253
+ const loginExternalMini = async (data: any) => {
254
+ try {
255
+ // 设置Token
256
+ setToken(data.access_token)
257
+
258
+ // 加密存储登录票据
259
+ const LoginTicket = crypto.AESEncrypt(JSON.stringify(data), '3KMKqvgwR8ULbR8Z')
260
+ Storage.set('LoginTicket', LoginTicket)
261
+
262
+ return Promise.resolve(data)
263
+ }
264
+ catch (error) {
265
+ return Promise.reject(error)
266
+ }
267
+ }
253
268
 
254
269
  const logout = async () => {
255
270
  if (getToken()) {
@@ -294,6 +309,7 @@ export const useUserStore = defineStore('app-user', () => {
294
309
  Login,
295
310
  loginUnified,
296
311
  loginExternal,
312
+ loginExternalMini,
297
313
  getToken,
298
314
  getLastUpdateTime,
299
315
  logout,
@@ -0,0 +1,129 @@
1
+ /**
2
+ * 环境检测工具类
3
+ * 用于检测当前运行环境:微信服务号、浏览器、小程序、App等
4
+ */
5
+
6
+ export interface EnvironmentInfo {
7
+ isWechat: boolean
8
+ isMiniprogram: boolean
9
+ isApp: boolean
10
+ isBrowser: boolean
11
+ userAgent: string
12
+ platform: string
13
+ isAlipayClient: boolean
14
+ isDingTalk: boolean
15
+ }
16
+
17
+ /**
18
+ * 从 UA-CH 或 UA 推断平台,避免使用已弃用的 navigator.platform
19
+ */
20
+ function getPlatformFromClient(): string {
21
+ // 优先使用 UA-CH(Chromium 等支持)
22
+ const navAny = navigator as any
23
+ const uaData = navAny && navAny.userAgentData
24
+ const uaDataPlatform = typeof uaData?.platform === 'string' ? uaData.platform : ''
25
+
26
+ const platform = uaDataPlatform || inferPlatformFromUserAgent(navigator.userAgent)
27
+ return (platform || 'unknown').toLowerCase()
28
+ }
29
+
30
+ function inferPlatformFromUserAgent(userAgent: string): string {
31
+ const ua = (userAgent || '').toLowerCase()
32
+ if (ua.includes('windows'))
33
+ return 'windows'
34
+ if (ua.includes('mac os x') || ua.includes('macintosh') || ua.includes('mac os'))
35
+ return 'macos'
36
+ if (ua.includes('android'))
37
+ return 'android'
38
+ if (ua.includes('iphone') || ua.includes('ipad') || ua.includes('ipod') || ua.includes('ios'))
39
+ return 'ios'
40
+ if (ua.includes('cros'))
41
+ return 'chrome os'
42
+ if (ua.includes('linux'))
43
+ return 'linux'
44
+ return 'unknown'
45
+ }
46
+
47
+ /**
48
+ * 检测当前运行环境
49
+ */
50
+ export function detectEnvironment(): EnvironmentInfo {
51
+ const userAgent = navigator.userAgent.toLowerCase()
52
+ const platform = getPlatformFromClient()
53
+
54
+ // 检测微信环境
55
+ const isWechat = /micromessenger/i.test(userAgent)
56
+
57
+ // 检测支付宝环境
58
+ const isAlipayClient = /alipayclient/i.test(userAgent)
59
+
60
+ // 检测抖音环境
61
+ const isDingTalk = /dingtalk/i.test(userAgent)
62
+
63
+ // 检测微信小程序环境
64
+ const isMiniprogram = isWechat && /miniprogram/i.test(userAgent)
65
+
66
+ // 检测App环境 - 使用括号明确优先级
67
+ const isApp = (
68
+ /myapp|customapp|nativeapp/.test(userAgent)
69
+ || (Object.prototype.hasOwnProperty.call(window, 'webkit') && !!(window as any).webkit?.messageHandlers)
70
+ )
71
+
72
+ // 检测浏览器环境
73
+ const isBrowser = !isWechat && !isApp
74
+
75
+ return {
76
+ isWechat,
77
+ isMiniprogram,
78
+ isApp,
79
+ isBrowser,
80
+ userAgent,
81
+ platform,
82
+ isAlipayClient,
83
+ isDingTalk,
84
+ }
85
+ }
86
+ /**
87
+ * 获取当前场景类型
88
+ */
89
+ export function getCurrentScene(): 'wechat' | 'browser' | 'miniprogram' | 'app' | 'unknown' {
90
+ const env = detectEnvironment()
91
+
92
+ if (env.isMiniprogram)
93
+ return 'miniprogram'
94
+ if (env.isWechat)
95
+ return 'wechat'
96
+ if (env.isApp)
97
+ return 'app'
98
+ if (env.isBrowser)
99
+ return 'browser'
100
+
101
+ return 'unknown'
102
+ }
103
+
104
+ /**
105
+ * 检查是否支持特定功能
106
+ */
107
+ export function checkFeatureSupport() {
108
+ const env = detectEnvironment()
109
+
110
+ return {
111
+ // 摄像头支持
112
+ camera: 'mediaDevices' in navigator && 'getUserMedia' in navigator.mediaDevices,
113
+
114
+ // NFC支持
115
+ nfc: 'NDEFReader' in window || 'nfc' in navigator,
116
+
117
+ // 文件系统支持
118
+ fileSystem: 'showOpenFilePicker' in window,
119
+
120
+ // 振动支持
121
+ vibration: 'vibrate' in navigator,
122
+
123
+ // 地理位置支持
124
+ geolocation: 'geolocation' in navigator,
125
+
126
+ // 微信JS-SDK支持
127
+ wechatJSSDK: env.isWechat && typeof window !== 'undefined' && 'WeixinJSBridge' in window,
128
+ }
129
+ }
@@ -5,7 +5,7 @@
5
5
 
6
6
  import type { RouteLocationNormalized } from 'vue-router'
7
7
  import { PLATFORM_ROUTE_MAP, PlatformType } from '@af-mobile-client-vue3/types/platform'
8
-
8
+ import { detectEnvironment } from '@af-mobile-client-vue3/utils/environment'
9
9
  /**
10
10
  * 认证参数接口
11
11
  */
@@ -58,7 +58,7 @@ export function isExternalUser(to: RouteLocationNormalized): ExternalUserResult
58
58
 
59
59
  // 第一层检测:URL参数检测(最高优先级)判断公众号登录逻辑
60
60
  // 检查路由查询参数中是否有授权参数(code + state)
61
- const { code, state } = to.query
61
+ const { code, state, appData } = to.query
62
62
  if (code && state) {
63
63
  // 解析认证参数
64
64
  const authParams = {
@@ -77,10 +77,21 @@ export function isExternalUser(to: RouteLocationNormalized): ExternalUserResult
77
77
 
78
78
  // 第二层检测:User-Agent环境检测
79
79
  // 检查浏览器环境是否为第三方平台
80
- const ua = navigator.userAgent.toLowerCase()
81
-
80
+ const env = detectEnvironment()
81
+ // 微信小程序
82
+ if (env.isMiniprogram && appData) {
83
+ const authParams = {
84
+ platformType: PlatformType.WECHAT_MINI,
85
+ appData,
86
+ }
87
+ // 暂未实现 后续需要增加登陆参数
88
+ return {
89
+ isExternal: true,
90
+ authParams,
91
+ }
92
+ }
82
93
  // 微信环境检测
83
- if (/micromessenger/i.test(ua)) {
94
+ if (env.isWechat) {
84
95
  console.log('[Platform Detection] 检测到微信环境,判定为外部用户(无授权参数)')
85
96
  return {
86
97
  isExternal: true,
@@ -92,7 +103,7 @@ export function isExternalUser(to: RouteLocationNormalized): ExternalUserResult
92
103
  }
93
104
 
94
105
  // 支付宝环境检测
95
- if (/alipayclient/i.test(ua)) {
106
+ if (env.isAlipayClient) {
96
107
  // 暂未实现 后续需要增加登陆参数
97
108
  return {
98
109
  isExternal: true,
@@ -103,9 +114,14 @@ export function isExternalUser(to: RouteLocationNormalized): ExternalUserResult
103
114
  }
104
115
 
105
116
  // 钉钉环境检测
106
- if (/dingtalk/i.test(ua)) {
117
+ if (env.isDingTalk) {
107
118
  // 暂未实现 后续需要增加登陆参数
108
- return { isExternal: true }
119
+ return {
120
+ isExternal: true,
121
+ authParams: {
122
+ platformType: PlatformType.DINGTALK,
123
+ },
124
+ }
109
125
  }
110
126
 
111
127
  // 第三层检测:路由前缀检测
@@ -0,0 +1,297 @@
1
+ import { get } from '@af-mobile-client-vue3/services/restTools'
2
+ import { detectEnvironment } from '@af-mobile-client-vue3/utils/environment'
3
+ import wx from 'weixin-js-sdk'
4
+ // 微信JS-SDK配置接口
5
+ export interface WechatConfig {
6
+ debug: boolean
7
+ appId: string
8
+ timestamp: string
9
+ nonceStr: string
10
+ signature: string
11
+ jsApiList: string[]
12
+ }
13
+
14
+ // 微信扫码配置
15
+ export interface WechatScanConfig {
16
+ needResult: 0 | 1
17
+ scanType: string[]
18
+ }
19
+
20
+ // 微信扫码结果
21
+ export interface WechatScanResult {
22
+ resultStr: string
23
+ }
24
+
25
+ // 检查是否在微信环境中
26
+ export function isWechatBrowser(): boolean {
27
+ const env = detectEnvironment()
28
+ return env.isWechat
29
+ }
30
+
31
+ // 检查是否在小程序环境中
32
+ export function isMiniprogram(): boolean {
33
+ const env = detectEnvironment()
34
+ return env.isMiniprogram
35
+ }
36
+
37
+ // 配置微信JS-SDK
38
+ export function configWechatSDK(config: WechatConfig): Promise<void> {
39
+ return new Promise((resolve, reject) => {
40
+ if (!isWechatBrowser()) {
41
+ reject(new Error('非微信环境,无法使用微信JS-SDK'))
42
+ return
43
+ }
44
+
45
+ wx.config({
46
+ debug: config.debug,
47
+ appId: config.appId,
48
+ timestamp: config.timestamp,
49
+ nonceStr: config.nonceStr,
50
+ signature: config.signature,
51
+ jsApiList: config.jsApiList,
52
+ })
53
+
54
+ wx.ready(() => {
55
+ console.log('微信JS-SDK配置成功')
56
+ resolve()
57
+ })
58
+
59
+ wx.error((res: any) => {
60
+ console.error('微信JS-SDK配置失败:', res)
61
+ reject(new Error(`微信JS-SDK配置失败: ${res.errMsg}`))
62
+ })
63
+ })
64
+ }
65
+
66
+ // 微信扫码
67
+ export function scanQRCode(config: WechatScanConfig): Promise<WechatScanResult> {
68
+ return new Promise((resolve, reject) => {
69
+ if (!isWechatBrowser()) {
70
+ reject(new Error('非微信环境,无法使用微信扫码'))
71
+ return
72
+ }
73
+
74
+ wx.scanQRCode({
75
+ needResult: config.needResult,
76
+ scanType: config.scanType,
77
+ success: (res: WechatScanResult) => {
78
+ console.log('微信扫码成功:', res)
79
+ resolve(res)
80
+ },
81
+ fail: (res: any) => {
82
+ console.error('微信扫码失败:', res)
83
+ reject(new Error(`微信扫码失败: ${res.errMsg}`))
84
+ },
85
+ cancel: () => {
86
+ reject(new Error('用户取消扫码'))
87
+ },
88
+ })
89
+ })
90
+ }
91
+
92
+ // 获取微信签名(模拟)
93
+ export async function getWechatSignature(url: string): Promise<{
94
+ appId: string
95
+ timestamp: string
96
+ nonceStr: string
97
+ signature: string
98
+ }> {
99
+ // 这里应该调用后端接口获取微信签名
100
+ // 现在使用模拟数据
101
+ return new Promise((resolve) => {
102
+ get(`/af-wechat/weixin/getJsSdk?path=${url}`).then((res) => {
103
+ resolve({
104
+ appId: res.appId,
105
+ timestamp: res.timeStamp,
106
+ nonceStr: res.nonceStr,
107
+ signature: res.sign,
108
+ })
109
+ })
110
+ })
111
+ }
112
+
113
+ // 初始化微信环境
114
+ export async function initWechatEnvironment(): Promise<void> {
115
+ if (!isWechatBrowser()) {
116
+ console.log('非微信环境,跳过微信初始化')
117
+ return
118
+ }
119
+
120
+ try {
121
+ const currentUrl = window.location.href.split('#')[0]
122
+ const signatureData = await getWechatSignature(currentUrl)
123
+
124
+ await configWechatSDK({
125
+ debug: false,
126
+ appId: signatureData.appId,
127
+ timestamp: signatureData.timestamp,
128
+ nonceStr: signatureData.nonceStr,
129
+ signature: signatureData.signature,
130
+ jsApiList: [
131
+ 'onMenuShareTimeline',
132
+ 'onMenuShareAppMessage',
133
+ 'onMenuShareQQ',
134
+ 'onMenuShareWeibo',
135
+ 'onMenuShareQZone',
136
+ 'startRecord',
137
+ 'stopRecord',
138
+ 'onVoiceRecordEnd',
139
+ 'playVoice',
140
+ 'pauseVoice',
141
+ 'stopVoice',
142
+ 'onVoicePlayEnd',
143
+ 'uploadVoice',
144
+ 'downloadVoice',
145
+ 'chooseImage',
146
+ 'previewImage',
147
+ 'uploadImage',
148
+ 'downloadImage',
149
+ 'translateVoice',
150
+ 'getNetworkType',
151
+ 'openLocation',
152
+ 'getLocation',
153
+ 'hideOptionMenu',
154
+ 'showOptionMenu',
155
+ 'hideMenuItems',
156
+ 'showMenuItems',
157
+ 'hideAllNonBaseMenuItem',
158
+ 'showAllNonBaseMenuItem',
159
+ 'closeWindow',
160
+ 'scanQRCode',
161
+ 'chooseWXPay',
162
+ 'openProductSpecificView',
163
+ 'addCard',
164
+ 'chooseCard',
165
+ 'openCard',
166
+ ],
167
+ })
168
+
169
+ console.log('微信环境初始化成功')
170
+ }
171
+ catch (error) {
172
+ console.error('微信环境初始化失败:', error)
173
+ }
174
+ }
175
+
176
+ // 小程序扫码(在小程序环境中)
177
+ export function miniprogramScanCode(): Promise<string> {
178
+ return new Promise((resolve, reject) => {
179
+ if (!isMiniprogram()) {
180
+ reject(new Error('非小程序环境,无法使用小程序扫码'))
181
+ return
182
+ }
183
+
184
+ // 在小程序环境中,通过 postMessage 与小程序通信
185
+ const mp = (window as any).wx && (window as any).wx.miniProgram
186
+ const sendMessage = (payload: any) => {
187
+ if (mp && typeof mp.postMessage === 'function') {
188
+ mp.postMessage({ data: payload })
189
+ }
190
+ else if (window.parent && window.parent !== window) {
191
+ window.parent.postMessage(payload, '*')
192
+ }
193
+ else {
194
+ throw new Error('无法与小程序通信')
195
+ }
196
+ }
197
+
198
+ try {
199
+ sendMessage({ type: 'scanCode', data: {} })
200
+
201
+ // 监听小程序返回的扫码结果
202
+ const handleMessage = (event: MessageEvent) => {
203
+ const raw = (event as any).data
204
+ const msg = raw && typeof raw === 'object' && 'data' in raw ? (raw as any).data : raw
205
+ if (msg && msg.type === 'scanCodeResult') {
206
+ window.removeEventListener('message', handleMessage)
207
+ if (msg.success) {
208
+ resolve(msg.result)
209
+ }
210
+ else {
211
+ reject(new Error(msg.error || '扫码失败'))
212
+ }
213
+ }
214
+ }
215
+
216
+ window.addEventListener('message', handleMessage)
217
+
218
+ // 设置超时
219
+ setTimeout(() => {
220
+ window.removeEventListener('message', handleMessage)
221
+ reject(new Error('扫码超时'))
222
+ }, 30000)
223
+ }
224
+ catch (err) {
225
+ reject(err)
226
+ }
227
+ })
228
+ }
229
+
230
+ // 小程序NFC读取(在小程序环境中)
231
+ export function miniprogramNfcRead(): Promise<string> {
232
+ return new Promise((resolve, reject) => {
233
+ if (!isMiniprogram()) {
234
+ reject(new Error('非小程序环境,无法使用小程序NFC'))
235
+ return
236
+ }
237
+
238
+ const mp = (window as any).wx && (window as any).wx.miniProgram
239
+ const sendMessage = (payload: any) => {
240
+ if (mp && typeof mp.postMessage === 'function') {
241
+ mp.postMessage({ data: payload })
242
+ }
243
+ else if (window.parent && window.parent !== window) {
244
+ window.parent.postMessage(payload, '*')
245
+ }
246
+ else {
247
+ throw new Error('无法与小程序通信')
248
+ }
249
+ }
250
+
251
+ try {
252
+ sendMessage({ type: 'nfcRead', data: {} })
253
+
254
+ const handleMessage = (event: MessageEvent) => {
255
+ const raw = (event as any).data
256
+ const msg = raw && typeof raw === 'object' && 'data' in raw ? (raw as any).data : raw
257
+ if (msg && msg.type === 'nfcResult') {
258
+ window.removeEventListener('message', handleMessage)
259
+ if (msg.success) {
260
+ resolve(msg.result || '')
261
+ }
262
+ else {
263
+ reject(new Error(msg.error || 'NFC读取失败'))
264
+ }
265
+ }
266
+ }
267
+
268
+ window.addEventListener('message', handleMessage)
269
+
270
+ setTimeout(() => {
271
+ window.removeEventListener('message', handleMessage)
272
+ reject(new Error('NFC读取超时'))
273
+ }, 30000)
274
+ }
275
+ catch (err) {
276
+ reject(err)
277
+ }
278
+ })
279
+ }
280
+ // H5:仅监听小程序主动回传
281
+ export function waitAuthFromMiniProgram(timeout = 15000) {
282
+ return new Promise<{ token: string, resources?: any, expireTime?: number }>((resolve, reject) => {
283
+ const handle = (event: MessageEvent) => {
284
+ const raw = (event as any).data
285
+ const msg = raw && typeof raw === 'object' && 'data' in raw ? (raw as any).data : raw
286
+ if (msg && msg.type === 'auth') {
287
+ window.removeEventListener('message', handle)
288
+ return msg ? resolve(msg) : reject(new Error('未获取到授权信息'))
289
+ }
290
+ }
291
+ window.addEventListener('message', handle)
292
+ setTimeout(() => {
293
+ window.removeEventListener('message', handle)
294
+ reject(new Error('获取授权信息超时'))
295
+ }, timeout)
296
+ })
297
+ }
@@ -2,11 +2,22 @@
2
2
  import XForm from '@af-mobile-client-vue3/components/data/XForm/index.vue'
3
3
  import NormalDataLayout from '@af-mobile-client-vue3/components/layout/NormalDataLayout/index.vue'
4
4
  import { ref } from 'vue'
5
+ import {
6
+ Button as VanButton,
7
+ } from 'vant'
5
8
 
6
- const configName = ref('lngSecurityChecktestForm')
9
+ const configName = ref('测试Form')
7
10
  const serviceName = ref('af-safecheck')
11
+ const formGroupAddConstruction = ref()
8
12
 
9
- const formGroupAddConstruction = ref(null)
13
+ // 提交测试
14
+ function onSubmit(form) {
15
+ console.log('事件触发提交表单----', form)
16
+ }
17
+ async function onAsyncSubmit() {
18
+ const res = await formGroupAddConstruction.value.asyncSubmit()
19
+ console.log('异步提交表单----', res)
20
+ }
10
21
  </script>
11
22
 
12
23
  <template>
@@ -16,10 +27,14 @@ const formGroupAddConstruction = ref(null)
16
27
  ref="formGroupAddConstruction"
17
28
  mode="新增"
18
29
  :config-name="configName"
19
- :service-name="serviceName"
30
+ :show-tab-header="false"
31
+ service-name="af-safecheck"
32
+ :is-group-form="true"
33
+ @on-submit="onSubmit"
20
34
  />
21
35
  </template>
22
36
  </NormalDataLayout>
37
+ <van-button type="primary" @click="onAsyncSubmit">提交</van-button>
23
38
  </template>
24
39
 
25
40
  <style scoped lang="less">
@@ -24,8 +24,16 @@ async function handleAuth() {
24
24
  const authParam = route.query as Record<string, string>
25
25
 
26
26
  if (authParam.platformType) {
27
- // 微信公众号授权登录参数
28
- await handleExternalLogin(authParam)
27
+ switch (authParam.platformType) {
28
+ case PlatformType.WECHAT_OFFICIAL:
29
+ case PlatformType.WECHAT_MINI:
30
+ // 微信公众号,微信小程序授权登录参数
31
+ await handleExternalLogin(authParam)
32
+ break
33
+ default:
34
+ // 其他环境使用原生扫码(需要页面跳转或调用原生API)
35
+ throw new Error('当前环境不支持授权登录')
36
+ }
29
37
  }
30
38
  else {
31
39
  // 无授权参数,检查是否已登录或等待授权
@@ -49,9 +57,16 @@ async function handleAuth() {
49
57
 
50
58
  // 处理外部用户登录
51
59
  async function handleExternalLogin(loginParams: any) {
52
- const data = await userStore.loginExternal(Object.assign(loginParams, {
53
- isMobile: true,
54
- }))
60
+ let data: any
61
+ if (loginParams.platformType === PlatformType.WECHAT_OFFICIAL) {
62
+ data = await userStore.loginExternal(Object.assign(loginParams, {
63
+ isMobile: true,
64
+ }))
65
+ }
66
+ else {
67
+ data = await userStore.loginExternalMini(JSON.parse(loginParams.appData))
68
+ }
69
+
55
70
  const loginInfo = {
56
71
  f: data,
57
72
  jwt: data.id,
@@ -310,10 +310,14 @@ async function submitRegistration(): Promise<void> {
310
310
  try {
311
311
  console.log('formData', formData.value)
312
312
  const response = await openApiLogic(formData.value, 'registrationUser', 'af-system')
313
- console.log('response', response)
313
+ if (response.success) {
314
+ showSuccess.value = true
315
+ showSuccessToast('注册成功')
316
+ }
317
+ else {
318
+ showSuccessToast(`注册失败,${response.msg}!`)
319
+ }
314
320
  isSubmitting.value = false
315
- showSuccess.value = true
316
- showSuccessToast('注册成功')
317
321
  }
318
322
  catch (error) {
319
323
  isSubmitting.value = false
@@ -705,12 +709,12 @@ onMounted(async () => {
705
709
  <p><strong>手机号码:</strong>{{ formData.phone }}</p>
706
710
  </div>
707
711
  <div class="success-actions">
708
- <VanButton type="default" @click="resetForm">
709
- 继续注册
710
- </VanButton>
711
- <VanButton type="primary" @click="goBack">
712
- 去登录
713
- </VanButton>
712
+ <!-- <VanButton type="default" @click="resetForm"> -->
713
+ <!-- 继续注册 -->
714
+ <!-- </VanButton> -->
715
+ <!-- <VanButton type="primary" @click="goBack"> -->
716
+ <!-- 去登录 -->
717
+ <!-- </VanButton> -->
714
718
  </div>
715
719
  </div>
716
720
  </VanPopup>