wui-components-v2 1.2.46 → 1.2.49

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.
@@ -2,7 +2,7 @@
2
2
  import { defineEmits, defineOptions, defineProps, reactive, ref } from 'vue'
3
3
  import { useRouter } from 'uni-mini-router'
4
4
  import { useGlobalToast } from '../../composables/useGlobalToast'
5
- import { getUserConfig, login } from '../../api/login'
5
+ import { getKaptchaToken, getUserConfig, login } from '../../api/login'
6
6
  import { useUser } from '../../composables/useUser'
7
7
  import { useTabbar } from '../../composables/useTabbar'
8
8
  import type { TabbarItem } from '../../composables/useTabbar'
@@ -30,11 +30,46 @@ const model = reactive<{
30
30
  name: string
31
31
  password: string
32
32
  remember: boolean
33
+ kaptchaText: string
33
34
  }>({
34
35
  name: uni.getStorageSync('USER_NAME') || '',
35
36
  password: uni.getStorageSync('USER_PASSWORD') || '',
36
37
  remember: uni.getStorageSync('REMEMBER') || false,
38
+ kaptchaText: '',
37
39
  })
40
+ // 是否显示验证码
41
+ const showCaptcha = ref(false)
42
+ // 验证码token
43
+ const kaptchaToken = ref('')
44
+ // 验证码图片
45
+ const captchaImg = ref('')
46
+ // 是否正在加载验证码
47
+ const captchaLoading = ref(false)
48
+
49
+ // 获取验证码
50
+ async function handleGetCaptcha() {
51
+ try {
52
+ captchaLoading.value = true
53
+ // 调用 /v3/auth/kaptcha 接口获取验证码
54
+ const res = await getKaptchaToken()
55
+ // 接口返回:{ img: base64图片, kaptchaToken: 验证码token, status: 'success' }
56
+ const data = res?.data || res
57
+ if (data.status === 'success' || data.kaptchaToken) {
58
+ kaptchaToken.value = data.kaptchaToken
59
+ captchaImg.value = data.img
60
+ showCaptcha.value = true
61
+ // 清空之前输入的验证码
62
+ model.kaptchaText = ''
63
+ } else {
64
+ toast.error({ msg: data.message || '验证码获取失败,请重试' })
65
+ }
66
+ } catch (error: any) {
67
+ console.log(error, '获取验证码失败')
68
+ toast.error({ msg: '验证码获取失败,请重试' })
69
+ } finally {
70
+ captchaLoading.value = false
71
+ }
72
+ }
38
73
  const { setTabbarItemActive } = useTabbar(props.tabbarItems)
39
74
  const form = ref()
40
75
 
@@ -46,8 +81,13 @@ function handleSubmit() {
46
81
  if (valid) {
47
82
  try {
48
83
  subloading.value = true
49
- // 登录
50
- const res = await login(model.name, model.password)
84
+ // 登录(如果已显示验证码则携带验证码信息)
85
+ const res = await login(
86
+ model.name,
87
+ model.password,
88
+ showCaptcha.value ? kaptchaToken.value : '',
89
+ showCaptcha.value ? model.kaptchaText : ''
90
+ )
51
91
 
52
92
  if (res.token) {
53
93
  // 保存token
@@ -79,10 +119,14 @@ function handleSubmit() {
79
119
  toast.success({ msg: '登录成功!' })
80
120
  }
81
121
  } else {
82
- toast.error({ msg: res.message })
122
+ toast.error({ msg: res.message || res.msg || '账号或密码错误' })
123
+ // 账号或密码错误时,显示并获取验证码
124
+ handleGetCaptcha()
83
125
  }
84
126
  } catch (error: any) {
85
- console.log(error, 'error')
127
+ // 登录接口返回 status: 'error' 时,core/index.ts 会 reject 整个 res
128
+ // 该函数内部已通过 uni.showToast 提示错误,这里仅触发验证码显示
129
+ handleGetCaptcha()
86
130
  }
87
131
  } else {
88
132
  toast.error({ msg: '请填写登录信息' })
@@ -122,10 +166,37 @@ function handleSubmit() {
122
166
  placeholder="请输入密码"
123
167
  :rules="[{ required: true, message: '请填写密码' }]"
124
168
  />
125
- <view class="p-4 pb-0 pt-0 dark:bg-[#1b1b1e]">
126
- <wd-checkbox v-model="model.remember" shape="square">记住密码</wd-checkbox>
127
- </view>
128
169
  </wd-cell-group>
170
+ <!-- 验证码(账号或密码错误时显示) -->
171
+ <wd-cell-group v-if="showCaptcha" border>
172
+ <wd-input
173
+ v-model="model.kaptchaText"
174
+ label="验证码"
175
+ label-width="100px"
176
+ prop="kaptchaText"
177
+ clearable
178
+ placeholder="请输入验证码"
179
+ :rules="[{ required: true, message: '请填写验证码' }]"
180
+ >
181
+ <template #suffix>
182
+ <view class="flex items-center justify-center" @click="handleGetCaptcha">
183
+ <image
184
+ v-if="captchaImg"
185
+ :src="captchaImg"
186
+ class="h-32px w-90px"
187
+ mode="aspectFit"
188
+ />
189
+ <wd-button v-else size="small" :round="false" :loading="captchaLoading">
190
+ 获取验证码
191
+ </wd-button>
192
+ </view>
193
+ </template>
194
+ </wd-input>
195
+ </wd-cell-group>
196
+ <!-- 记住密码 -->
197
+ <view class="p-4 pb-0 pt-0 dark:bg-[#1b1b1e]">
198
+ <wd-checkbox v-model="model.remember" shape="square">记住密码</wd-checkbox>
199
+ </view>
129
200
  </view>
130
201
  <view class="p-4">
131
202
  <wd-button block :loading="subloading" :round="false" @click="handleSubmit">登录</wd-button>
@@ -39,6 +39,26 @@ const props = defineProps({
39
39
  type: Boolean,
40
40
  default: true,
41
41
  },
42
+ // 是否显示搜索栏,默认不显示
43
+ showSearchBar: {
44
+ type: Boolean,
45
+ default: false,
46
+ },
47
+ // 是否显示轮播图,默认不显示
48
+ showBannerCarousel: {
49
+ type: Boolean,
50
+ default: false,
51
+ },
52
+ // 是否显示快捷菜单,默认不显示
53
+ showSectionMenus: {
54
+ type: Boolean,
55
+ default: false,
56
+ },
57
+ // 是否显示统计,默认不显示
58
+ showQuickPanel: {
59
+ type: Boolean,
60
+ default: false,
61
+ },
42
62
  // 菜单网格列数,调用方可覆盖默认 4 列
43
63
  column: {
44
64
  type: Number,
@@ -104,13 +124,13 @@ onMounted(() => {
104
124
  <!-- 自定义顶部图片插槽:直接渲染在可滚动内容区顶部,避免被当作 z-paging 不存在的 topImg 插槽而丢弃 -->
105
125
  <slot name="topImg" />
106
126
  <!-- 菜单搜索 -->
107
- <searchBar v-if="themeConfig?.showHomePage" />
127
+ <searchBar v-if="themeConfig?.showHomePage && props.showSearchBar" />
108
128
  <!-- 轮播图 -->
109
- <bannerCarousel v-if="themeConfig?.showHomePage" />
129
+ <bannerCarousel v-if="themeConfig?.showHomePage && props.showBannerCarousel" />
110
130
  <!-- 快捷菜单 -->
111
- <sectionMenus v-if="themeConfig?.showHomePage" />
131
+ <sectionMenus v-if="themeConfig?.showHomePage && props.showSectionMenus" />
112
132
  <!-- 统计 -->
113
- <quickPanel v-if="themeConfig?.showHomePage" />
133
+ <quickPanel v-if="themeConfig?.showHomePage && props.showQuickPanel" />
114
134
  <!-- 消息 -->
115
135
  <!-- <wuiNotifyInfo /> -->
116
136
 
@@ -163,7 +183,7 @@ onMounted(() => {
163
183
  >
164
184
  <view
165
185
  class="menu-icon-wrapper flex items-center justify-center"
166
- :style="{ background: subItem.themeColor }"
186
+ :style="{ background: subItem.themeColor || currentThemeColor.primary }"
167
187
  >
168
188
  <text class="menu-icon !text-xl iconfont" :class="[subItem.appIcon || 'i-carbon:grid']" />
169
189
  <view class="icon-shine" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.2.46",
3
+ "version": "1.2.49",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",