Pārlūkot izejas kodu

Merge branch 'master' of https://git.citupro.com/zhengnaiwen_citu/menduner-uniapp

lifanagju_citu 7 mēneši atpakaļ
vecāks
revīzija
ab2fd4951f

+ 25 - 0
api/integral.js

@@ -0,0 +1,25 @@
+import request from "@/utils/request"
+
+// 获取规则配置跟踪列表
+export const getRewardEventTrackList = () => {
+  return request({
+    url: '/admin-api/menduner/reward/event-track/list',
+    method: 'GET',
+    custom: {
+      showLoading: false,
+      auth: true
+    }
+  })
+}
+
+// 规则接口触发
+export const rewardEventTrackClick = (url) => {
+  return request({
+    url: '/admin-api/menduner/reward/event-track/click?url=' + url,
+    method: 'POST',
+    custom: {
+      showLoading: false,
+      auth: true
+    }
+  })
+}

+ 2 - 2
layout/components/authModal/login/index.vue

@@ -160,8 +160,8 @@ const state = ref({
     code: ''
   },
   account: {
-    phone: '',
-    password: ''
+    phone: '13229740092',
+    password: 'Citu123456'
   },
   rules: {
     phone: mobile,

+ 2 - 0
store/user.js

@@ -4,6 +4,7 @@ import { smsLogin, passwordLogin, logout, userRegister, shareUserRegister } from
 import { closeAuthModal } from '@/hooks/useModal'
 import { timesTampChange } from '@/utils/date'
 import { getBaseInfoDictOfName } from '@/utils/getText'
+import { updateEventList } from '@/utils/eventList'
 
 // 默认用户信息
 const defaultBaseInfo = {
@@ -93,6 +94,7 @@ export const userStore = defineStore('user', {
     // 获取人才信息
     async getInfo() {
       const { code, data } = await getBaseInfo({ userId: this.accountInfo.userId });
+      updateEventList() // 更新事件列表
       if (code !== 0) {
         return;
       }

+ 31 - 0
utils/eventList.js

@@ -0,0 +1,31 @@
+import { ref } from 'vue'
+import { getRewardEventTrackList } from '@/api/integral'
+
+const getRewardEventList = async () => {
+  const { data } = await getRewardEventTrackList()
+  uni.setStorageSync('eventList', JSON.stringify(data) ?? [])
+}
+
+// 规则配置跟踪列表(每5分钟更新一次)
+export const updateEventList = () => {
+  const timer = ref(null)
+  if (uni.getStorageSync('token')) {
+    getRewardEventList()
+    if (timer.value) clearInterval(timer.value)
+      
+    timer.value = setInterval(async () => {
+      // 没有token时销毁定时器
+      if (!uni.getStorageSync('token')) {
+        clearInterval(timer.value)
+        timer.value = null
+        return
+      }
+      getRewardEventList()
+    }, 180000)
+
+  } else {
+    clearInterval(timer.value)
+    timer.value = null
+    uni.setStorageSync('eventList', [])
+  }
+}

+ 29 - 0
utils/prefixUrl.js

@@ -0,0 +1,29 @@
+// import Snackbar from '@/plugins/snackbar'
+// import Curtain from '@/plugins/curtain'
+
+const prefixList = ['/app-api', '/admin-api']
+export const getSuffixAfterPrefix = (str) => {
+  const matchingPrefix = prefixList.find(prefix => str.startsWith(prefix))
+  if (matchingPrefix) {
+    const matchUrl = str.slice(matchingPrefix.length)
+    const hasQuery = matchUrl.indexOf('?') !== -1
+    if (hasQuery) {
+      const arr = matchUrl.split('?')
+      return arr[0]
+    }
+    else return matchUrl
+  }
+  return undefined
+}
+
+
+
+// 展示积分
+// export function showNextAction (list) {
+//   const arr = list.reduce((newArr, action) => {
+//     // if (action.match) newArr.push(`+${action.point}  恭喜您【${action.title}】获得${action.point}积分`)
+//     if (action.match) newArr.push(`+${action.point}  恭喜您获得${action.point}积分`)
+//     return newArr
+//   }, [])
+//   if (arr?.length) Curtain('point', { list: arr })
+// }

+ 53 - 3
utils/request.js

@@ -8,8 +8,18 @@ import { refreshToken } from '@/api/common';
 import { userStore } from '@/store/user'
 import { baseUrl, tenantId, apiPath } from './config'
 import { showAuthModal } from '@/hooks/useModal'
+import { rewardEventTrackClick } from '@/api/integral'
+import { getSuffixAfterPrefix } from '@/utils/prefixUrl'
 import qs from 'qs'
 
+const RETURNED_API = '/admin-api/menduner/reward/event-track/click'
+// 规则配置跟踪列表
+const eventRules = uni.getStorageSync('eventList') ? JSON.parse(uni.getStorageSync('eventList')) : []
+// 请求成功后触发
+const requestCompletionTrigger = eventRules ? eventRules.filter(_e => _e.triggerType === '0') : []
+// 点击触发
+const clickTrigger = eventRules ? eventRules.filter(_e => _e.triggerType === '1') : []
+
 const options = {
 	// 显示操作成功消息 默认不显示
 	showSuccess: false,
@@ -114,6 +124,17 @@ http.interceptors.request.use(
         config.url = config.url + '?' + paramsStr
       }
     }
+
+		if (uni.getStorageSync('token')) {
+      // 截取request url
+      const url = getSuffixAfterPrefix(config.url)
+      if (!url || !clickTrigger.length) return config
+      const _obj = clickTrigger.find(e => e.url === url)
+      if (_obj) {
+        getIntegral(_obj.url)
+      }
+    }
+
 		return config;
 	},
 	(error) => {
@@ -131,6 +152,22 @@ http.interceptors.response.use(
 			const useUserStore = userStore()
 			useUserStore.setToken(response.data.data.accessToken, response.data.data.refreshToken);
 		}
+		if (response.config.url.includes(RETURNED_API)) {
+			if (!response.data.data || !response.data.data.length) return
+
+			// 目前先默认展示返回的第一个,后续需改为展示多个内容
+			const item = response.data.data && response.data.data.length ? response.data.data[0] : {}
+			if (item.match) {
+				uni.showModal({
+					title: '系统提示',
+					content: `恭喜您 【${item.title}】获得${item.point}积分`,
+					showCancel: false,
+					confirmText: '关闭',
+					confirmColor: '#00897B'
+				})
+			}
+      return
+    }
 
     // 自定处理【loading 加载中】:如果需要显示 loading,则关闭 loading
 		response.config.custom.showLoading && closeLoading();
@@ -153,15 +190,23 @@ http.interceptors.response.use(
 		}
 
 		// 自定义处理【showSuccess 成功提示】:如果需要显示成功提示,则显示成功提示
-		if (response.config.custom.showSuccess
-      && response.config.custom.successMsg !== ''
-      &&  response.data.code === 0) {
+		if (response.config.custom.showSuccess && response.config.custom.successMsg !== '' && response.data.code === 0) {
       uni.showToast({
 				title: response.config.custom.successMsg,
 				icon: 'none',
 			});
 		}
 
+		// 请求成功后触发获取积分
+    if (response.config.header?.Authorization) {
+      const url = getSuffixAfterPrefix(response.config.url)
+      if (!url || !requestCompletionTrigger.length) return data
+      const _obj = requestCompletionTrigger.find(e => e.url === url)
+      if (_obj) {
+        getIntegral(_obj.url)
+      }
+    }
+
     // 返回结果:包括 code + data + msg
 		return Promise.resolve(response.data);
 	},
@@ -306,6 +351,11 @@ const handleAuthorized = () => {
   })
 }
 
+// 触发获取积分
+const getIntegral = (url) => {
+  rewardEventTrackClick(url).then(() => {})
+}
+
 /** 获得访问令牌 */
 export const getAccessToken = () => {
   return uni.getStorageSync('token');