af-mobile-client-vue3 1.2.16 → 1.2.18

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.2.16",
4
+ "version": "1.2.18",
5
5
  "packageManager": "pnpm@10.12.3",
6
6
  "description": "Vue + Vite component lib",
7
7
  "engines": {
@@ -42,6 +42,7 @@ const props = withDefaults(defineProps<{
42
42
  formName?: string
43
43
  mode?: string
44
44
  submitButton?: boolean
45
+ isHandleFormKey?: boolean
45
46
  }>(), {
46
47
  configName: undefined,
47
48
  groupFormItems: null,
@@ -50,6 +51,7 @@ const props = withDefaults(defineProps<{
50
51
  formName: 'default',
51
52
  mode: '查询',
52
53
  submitButton: true,
54
+ isHandleFormKey: true,
53
55
  })
54
56
  const emits = defineEmits(['onSubmit'])
55
57
  const userStore = useUserStore()
@@ -76,9 +78,6 @@ const realJsonData = computed(() => {
76
78
  })
77
79
  })
78
80
 
79
- // 是否处理表单Key值
80
- const isHandleFormKey = ref(true)
81
-
82
81
  // 过滤出用于静默新增场景的表单项
83
82
  const silenceAddJsonData = computed(() => {
84
83
  return myFormItems.value.filter((item) => {
@@ -263,7 +262,7 @@ function setForm(obj) {
263
262
  function getRealKey(key, mustHandleKey = false) {
264
263
  if (key === 'selected_id')
265
264
  return key
266
- if (isHandleFormKey.value || mustHandleKey) {
265
+ if (props.isHandleFormKey || mustHandleKey) {
267
266
  return key.substring(key.indexOf('_') + 1)
268
267
  }
269
268
  else {
@@ -305,7 +304,7 @@ function handleFormKeys(form, mustHandleKey = false) {
305
304
  realForm[extraFormKey][realKey] = value
306
305
  }
307
306
  else {
308
- const realKey = isHandleFormKey.value || mustHandleKey ? getRealKey(key, mustHandleKey) : key
307
+ const realKey = props.isHandleFormKey || mustHandleKey ? getRealKey(key, mustHandleKey) : key
309
308
  // 如果发生重名,不覆盖,把key的别名带上
310
309
  if (realForm[realKey]) {
311
310
  realForm[key] = value
@@ -301,6 +301,18 @@ watch(localValue, (newVal) => {
301
301
  dataChangeFunc()
302
302
  })
303
303
 
304
+ // 监听 props.form 的变化
305
+ watch(
306
+ () => props.form,
307
+ (newVal, oldVal) => {
308
+ // 如果是从函数获取 options
309
+ if (props.attr.keyName && (props.attr.keyName.toString().includes('async ') || props.attr.keyName.toString().includes('function'))) {
310
+ debouncedUpdateOptions()
311
+ }
312
+ },
313
+ { deep: true },
314
+ )
315
+
304
316
  function updateFile(files, _index) {
305
317
  // 处理文件数据
306
318
  // 更新本地值
@@ -11,6 +11,9 @@ export interface WebConfig {
11
11
  homePage: string
12
12
  defaultAvatarUrl: string
13
13
  wechatLogin: boolean
14
+ wxLoginAge: boolean
15
+ wxAutoLogin: string
16
+ tenantName: string
14
17
  }
15
18
 
16
19
  // 存放 webConfig 中的 setting 配置
@@ -33,13 +36,14 @@ export const useSettingStore = defineStore('setting', () => {
33
36
 
34
37
  const useStore = createStorage()
35
38
  const catchWebConfig = useStore.get(APP_WEB_CONFIG_KEY)
36
- if (catchWebConfig) {
37
- setSetting(catchWebConfig)
39
+ if (catchWebConfig?.setting) {
40
+ setSetting(catchWebConfig?.setting)
38
41
  }
39
42
  else {
40
43
  const res = await getConfigByNameAsync('webMobileConfig')
41
44
  if (res.setting) {
42
45
  useStore.set(APP_WEB_CONFIG_KEY, res)
46
+ console.log('res.setting', res.setting)
43
47
  setSetting(res.setting)
44
48
  }
45
49
  }
@@ -205,6 +205,9 @@ export const useUserStore = defineStore('app-user', () => {
205
205
  console.error(e)
206
206
  }
207
207
  }
208
+ const getCode = (tenantName: string) => {
209
+ window.location.replace(`api/af-system/user/getcode?state=${tenantName}`)
210
+ }
208
211
 
209
212
  return {
210
213
  Login,
@@ -225,6 +228,7 @@ export const useUserStore = defineStore('app-user', () => {
225
228
  setRoutesConfig,
226
229
  setTenantName,
227
230
  getTenantName,
231
+ getCode,
228
232
  }
229
233
  })
230
234
 
@@ -93,3 +93,17 @@ html:not(.dark) {
93
93
  .forget_password_form {
94
94
  margin-top: 15px;
95
95
  }
96
+ /* 使图标垂直居中 */
97
+ .wechat-login-btn .van-icon {
98
+ vertical-align: middle;
99
+ }
100
+ /* 悬停效果 */
101
+ .wechat-login-btn:hover {
102
+ background-color: #06ad56 !important;
103
+ border-color: #06ad56 !important;
104
+ }
105
+ /* 点击效果 */
106
+ .wechat-login-btn:active {
107
+ background-color: #05994c !important;
108
+ border-color: #05994c !important;
109
+ }
@@ -48,7 +48,7 @@ const getShow = computed(() => (unref(getLoginState) === LoginStateEnum.LOGIN))
48
48
 
49
49
  const login: any = inject('$login')
50
50
  onBeforeMount(async () => {
51
- if (isWechat()) {
51
+ if (isWechat() && setting.getSetting()?.wxAutoLogin) {
52
52
  // 检测是否要开放微信登录
53
53
  if (setting.getSetting()?.wechatLogin) {
54
54
  try {
@@ -187,8 +187,53 @@ async function afterGeneral(result) {
187
187
  // 每次重新登录时,清除indexedDB缓存
188
188
  indexedDB.clear()
189
189
  }
190
-
191
- onMounted(() => {})
190
+ async function wxLoginFun() {
191
+ await localStorage.setItem('wechatLoginPending', 'true')
192
+ userState.getCode(setting.getSetting()?.tenantName)
193
+ }
194
+ async function wxLoginFunContinue(code, state) {
195
+ try {
196
+ wxloading.value = true
197
+ const data = await userState.loginUnified({
198
+ unifiedCode: `${code}`,
199
+ tenantName: `${state}`,
200
+ loginMode: 'wechat',
201
+ resourceName: setting.getSetting()?.routerName || '智慧手机',
202
+ })
203
+ login.f = data
204
+ await Promise.all([GetAppDataService.load()])
205
+ const loginInfo = {
206
+ f: login.f,
207
+ jwt: login.f.id,
208
+ r: login.r,
209
+ }
210
+ userState.setLogin(loginInfo)
211
+ userState.setTenantName(route.query.state)
212
+ await afterGeneral(data.resources)
213
+ const toPath = decodeURIComponent((route.query?.redirect || '/') as string)
214
+ closeToast()
215
+ if (route.name === '/login')
216
+ await router.replace('/')
217
+ else await router.replace(toPath)
218
+ }
219
+ finally {
220
+ wxloading.value = false
221
+ }
222
+ }
223
+ function getQueryParam(param: string): string | null {
224
+ const search = window.location.search || window.location.hash.split('?')[1] || ''
225
+ const params = new URLSearchParams(search)
226
+ return params.get(param)
227
+ }
228
+ onMounted(() => {
229
+ const pending = localStorage.getItem('wechatLoginPending')
230
+ const code = getQueryParam('code')
231
+ const state = getQueryParam('state')
232
+ if (pending && code && state) {
233
+ localStorage.removeItem('wechatLoginPending')
234
+ wxLoginFunContinue(code, state)
235
+ }
236
+ })
192
237
  </script>
193
238
 
194
239
  <template>
@@ -241,6 +286,19 @@ onMounted(() => {})
241
286
  <VanButton class="login_btn btn" type="primary" block native-type="submit" :loading="loading">
242
287
  登 录
243
288
  </VanButton>
289
+ <VanButton
290
+ v-show="setting.getSetting()?.wxLoginAge && isWechat()"
291
+ class="wechat-login-btn btn"
292
+ type="primary"
293
+ block
294
+ native-type="button"
295
+ :loading="wxloading"
296
+ style="background-color: #07C160; border-color: #07C160; margin-top: 15px"
297
+ @click="wxLoginFun"
298
+ >
299
+ <VanIcon name="wechat" size="20px" />
300
+ 微信登录
301
+ </VanButton>
244
302
  </VanForm>
245
303
  </div>
246
304
  </template>
package/vite.config.ts CHANGED
@@ -24,12 +24,22 @@ export default ({ mode }: ConfigEnv): UserConfig => {
24
24
  server: {
25
25
  host: true,
26
26
  port: 7190,
27
+ allowedHosts: [
28
+ 'www.aofengcloud.com',
29
+ '.aofengcloud.com',
30
+ ],
27
31
  proxy: Object.assign({
28
32
  '/api/af-system/resource': {
29
33
  target: v4Server,
30
34
  ws: false,
31
35
  changeOrigin: true,
32
36
  },
37
+ '/api/af-system/user': {
38
+ target: 'http://127.0.0.1:9002/',
39
+ rewrite: (path: string) => path.replace(/^\/api\/af-system\//, '/'),
40
+ ws: false,
41
+ changeOrigin: true,
42
+ },
33
43
  '/api/invoice': {
34
44
  target: 'http://219.153.176.6:8400/',
35
45
  rewrite: (path: string) => path.replace(/^\/api\//, '/'),