import Vue from 'vue' import { getUserInfo, getUsersFace } from '@/network/module/user.api.js' import { formatDate } from '@/utils/util.js' import { downloads } from '@/utils/synchronization-persons.js' import config from '@/common/config.js' // #ifdef APP-PLUS const arcfaceModule = uni.requireNativePlugin('ArcfaceModule') // #endif const state = { userInfo: {}, data2Time: '', photosSync: '', dateTask: null }; const mutations = { SETUSERINFO(state, user) { state.userInfo = user }, LOGOUT(state) { uni.removeStorageSync(config.const.access_token) state.userInfo = {} }, SETUSERAVATAR(state, avatar) { state.userInfo.avatar = avatar }, SETDATE2TIME(state, data2Time) { state.data2Time = data2Time || '' }, SETDATETASK(state, task) { state.dateTask = task }, SETPHOTOSSYNC(state, value) { state.photosSync = value || '' } }; const actions = { goOut({ commit }) { commit('LOGOUT') }, // 修改用户头像 setUserAvatar({ commit }, avatar) { commit('SETUSERAVATAR', avatar) }, setUserInfo({ commit }, token) { uni.setStorageSync(config.const.access_token, token) return new Promise((resolve, reject) => { getUserInfo().then((res) => { commit('SETUSERINFO', res.data) resolve(res.data) }).catch((error) => { reject(error) }) }) }, // 获取所有的用户图片 async getAllUserFace({ commit }) { // #ifdef APP-PLUS let personPhotos = [] try{ const result = await getUsersFace() personPhotos = result.data // 测试用的图片地址 // personPhotos.push({ // photo: 'http://pic-bucket.ws.126.net/photo/0003/2023-08-17/ICB55PEH00AJ0003NOS.jpg', // safeThingsUserId: 2 // }) // personPhotos.push({ // photo: 'http://pic-bucket.ws.126.net/photo/0003/2023-08-17/ICB55PEF00AJ0003NOS.jpg', // safeThingsUserId: 1 // }) }catch(e) { personPhotos = [] } if(!personPhotos || personPhotos.length <= 0) { // 同步信息失败 commit('SETPHOTOSSYNC', null) return } commit('SETPHOTOSSYNC', `0/${personPhotos.length}`) downloads(personPhotos, (res) => { // uni.$u.toast(`下载完成:总大小${res.total}, 有效下载数(${res.available}), 需要下载数(${res.downlaods})`) arcfaceModule.doRegister((result) => { // uni.$u.toast("注册结果" + JSON.stringify(result)) if(result.code === 200) { commit('SETPHOTOSSYNC', `${result.data.total}/${result.data.total}`) } else if(result.code === 300) { commit('SETPHOTOSSYNC', `${result.data.successCount}/${result.data.total}`) } else { uni.$u.toast(result.msg) } }) }) // #endif }, updateHeadStatus({ state, commit }) { if(state.dateTask) { return } const dateTask = setInterval(() => { const dateTimeStr = formatDate(new Date(), 9) commit('SETDATE2TIME', dateTimeStr) }, 1000) commit('SETDATETASK', dateTask) } }; export default { state, mutations, actions }