import { computed } from 'vue'; import { onLoad } from '@dcloudio/uni-app'; import useGetUserIdFromLocal from '@/hooks/user/useGetUserIdFromLocal'; import { useStore } from 'vuex'; export default function useInit() { const store = useStore(); const token = computed(() => store.state.user.token); const userId = useGetUserIdFromLocal(); console.log('userId: ', userId); onLoad(options => { console.log('onLoad options: ', options); init(options); }); /** * 初始化 * @param {object | null} options */ function init(options) { if (!token.value) { // 不论有没有token都直接从userId获取token // token有过期时间 从本地获取可能是过期 干脆直接从userId获取 if (!options || !options.u) { uni.$ui.showToast('缺少用户信息参数'); // 参数里没有u (userId)提示 } else { store.dispatch('user/getToken', options.u); } } // 参数里有项目名称 就设置标题里的项目名称 options && options.pname && store.commit('project/setProjectName', options.pname); if (!options || !options.p) { uni.$ui.showToast('缺少项目信息参数'); // 没有项目id参数 } else { if (options.p !== uni.$storage.getStorageSync('projectId')) { console.log('切项目了'); uni.$storage.setStorageSync('roleId', ''); } // TODO getProjectById({ projectId: options.p, num: 0 }); // 根据项目id获取项目信息 // 查询医院是否填写了调查问卷 // this.handleQueryNotWrite(options.p); // 根据项目id获取成员列表 store.dispatch('role/getAllMembers', { projectId: options.p }); } } }