fix:大改造前的保存

This commit is contained in:
MJ 2025-08-06 15:14:41 +08:00
parent 3c5e2578c0
commit 973c4f5ab6
29 changed files with 274 additions and 279 deletions

View File

@ -1,54 +1,54 @@
module.exports = {
extends: ['alloy', 'alloy/vue', 'alloy/typescript', 'plugin:@typescript-eslint/recommended'],
parser: 'vue-eslint-parser',
parserOptions: {
parser: {
js: '@babel/eslint-parser',
jsx: '@babel/eslint-parser',
ts: '@typescript-eslint/parser',
tsx: '@typescript-eslint/parser',
},
extends: ['alloy', 'alloy/vue', 'alloy/typescript', 'plugin:@typescript-eslint/recommended'],
parser: 'vue-eslint-parser',
parserOptions: {
parser: {
js: '@babel/eslint-parser',
jsx: '@babel/eslint-parser',
ts: '@typescript-eslint/parser',
tsx: '@typescript-eslint/parser',
},
rules: {
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'no-return-assign': 'off',
'guard-for-in': 'off',
},
rules: {
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'no-return-assign': 'off',
'guard-for-in': 'off',
'vue/no-setup-props-destructure': 'off',
'vue/no-duplicate-attr-inheritance': 'off',
'no-eq-null': 'off', // 允许 == 用于 null
'vue/no-setup-props-destructure': 'off',
'vue/no-duplicate-attr-inheritance': 'off',
'no-eq-null': 'off', // 允许 == 用于 null
'vue/v-on-event-hyphenation': 'off', // 关闭 vue 中 @ 使用短横线命名
'no-duplicate-imports': 'off', // 使用ts-eslint的重复导入规则
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'vue/multi-word-component-names': 'off',
'vue/no-duplicate-attributes': [
'error',
{
allowCoexistClass: true, // 启用v-bind:class指令可以与普通class属性共存。默认值为true。
allowCoexistStyle: true,
},
],
// 圈复杂度 每个函数的最高圈复杂度
complexity: [
'error',
{
max: 12,
},
],
},
globals: {
defineProps: 'readonly',
defineEmits: 'readonly',
defineExpose: 'readonly',
withDefaults: 'readonly',
},
plugins: ['@typescript-eslint'],
};
'vue/v-on-event-hyphenation': 'off', // 关闭 vue 中 @ 使用短横线命名
'no-duplicate-imports': 'off', // 使用ts-eslint的重复导入规则
'no-console': import.meta.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': import.meta.env.NODE_ENV === 'production' ? 'warn' : 'off',
'vue/multi-word-component-names': 'off',
'vue/no-duplicate-attributes': [
'error',
{
allowCoexistClass: true, // 启用v-bind:class指令可以与普通class属性共存。默认值为true。
allowCoexistStyle: true,
},
],
// 圈复杂度 每个函数的最高圈复杂度
complexity: [
'error',
{
max: 12,
},
],
},
globals: {
defineProps: 'readonly',
defineEmits: 'readonly',
defineExpose: 'readonly',
withDefaults: 'readonly',
},
plugins: ['@typescript-eslint'],
}

View File

@ -48,5 +48,5 @@
"src/uni_modules/uni-search-bar/components/uni-search-bar/i18n",
"src/uni_modules/z-paging/components/z-paging/i18n"
],
"cSpell.words": ["iconfont", "pinia", "VITE", "xuexiaole"]
"cSpell.words": ["iconfont", "persistedstate", "pinia", "VITE", "Wechat", "Weixin", "xuexiaole"]
}

View File

@ -62,13 +62,13 @@
"dayjs": "^1.11.13",
"echarts": "^5.5.1",
"lint-staged": "^15.0.1",
"lodash": "4.17.21",
"pinia": "^2.0.36",
"qs": "^6.14.0",
"sass": "^1.72.0",
"unplugin-vue-define-options": "^1.4.2",
"vue": "^3.3.4",
"vue-i18n": "^9.1.9",
"lodash": "4.17.21",
"vue-qrcode-reader": "^5.5.7",
"weixin-js-sdk": "^1.6.5"
},
@ -82,6 +82,7 @@
"@dcloudio/uni-cli-shared": "3.0.0-3081220230817001",
"@dcloudio/uni-stacktracey": "3.0.0-3081220230817001",
"@dcloudio/vite-plugin-uni": "3.0.0-3081220230817001",
"@types/lodash": "4.17.16",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@vue/runtime-core": "^3.4.21",
@ -94,7 +95,6 @@
"prettier": "^3.0.3",
"typescript": "^4.9.5",
"vite": "4.1.4",
"@types/lodash": "4.17.16",
"vue-eslint-parser": "^9.3.2",
"vue-tsc": "^1.0.24"
},

View File

@ -1,9 +1,5 @@
import { http } from './request/request'
// 获取客服信息
export const getCsInfo = async (id: string) =>
await http.get<any>(`/customerService/getInfoByUserId/${id}`)
// 更新用户信息
export const updateUserInfo = async (data: any) =>
await http.post<any>('/sysUser/editPerfectMessage', data)

View File

@ -46,16 +46,6 @@ export const wxLoginApi = async data =>
clientType: 'PARENT',
})
// /**
// * 微信绑定账号
// * @param data 请求参数
// */
// export const wxBindAccountApi = async data =>
// await http.post<any>('/wxBindAccount', {
// ...data,
// clientType: 'PARENT',
// })
/**
*
* @param data
@ -83,4 +73,4 @@ export const bindAuthInfoApi = async data =>
export const getAuthUrlApi = async () => await http.get<any>('/wechatPublic/getAuthUrl')
// 退出登录
export const logout = async () => await http.get<any>('/logout')
export const logoutApi = async () => await http.get<any>('/logout')

View File

@ -1,8 +1,8 @@
import { http } from '../request/request'
import { storeToRefs } from 'pinia'
import { user } from '@/store'
import { getCache } from '@/utils'
import db from '@/utils/db'
import { userStore } from '@/store'
// 课表日历
export const getScheduleList = async (data?: Record<string, any>): Promise<any> =>
@ -64,9 +64,9 @@ export const getUserInfo = async (data?: Record<string, any>): Promise<any> =>
await http.get<any>('/phone/inspectorTeacher/getCurrentTeacher')
// 文件上传
export const uploadFile = async (file): Promise<any> => {
const { token } = storeToRefs(user())
const { token } = storeToRefs(userStore())
const mergerToken = token.value || db.get('token')
const mergerToken = token.value
const data = await uni.uploadFile({
url: `/api/main/sysFileInfo/tenUploadAll`, // ${import.meta.env.VITE_HOST}

View File

@ -5,6 +5,8 @@ import { HTTP_STATUS, ERROR_MSG } from './config'
import router from '@/router/router'
import db from '@/utils/db'
import toast from '@/utils/hud'
import { storeToRefs } from 'pinia'
import { userStore } from '@/store'
// 请求拦截器
export const requestInterceptor = async (options: RequestOptions): Promise<RequestOptions> => {
@ -12,12 +14,12 @@ export const requestInterceptor = async (options: RequestOptions): Promise<Reque
const header: any = {
...options?.header,
}
const { token } = storeToRefs(userStore())
// 获取token
const token = db.get('token')
// 如果有token添加到请求头
if (token) {
header['Authorization'] = `Bearer ${token}`
if (token.value) {
header['Authorization'] = `Bearer ${token.value}`
}
return {

View File

@ -1,11 +1,11 @@
import { useWebSocket } from '@vueuse/core'
import { user } from '@/store'
import { userStore } from '@/store'
import { ref } from 'vue'
import type { UseWebSocketReturn } from '@vueuse/core'
let SOCKET: UseWebSocketReturn<any>
export const useSocket = () => {
const { token, userInfo } = user()
const { token, userInfo } = userStore()
const inspectorMessage = ref<any>()
const inspectorDesktopMessage = ref([])
const desktopPath = ref<string>()
@ -18,7 +18,7 @@ export const useSocket = () => {
}
function init() {
SOCKET = useWebSocket(
`${process.env.VITE_WS_URL}?accessToken=${token.replace('Bearer ', '')}`,
`${import.meta.env.VITE_WS_URL}?accessToken=${token.replace('Bearer ', '')}`,
{
autoReconnect: {
retries: 5,

View File

@ -5,11 +5,14 @@ import * as Pinia from 'pinia'
import './styles/global.scss'
import './styles/font.scss'
import './styles/iconfont.scss'
import BackBar from '@/components/BackBar/index'
import PiniaPluginPersist from './plugins/pinia-plugin-persist'
import BackBar from '@/components/BackBar/index.vue'
export function createApp() {
const app = createSSRApp(App)
app.use(Pinia.createPinia())
const pinia = Pinia.createPinia()
pinia.use(PiniaPluginPersist)
app.use(pinia)
app.component('BackBar', BackBar)
return {
app,

View File

@ -47,11 +47,11 @@ import type { ChildrenType } from '@/pages/mine/interface'
import type { SubjectType } from './interface'
import './index.scss'
import { getParentBindChildApi, subjectApi } from '@/api'
import { user } from '@/store'
import { userStore } from '@/store'
import { storeToRefs } from 'pinia'
import hud from '@/utils/hud'
const { userInfo } = storeToRefs(user())
const { userInfo } = storeToRefs(userStore())
const childrenList = ref<ChildrenType[]>() //
const empty = ref(false)

View File

@ -143,10 +143,10 @@ import { getParentBindDeviceApi, parentDeviceCurrentLoginApi, queryAppRecordApi
import TabBar from '@/components/Tabbar/index.vue'
import CustomPopup from '@/components/CustomPopup/index.vue'
import Empty from '@/components/Empty/index.vue'
import { user } from '@/store'
import { userStore } from '@/store'
import { storeToRefs } from 'pinia'
const { userInfo } = storeToRefs(user())
const { userInfo } = storeToRefs(userStore())
const OSS_URL = import.meta.env.VITE_OSS_HOST
const defaultAvatar = `${OSS_URL}/urm/default_avatar.png`
const arrow = `${OSS_URL}/iconfont/down_arrow.png`

View File

@ -108,14 +108,14 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { getCurInfo, parentBindAdmin } from '@/api'
import { user, shareConfigStore } from '@/store'
import { userStore, shareConfigStore } from '@/store'
import { storeToRefs } from 'pinia'
import TipPopup from '@/components/TipPopup/index.vue'
import router from '@/router/router'
import jWeixin from 'weixin-js-sdk'
const { initWeixinShareConfig } = shareConfigStore()
const { userInfo } = storeToRefs(user())
const { userInfo } = storeToRefs(userStore())
const OSS_URL = import.meta.env.VITE_OSS_HOST
const show = ref(false)
@ -260,7 +260,7 @@ async function determine() {
} else {
router.navigateTo({
path: './familyRelationships',
query: { parameter: JSON.stringify(obj) }
query: { parameter: JSON.stringify(obj) },
})
}
}

View File

@ -79,14 +79,14 @@
import { onMounted, reactive, ref } from 'vue'
import { getParentBindDeviceApi, parentDeviceCurrentLoginApi } from '@/api'
import TabBar from '@/components/Tabbar/index.vue'
import { user } from '@/store'
import { userStore } from '@/store'
import { storeToRefs } from 'pinia'
import hud from '@/utils/hud'
import router from '@/router/router'
const userStore = user()
const { getUserInfo } = userStore
const { userInfo } = storeToRefs(userStore)
const store = userStore()
const { getUserInfo } = store
const { userInfo } = storeToRefs(store)
const OSS_URL = import.meta.env.VITE_OSS_HOST
const scanQr = `${OSS_URL}/iconfont/scan_qr.png`
const arrow = `${OSS_URL}/iconfont/down_arrow.png`
@ -185,19 +185,24 @@ function change(i: any) {
}
//
async function getParentBindDevice() {
equipmentList.value = []
hud.load({
task: async () => {
equipmentList.value = []
showEquipment.value = {}
const data = await getParentBindDeviceApi({ parentId: userInfo.value.id, size: -1 })
for (let i in data.rows) {
const _r = await parentDeviceCurrentLoginApi(data.rows[i].id)
equipmentList.value.push({
...data.rows[i],
curDeviceUserName: _r.curDeviceUserName,
curDeviceUserAvatar: _r.curDeviceUserAvatar,
})
if (data.rows?.length > 0) {
equipmentList.value = data.rows
showEquipment.value = data.rows[0]
}
showEquipment.value = data.rows?.length > 0 ? equipmentList.value[0] : {}
// for (let i in data.rows) {
// const _r = await parentDeviceCurrentLoginApi(data.rows[i].id)
// equipmentList.value.push({
// ...data.rows[i],
// curDeviceUserName: _r.curDeviceUserName,
// curDeviceUserAvatar: _r.curDeviceUserAvatar,
// })
// }
// showEquipment.value = data.rows?.length > 0 ? equipmentList.value[0] : {}
},
})
}

View File

@ -55,10 +55,10 @@
<script setup lang="ts">
import { computed, inject, onBeforeMount, type Ref, ref } from 'vue'
import type { UserInfo } from '@/types/inspector/mine'
import { getUserInfo, queryUserRoles, switchRole } from '@/api/inspector/mine'
import { getAvatarUrl, getCache, setCache } from '@/utils'
import { queryUserRoles, switchRole } from '@/api/inspector/mine'
import { getAvatarUrl } from '@/utils'
import { getAuthUrlApi } from '@/api/login'
import { user } from '@/store'
import { userStore } from '@/store'
import db from '@/utils/db'
const roleRef = ref(null)
@ -67,7 +67,7 @@ const userInfo = inject<Ref<UserInfo>>('userInfo')
const roleList = ref<any[]>([])
const { getUserInfo: getLoginUserInfo } = user()
const { getUserInfo: getLoginUserInfo } = userStore()
const queryRole = async () => {
const data = await queryUserRoles({ phone: userInfo.value.phone })

View File

@ -181,8 +181,8 @@
</view>
</template>
<script setup lang="ts">
import { user } from '@/store'
const { logout } = user()
import { userStore } from '@/store'
const { logout } = userStore()
import { onLaunch, onShow, onHide, onLoad } from '@dcloudio/uni-app'
import { usepersonalStoreHook } from '@/store/inspector'
import Picker from '../releasePlan/components/picker.vue'

View File

@ -55,14 +55,14 @@
import { ref, computed, nextTick, onMounted } from 'vue'
import { sendCodeMessageApi, smsLoginApi, wxLoginApi } from '@/api'
import { user } from '@/store'
import { userStore } from '@/store'
import router from '@/router/router'
import db from '@/utils/db'
import hud from '@/utils/hud'
const emits = defineEmits(['reloadFun'])
const OSS_URL = import.meta.env.VITE_OSS_HOST
const { getUserInfo, setToken } = user()
const { getUserInfo, setToken } = userStore()
const formatPhone = ref('')
const verifyCode = ref('')

View File

@ -67,17 +67,17 @@
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { storeToRefs } from 'pinia';
import Empty from '@/components/Empty/index.vue';
import CustomPopup from '@/components/CustomPopup/index.vue';
import { updateTaskStatusApi, getParentBindChildApi, getFamilyTaskStuApi } from '@/api';
import { user } from '@/store';
const { userInfo } = storeToRefs(user());
const OSS_URL = import.meta.env.VITE_OSS_HOST;
const pageStatus = ref('');
const taskType = ref(); // 0- 1-
import { ref, onMounted } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { storeToRefs } from 'pinia'
import Empty from '@/components/Empty/index.vue'
import CustomPopup from '@/components/CustomPopup/index.vue'
import { updateTaskStatusApi, getParentBindChildApi, getFamilyTaskStuApi } from '@/api'
import { userStore } from '@/store'
const { userInfo } = storeToRefs(userStore())
const OSS_URL = import.meta.env.VITE_OSS_HOST
const pageStatus = ref('')
const taskType = ref() // 0- 1-
const taskStatusOpt = ref([
{
status: 0,
@ -87,40 +87,40 @@ const taskStatusOpt = ref([
status: 1,
text: '已完成',
},
]);
const activeStatus = ref(0);
])
const activeStatus = ref(0)
const taskStatusInfo = ref({
taskId: '',
status: 0,
});
const showFinishPopup = ref(false);
})
const showFinishPopup = ref(false)
const checkedList = ref([]); //
const checkedList = ref([]) //
const pageType = ref<number>(); // 1 2
const childrenList = ref([]); //
const pageType = ref<number>() // 1 2
const childrenList = ref([]) //
const page = ref({
current: 1,
size: 10,
});
})
//
function filterStatus(i) {
taskStatusInfo.value.status = i.status;
activeStatus.value = i.status;
fetchStudentTaskStatus();
taskStatusInfo.value.status = i.status
activeStatus.value = i.status
fetchStudentTaskStatus()
}
//
function handleSingleCheck(i) {
let id = i.childId;
let id = i.childId
if (pageType.value === 1) {
taskStatusInfo.value.status = 1;
showFinishPopup.value = true;
taskStatusInfo.value.status = 1
showFinishPopup.value = true
}
i.checked = !i.checked;
i.checked = !i.checked
if (i.checked) {
checkedList.value.push(id);
checkedList.value.push(id)
} else {
checkedList.value.splice(checkedList.value.indexOf(id), 1);
checkedList.value.splice(checkedList.value.indexOf(id), 1)
}
}
@ -128,31 +128,31 @@ function handleSingleCheck(i) {
async function handleConfirmFinish() {
uni.showLoading({
title: '正在完成...',
});
})
let res = await updateTaskStatusApi({
...taskStatusInfo.value,
stuIdList: checkedList.value,
});
uni.hideLoading();
})
uni.hideLoading()
if (res.code === 200) {
uni.showToast({
icon: 'none',
title: '已完成',
});
taskStatusInfo.value.status = 0;
fetchStudentTaskStatus();
showFinishPopup.value = false;
})
taskStatusInfo.value.status = 0
fetchStudentTaskStatus()
showFinishPopup.value = false
}
}
//
function handleCancelFinish() {
checkedList.value = [];
checkedList.value = []
childrenList.value = childrenList.value.map(item => {
return {
...item,
checked: false,
};
});
}
})
}
//
@ -160,22 +160,22 @@ async function fetchChildrenInfo() {
try {
uni.showLoading({
title: '加载中...',
});
})
const data = await getParentBindChildApi({
parentId: userInfo.value.id,
...page.value,
});
})
for (let i in data.rows) {
childrenList.value.push({
...data.rows[i],
checked: checkedList.value.includes(data.rows[i].childId),
});
})
}
pageStatus.value = childrenList.value.length === 0 ? 'empty' : '';
uni.hideLoading();
pageStatus.value = childrenList.value.length === 0 ? 'empty' : ''
uni.hideLoading()
} catch (err) {
console.log(err);
uni.hideLoading();
console.log(err)
uni.hideLoading()
}
}
//
@ -183,16 +183,16 @@ async function fetchStudentTaskStatus() {
try {
uni.showLoading({
title: '加载中...',
});
})
const data = await getFamilyTaskStuApi({
...taskStatusInfo.value,
});
childrenList.value = data;
pageStatus.value = childrenList.value.length === 0 ? 'empty' : '';
uni.hideLoading();
})
childrenList.value = data
pageStatus.value = childrenList.value.length === 0 ? 'empty' : ''
uni.hideLoading()
} catch (err) {
console.log(err);
uni.hideLoading();
console.log(err)
uni.hideLoading()
}
}
@ -200,31 +200,31 @@ async function fetchStudentTaskStatus() {
function handleConfirm() {
uni.$emit('updateTaskSendObject', {
list: JSON.stringify(checkedList.value),
});
uni.navigateBack();
})
uni.navigateBack()
}
//
function handleCancel() {
checkedList.value = [];
uni.navigateBack();
checkedList.value = []
uni.navigateBack()
}
onLoad(option => {
pageType.value = Number(option.pageType);
pageType.value = Number(option.pageType)
uni.setNavigationBarTitle({
title: pageType.value === 1 ? '发送对象' : '选择发送对象',
});
})
if (pageType.value === 1) {
//
let details = JSON.parse(decodeURIComponent(option.details));
taskType.value = details.customTask;
taskStatusInfo.value.taskId = details.id;
fetchStudentTaskStatus();
let details = JSON.parse(decodeURIComponent(option.details))
taskType.value = details.customTask
taskStatusInfo.value.taskId = details.id
fetchStudentTaskStatus()
} else {
checkedList.value = JSON.parse(option.checkedList);
fetchChildrenInfo();
checkedList.value = JSON.parse(option.checkedList)
fetchChildrenInfo()
}
});
})
</script>
<style lang="scss" scoped>

View File

@ -3,11 +3,9 @@
<z-paging
ref="paging"
v-model="dataList"
:paging-style="{ margin: isAdmin ? '402rpx 30rpx 0 30rpx' : '226rpx 30rpx 0 30rpx' }"
:paging-style="{ margin: '402rpx 30rpx 0 30rpx' }"
:style="{
height: isAdmin
? `calc(100% - 532rpx - 120rpx - 52rpx)`
: `calc(100% - 356rpx - 120rpx - 52rpx)`,
height: `calc(100% - 532rpx - 120rpx - 52rpx)`,
}"
@query="queryList"
>
@ -83,18 +81,18 @@
import { reactive, ref, onMounted, nextTick } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { getParentBindChildApi, getParentBindDeviceApi } from '@/api'
import { user } from '@/store'
import { userStore } from '@/store'
import { storeToRefs } from 'pinia'
import { getCache } from '@/utils'
import router from '@/router/router'
import type { ChildrenType, DeviceType } from './interface'
import dayjs from 'dayjs'
import db from '@/utils/db'
const { userInfo } = storeToRefs(user())
const { userInfo } = storeToRefs(userStore())
const OSS_URL = import.meta.env.VITE_OSS_HOST
const defaultAvatar = `${OSS_URL}/urm/default_avatar.png`
const empty = `${OSS_URL}/empty.png`
const isAdmin = ref(false)
//
const activeNav = ref({
title: '我的孩子',
@ -173,9 +171,7 @@ onShow(() => {
paging.value.refresh()
}
})
onMounted(() => {
isAdmin.value = db.get('userAdmin')
})
onMounted(() => {})
</script>
<style lang="scss" scoped>

View File

@ -34,13 +34,13 @@ import { onLoad } from '@dcloudio/uni-app'
import dayjs from 'dayjs'
import bindPatriarch from './bindPatriarch.vue'
import type { ChildrenType } from '../interface'
import { user, shareConfigStore } from '@/store'
import { userStore, shareConfigStore } from '@/store'
import { storeToRefs } from 'pinia'
import { parentBindInviteApi } from '@/api'
import { onMounted } from 'vue'
const { initWeixinShareConfig } = shareConfigStore()
const { appId } = storeToRefs(shareConfigStore())
const { userInfo } = storeToRefs(user())
const { userInfo } = storeToRefs(userStore())
const detailInfo = ref<ChildrenType>({})
const OSS_URL = import.meta.env.VITE_OSS_HOST
const showMaskTip = ref(false) //

View File

@ -52,13 +52,13 @@ import type { DeviceType, CurrentLoginAccountType } from '../interface'
import bindPatriarch from './bindPatriarch.vue'
import { parentDeviceCurrentLoginApi, parentBindInviteApi } from '@/api'
import { user, shareConfigStore } from '@/store'
import { userStore, shareConfigStore } from '@/store'
import { storeToRefs } from 'pinia'
import dayjs from 'dayjs'
const { initWeixinShareConfig } = shareConfigStore()
const { appId } = storeToRefs(shareConfigStore())
const { userInfo } = storeToRefs(user())
const { userInfo } = storeToRefs(userStore())
const showMaskTip = ref(false)
const detailInfo = ref<DeviceType>()
const currentLogin = ref<CurrentLoginAccountType>()

View File

@ -9,7 +9,7 @@
<text class="name">{{ userInfo.nickName }}</text>
<text class="identity">家长</text>
</view>
<!-- <view class="function">
<view class="function">
<template v-for="i in list" :key="i.title">
<view v-if="i.show" class="function_item" @click="handleJump(i)">
<view class="photo_box">
@ -19,19 +19,19 @@
<text class="title">{{ i.title }}</text>
</view>
</template>
</view> -->
</view>
</view>
</template>
<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { user } from '@/store'
import { userStore } from '@/store'
import { storeToRefs } from 'pinia'
import { getCache } from '@/utils'
import router from '@/router/router'
import db from '@/utils/db'
const { userInfo } = storeToRefs(user())
const { userInfo } = storeToRefs(userStore())
const OSS_URL = import.meta.env.VITE_OSS_HOST
const defaultAvatar = `${OSS_URL}/urm/default_avatar.png`
@ -45,33 +45,33 @@ const list = ref([
{
title: '绑定申请',
photo: `${OSS_URL}/urm/my_binding_apply.png`,
show: false,
show: true,
url: '/pages/mine/bindApply/index',
},
{
title: '电子保修卡',
photo: `${OSS_URL}/urm/my_warranty.png`,
show: true,
url: '/pages/mine/warranty/index',
},
// {
// title: '',
// photo: `${OSS_URL}/urm/my_warranty.png`,
// show: true,
// url: '/pages/mine/warranty/index',
// },
// {
// title: '使',
// photo: `${OSS_URL}/urm/my_use_guideline.png`,
// show: true,
// url: '',
// },
{
title: '任务管理',
photo: `${OSS_URL}/urm/my_task_manage.png`,
show: true,
url: '/pages/mine/taskManage/index',
},
{
title: '奖励管理',
photo: `${OSS_URL}/urm/my_award_manage.png`,
show: true,
url: '/pages/mine/awardManage/index',
},
// {
// title: '',
// photo: `${OSS_URL}/urm/my_task_manage.png`,
// show: true,
// url: '/pages/mine/taskManage/index',
// },
// {
// title: '',
// photo: `${OSS_URL}/urm/my_award_manage.png`,
// show: true,
// url: '/pages/mine/awardManage/index',
// },
])
function handleJump(i: any) {
router.navigateTo({
@ -86,9 +86,7 @@ function handlePrefectInfo() {
// })
}
onMounted(() => {
list.value[1].show = db.get('userAdmin')
})
onMounted(() => {})
</script>
<style lang="scss" scoped>

View File

@ -59,13 +59,12 @@
<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { user } from '@/store'
import { updateUserInfoApi } from '@/api'
import { storeToRefs } from 'pinia'
import router from '@/router/router'
import CustomPopup from '@/components/CustomPopup/index.vue'
// #ifdef H5
import { h5Authorization } from '@/store'
import { h5Authorization, userStore } from '@/store'
import hud from '@/utils/hud'
const { authorizedLogin } = h5Authorization()
// #endif
@ -73,8 +72,9 @@ const popupRef = ref(null)
const OSS_URL = import.meta.env.VITE_OSS_HOST
const defaultAvatar = `${OSS_URL}/urm/default_avatar.png`
const arrow = `${OSS_URL}/iconfont/down_arrow.png`
const { logout, getUserInfo } = user()
const { userInfo } = storeToRefs(user())
const store = userStore()
const { logout, getUserInfo } = store
const { userInfo } = storeToRefs(store)
const indicatorStyle = ref(`height: 50px;`)
const showCustomPopup = ref(false)
const pageType = ref() // 1-

View File

@ -0,0 +1,48 @@
import db from '@/utils/db'
import type { PiniaPluginContext, StateTree, Store } from 'pinia'
const cache = ['user']
function getStoreKey(key: string) {
return `store_${key}`
}
// 解析数据同步到state
function hydrateStore(store: Store, key: string) {
try {
const data = db.get(getStoreKey(key))
if (!data) return
store.$patch(data)
} catch (err) {
console.error(err)
}
}
// 序列化之后存储到storage
function persistState(state: StateTree, key: string) {
try {
db.set(getStoreKey(key), state)
} catch (err) {
console.error(err)
}
}
function PiniaPluginPersist(context: PiniaPluginContext) {
const { store } = context
// 没包含的就不缓存
if (!cache.includes(store.$id)) return
hydrateStore(store, store.$id)
// 监听数据变化
store.$subscribe(
(mutation, state) => {
persistState(state, store.$id)
},
{
// 组件销毁时,当前监听不会被销毁
detached: true,
},
)
}
export default PiniaPluginPersist

View File

@ -1,7 +1,9 @@
/* eslint-disable no-param-reassign */
import { userStore } from '@/store'
import db from '../utils/db'
import page from '../utils/page'
import qs from 'qs'
import { storeToRefs } from 'pinia'
// 页面路径常量
export const route_login = '/pages/login/index'
@ -109,8 +111,8 @@ function beforeEach(options: RouterOptions) {
console.log('beforeEach', from, to)
// 执行跳转
const token = db.get('token')
if (!noTokenRoutes.includes(to.path) && !token) {
const { token } = storeToRefs(userStore())
if (!noTokenRoutes.includes(to.path) && !token.value) {
console.log('token 过期')
toLogin(to)
return false

View File

@ -1,19 +1,13 @@
import { getCache, setCache } from '@/utils'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { user } from '@/store'
import { userStore } from '@/store'
import { bindAuthInfoApi } from '@/api'
import db from '@/utils/db'
const { afterLogin, getUserInfo } = user()
// const { } = user();
export const h5Authorization = defineStore('h5Authorization', () => {
const H5Openid = ref('')
const authorizedLogin = async () => {
// if (getCache('userInfo')) {
// await getUserInfo();
// }
const code = getQueryString('code')
const state = getQueryString('state')
console.log('进入授权code和state', code, state)
@ -28,6 +22,7 @@ export const h5Authorization = defineStore('h5Authorization', () => {
// setCache('H5_OPENID', res.data.openId);
// setCache('H5_UNIONID', res.data.unionId);
// setCache('token', res.data.token);
const { afterLogin } = userStore()
await afterLogin()
})
} else {

View File

@ -4,7 +4,9 @@ import { ref } from 'vue'
import { global } from './global'
import { getCache, setCache } from '@/utils'
import db from '@/utils/db'
import { userStore } from './user'
export const socket = defineStore('socket', () => {
const { token } = storeToRefs(userStore())
const socket = ref()
const status = ref(true) // true在线 false离线
let hbTimer: any
@ -23,12 +25,11 @@ export const socket = defineStore('socket', () => {
return true
}
async function initSocket(simSerialNumber: string) {
const token = db.get('token')
init()
function init() {
if (!beforeInit()) return
socket.value = uni.connectSocket({
url: `${process.env.VITE_WS_URL}?accessToken=${token}`,
url: `${import.meta.env.VITE_WS_URL}?accessToken=${token.value}`,
complete: () => {},
})
@ -67,7 +68,7 @@ export const socket = defineStore('socket', () => {
// 心跳
function _heartBeat() {
// console.log('心跳')
if (!db.get('token')) {
if (!token.value) {
socket.value?.close()
clearInterval(hbTimer)
return

View File

@ -1,94 +1,53 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import {
// phoneLogin as phoneLoginApi,
getUserInfoApi,
// psdLogin as psdLoginApi,
logout as logoutApi,
getCsInfo as getCsInfoApi,
bindRegId,
userInfoPermitApi,
// updatePwdByPhone,
} from '@/api'
import { getUserInfoApi, logoutApi } from '@/api'
// import type { smsLoginType, accountLoginType, updatePasswordType } from '@/api';
// import defaultAvatar from "@/static/default_avatar.png";
import { global } from '@/store'
import router from '@/router/router'
import db from '@/utils/db'
export const user = defineStore('user', () => {
const userInfo = ref(db.get('userInfo') || ({} as any))
const csInfo = ref(db.get('csInfo') || {})
const token = ref(db.get('token') || '')
export const userStore = defineStore('user', () => {
const userInfo = ref({} as any)
const token = ref('')
const { getDicts } = global()
const afterLogin = async () => {
await Promise.allSettled([getUserInfo(), getDicts()])
// getCsInfo(); // 需等待用户信息加载完毕
}
const logout = async () => {
// #ifdef APP-PLUS
if (db.get('registerID')) {
await bindRegId({
registrationId: db.get('registerID'),
type: 2,
})
}
// #endif
await logoutApi()
clear()
router.toLogin()
}
const getUserInfo = async () => {
// 如果不是微信公众号环境,直接跳回登录页面
if (!db.get('openid')) {
const mode = import.meta.env.MODE
// 如果是正式环境 && 且缺少openid直接跳回登录页面
if (mode !== 'dev' && mode !== 'mp' && !db.get('openid')) {
router.toLogin()
return
}
const res = await getUserInfoApi()
userInfo.value = res
db.set('userInfo', res)
await getUserInfoPermit()
return res
}
// 当前登录用户是否管理员身份
async function getUserInfoPermit() {
const data = await userInfoPermitApi()
db.set('userAdmin', data)
}
const getCsInfo = async () => {
const res = await getCsInfoApi(userInfo.value.id)
csInfo.value = res
db.set('csInfo', res)
return res
}
const clear = async () => {
token.value = ''
userInfo.value = {}
csInfo.value = {}
await db.clear()
}
const setToken = (data: string) => {
token.value = data
db.set('token', data)
}
return {
userInfo,
csInfo,
token,
// setInfo,
// login,
// phoneLogin,
// accordLogin,
// updatePassword,
getUserInfo,
getCsInfo,
logout,
clear,
afterLogin,

View File

@ -695,7 +695,7 @@ export function isImageUrl(url: string): boolean {
/**
* H5
*/
export const isH5 = process.env.UNI_PLATFORM === 'h5'
export const isH5 = import.meta.env.UNI_PLATFORM === 'h5'
/**
*

View File

@ -49,7 +49,7 @@ function isSameSecond(time1: number, time2: number): boolean {
}
// 判断当前环境是否为 H5
const isH5 = process.env.UNI_PLATFORM === 'h5'
const isH5 = import.meta.env.UNI_PLATFORM === 'h5'
// 封装 requestAnimationFrame 和 setTimeout
function raf(fn: FrameRequestCallback): number {