wui-components-v2 1.2.53 → 1.2.55
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/api/login.ts +4 -5
- package/components/wui-user/wui-user.vue +26 -9
- package/package.json +1 -1
package/api/login.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// 导入核心alova实例
|
|
2
2
|
import dayjs from 'dayjs/esm/index'
|
|
3
|
-
import timezone from 'dayjs/esm/plugin/timezone'
|
|
4
|
-
import utc from 'dayjs/esm/plugin/utc'
|
|
5
3
|
import rsaEncrypt from '../utils/rsaEncrypt'
|
|
6
4
|
import req from './core/index'
|
|
7
5
|
// 获取公钥
|
|
@@ -18,9 +16,10 @@ export async function login(
|
|
|
18
16
|
kaptchaToken: string = '',
|
|
19
17
|
kaptchaText: string = ''
|
|
20
18
|
): Promise<any> {
|
|
21
|
-
dayjs.
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
// 注意:不能依赖 dayjs timezone/utc 插件,它们在 App 端会使用 Intl.DateTimeFormat,
|
|
20
|
+
// 而部分 App 环境(如 Android webview)未提供全局 Intl,会抛 ReferenceError: Intl is not defined。
|
|
21
|
+
// 这里用基础格式化取本地时间即可(不依赖 Intl)。
|
|
22
|
+
const datetime = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
|
|
24
23
|
const json = {
|
|
25
24
|
username,
|
|
26
25
|
password,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed, ref } from 'vue'
|
|
3
|
-
import { useDialog } from '@wot-ui/ui'
|
|
3
|
+
import { useDialog, useToast } from '@wot-ui/ui'
|
|
4
4
|
import { useUser } from '../../composables/useUser'
|
|
5
5
|
import { generateGradientColor } from '../../utils'
|
|
6
6
|
import { useManualTheme } from '../../composables/useManualTheme'
|
|
7
7
|
import { getUserConfig } from '../../api/login'
|
|
8
|
-
import { useGlobalToast } from '../../composables/useGlobalToast'
|
|
9
8
|
import { req } from '../../api/index'
|
|
10
9
|
import WuiUpdateComponent from '../wui-update-component/wui-update-component.vue'
|
|
11
10
|
import { onShow } from '@dcloudio/uni-app'
|
|
@@ -92,7 +91,9 @@ const cellGroupStyle = computed(() => ({
|
|
|
92
91
|
borderRadius: isDark.value ? '10px' : '0',
|
|
93
92
|
}))
|
|
94
93
|
const dialog = useDialog()
|
|
95
|
-
|
|
94
|
+
// 使用 wot-ui 的 useToast:其内部通过 provide/inject 与页面上的 <wd-toast> 共享同一个 ref,
|
|
95
|
+
// 更新 ref 才会触发 <wd-toast> 显示。若使用 pinia 的 useGlobalToast,<wd-toast> 收不到变化,toast 不显示。
|
|
96
|
+
const toast = useToast()
|
|
96
97
|
|
|
97
98
|
const storeUser = useUser().getUserInfo()
|
|
98
99
|
const userInfo = ref({
|
|
@@ -154,8 +155,10 @@ onShow(() => {
|
|
|
154
155
|
if (!props.sensorCode) {
|
|
155
156
|
sensorCode.value = uni.getStorageSync('sensorCode') || uni.getStorageSync('userInfo')?.sensorCode || ''
|
|
156
157
|
}
|
|
157
|
-
//
|
|
158
|
-
|
|
158
|
+
// 进入页面时查询传感器在线状态(仅云音/听音模式需要)
|
|
159
|
+
if (props.isYunyin) {
|
|
160
|
+
getSensorInfo()
|
|
161
|
+
}
|
|
159
162
|
})
|
|
160
163
|
|
|
161
164
|
// 从返回结果中提取在线状态(兼容 1/0、true/false、嵌套 data 等结构)
|
|
@@ -167,6 +170,8 @@ function resolveSensorStatus(res: any): number {
|
|
|
167
170
|
|
|
168
171
|
// 获取传感器在线信息:组件内置调用 /data/sensorOnline 接口(req 自动拼接 /Device 前缀)
|
|
169
172
|
async function getSensorInfo(cli?: string) {
|
|
173
|
+
// 非云音/听音模式不需要传感器在线状态,直接返回,避免多余请求
|
|
174
|
+
if (!props.isYunyin) return
|
|
170
175
|
let code = sensorCode.value
|
|
171
176
|
let newCode = code ? code.slice(3) : ''
|
|
172
177
|
if (!newCode) return
|
|
@@ -217,10 +222,19 @@ function setting() {
|
|
|
217
222
|
})
|
|
218
223
|
}
|
|
219
224
|
async function clearCache() {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
225
|
+
try {
|
|
226
|
+
const res = await getUserConfig()
|
|
227
|
+
if (res.status === 'success') {
|
|
228
|
+
toast.success({ msg: '清除成功!' })
|
|
229
|
+
uni.setStorageSync('userInfo', res.user)
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
toast.error({ msg: res.message || res.msg || '清除失败,请重试' })
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch (error: any) {
|
|
236
|
+
console.error('清除缓存失败:', error)
|
|
237
|
+
toast.error({ msg: error?.data?.message || '清除失败,请检查登录状态' })
|
|
224
238
|
}
|
|
225
239
|
}
|
|
226
240
|
|
|
@@ -393,6 +407,9 @@ function saveSensorConfig() {
|
|
|
393
407
|
</wd-popup>
|
|
394
408
|
|
|
395
409
|
<wd-dialog />
|
|
410
|
+
<!-- 关键:useToast() 在组件内 provide 的 ref 只能被子级 <wd-toast> 消费。
|
|
411
|
+
若此处不放 <wd-toast>,外部(如 wui-tabbar)的 <wd-toast> 与 useToast() 作用域隔离,toast 无法显示。 -->
|
|
412
|
+
<wd-toast />
|
|
396
413
|
</view>
|
|
397
414
|
</template>
|
|
398
415
|
|