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); onLoad(options => { console.log('onLoad options: ', options); init(options); }); /** * 初始化 * token 及 userId处理: * 1.1 store里有token 且没过期直接:使用store的token * 1.2 store里的token不可用 查localStorage里的token有且没过期 用localStorage里的token * 2. store里跟localStorage里的token均不可用 查userId * 2.1 url里有userId 将userId保存store和localStorage,根据userId查token * 2.2 url里没有userId 查store里的userId有无 有的话 根据store里的userId获取token * 2.3 url跟store的userId均没有,查localStorage里的userId 有 根据userId获取token * @param {object | null} options */ function init(options) { // 参数里有项目名称 就设置标题里的项目名称 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 uni.$u.api.findProjectById({ projectId: options.p, num: 0 }); // 根据项目id获取项目信息 // 查询医院是否填写了调查问卷 // this.handleQueryNotWrite(options.p); // 根据项目id获取成员列表 store.dispatch('role/getAllMembers', { projectId: options.p }); } } }