Explorar o código

工作台 增加年龄限制和密码修改提醒合规评测功能

yuanmingze hai 8 meses
pai
achega
54d3c781ed

+ 116 - 4
src/pages/index/index.vue

@@ -35,6 +35,12 @@ import { computed, ref } from 'vue'
 
 import { onShow } from '@dcloudio/uni-app'
 
+import {
+  getQuizPltTestResultApi,
+  resetPasswordApi,
+  stopSixtyReminderApi,
+} from '@/services/modules/userInfo'
+
 import { useUserStore } from '@/stores/modules/user'
 
 import HonestAgreementGate from './components/HonestAgreementGate.vue'
@@ -57,11 +63,23 @@ onShow(async () => {
     uni.hideTabBar()
     openHonestAgreementGate()
     return
-  } else {
-    uni.showTabBar()
   }
 
-  console.log('qaq', userInfo)
+  // 超龄退出
+  if (userInfo.ageLimit) {
+    isAgeOverLimit()
+  }
+  // 超龄提醒
+  if (userInfo.ageReminder) {
+    notifyUpcomingAgeLimit()
+  }
+  // 平台合规测试
+  const res = await getPltQuizResult()
+  if (!res) return
+  // 密码修改提醒
+  checkLastChangePassword()
+  // 兜底处理
+  uni.showTabBar()
 })
 
 const ensureCanOperate = (): boolean => {
@@ -110,10 +128,104 @@ const handleSelectTask = (item: any) => {
 // 业务判断
 // 显示签署廉洁协议弹窗
 const isHonestAgreementVisible = ref(false)
-
 const openHonestAgreementGate = () => {
   isHonestAgreementVisible.value = true
 }
+
+// 年龄已超限
+const isAgeOverLimit = () => {
+  uni.showModal({
+    title: '提示',
+    showCancel: false,
+    content: userStore?.currentUserInfo?.ageReminderInfo || '',
+    success() {
+      userStore.logout()
+      uni.reLaunch({
+        url: '/pages/login/index',
+      })
+    },
+  })
+}
+// 提前提醒年龄即将超限
+const notifyUpcomingAgeLimit = () => {
+  uni.showModal({
+    title: '提示',
+    cancelText: '不再提醒',
+    confirmText: '确定',
+    content: userStore?.currentUserInfo?.ageReminderInfo || '',
+    async success(res) {
+      if (res.cancel) {
+        const res = await stopSixtyReminderApi()
+        if (res.code === 0 && res.data) {
+          uni.showToast({
+            title: '不再弹出年龄提醒',
+            icon: 'none',
+          })
+        }
+      }
+    },
+  })
+}
+const getPltQuizResult = async (): Promise<boolean> => {
+  const res = await getQuizPltTestResultApi()
+
+  if (res.code === 0) {
+    const { required, testResults } = res.data
+    const hasInvalidResult = testResults.some((item) => !item.valid)
+    const flag = required && hasInvalidResult
+    if (flag) {
+      uni.showModal({
+        title: '提示',
+        cancelText: '暂不处理',
+        confirmText: '去测试',
+        content: '因平台合规升级,现需要您完成风险评估测试,请您认真作答。感谢您的配合!',
+        async success(res) {
+          if (res.confirm) {
+            uni.navigateTo({
+              url: '/pages/quiz-plt-test/index',
+            })
+          }
+          if (res.cancel) {
+            userStore.logout()
+            uni.reLaunch({
+              url: '/pages/login/index',
+            })
+          }
+        },
+      })
+      return false
+    }
+  }
+  return true
+}
+
+// 是否修改过密码
+const checkLastChangePassword = async () => {
+  const userInfo = userStore.currentUserInfo
+  if (!userInfo) return
+  const latestChangePwdTime = userInfo.latestChangePwdTime
+  const now = Date.now()
+  const ninetyDaysAgo = now - 90 * 24 * 60 * 60 * 1000
+  const lastChangeTime = new Date(latestChangePwdTime).getTime()
+
+  if (lastChangeTime < ninetyDaysAgo) {
+    uni.showModal({
+      title: '提示',
+      content: '您的登录密码长时间未修改,为保障账号安全,建议您及时修改密码!',
+      confirmText: '去修改',
+      cancelText: '暂不修改',
+      success: async (res) => {
+        if (res.confirm) {
+          uni.navigateTo({
+            url: '/pages/reset-password/index',
+          })
+        } else if (res.cancel) {
+          resetPasswordApi(userInfo.userId)
+        }
+      },
+    })
+  }
+}
 </script>
 
 <style lang="scss" scoped>

+ 1 - 1
src/services/modules/auth/userInfo.d.ts

@@ -52,7 +52,7 @@ export interface UserInfoItem {
   /** 年龄相关 */
   ageLimit: boolean
   ageReminder: boolean
-  ageReminderInfo: unknown | null
+  ageReminderInfo: string | null
 
   /** 动态子模块 / 菜单 */
   subList: string[]

+ 13 - 0
src/services/modules/userInfo/index.ts

@@ -0,0 +1,13 @@
+import http from '../../index'
+import type { QuizPltTestResultResponse } from './type'
+export const stopSixtyReminderApi = () => {
+  return http.post<boolean>('/admin/api/stop-sixtyyearsold-reminder')
+}
+
+export const getQuizPltTestResultApi = () => {
+  return http.get<QuizPltTestResultResponse>('/admin/api/quiz/plt/test/result')
+}
+
+export const resetPasswordApi = (userId: string) => {
+  return http.post<QuizPltTestResultResponse>(`/admin/user/reset-password?userId=${userId}`)
+}

+ 32 - 0
src/services/modules/userInfo/type.d.ts

@@ -0,0 +1,32 @@
+export interface QuizPltTestResultResponse {
+  required: boolean
+  testResults: TestResultItem[]
+}
+
+export interface TestResultItem {
+  expiryDate: string | null
+  finalMark: number | null
+  quiz: Quiz
+  valid: boolean
+}
+
+export interface Quiz {
+  quizId: number
+  serialNumber: string
+  title: string
+  introduction: string
+  sourceType: 'BLANK' | string
+  state: 'RELEASE' | string
+  enterpriseId: number
+  createBy: string
+  createTime: string
+  updateBy: string
+  updateTime: string
+  expand: QuizExpand
+}
+
+export interface QuizExpand {
+  itemQty: number
+  totalMark: number
+  passingMark: number
+}