|
|
@ -1,27 +1,10 @@ |
|
|
|
import { computed, nextTick, onMounted, ref, watch } from 'vue'; |
|
|
|
|
|
|
|
import { computed } from 'vue'; |
|
|
|
import { onLoad } from '@dcloudio/uni-app'; |
|
|
|
import useGetUserIdFromLocal from '@/hooks/user/useGetUserIdFromLocal'; |
|
|
|
import { useStore } from 'vuex'; |
|
|
|
|
|
|
|
// import {
|
|
|
|
// flatten
|
|
|
|
// } from 'lodash';
|
|
|
|
|
|
|
|
export default function useInit() { |
|
|
|
const store = useStore(); |
|
|
|
const token = computed(() => store.state.user.token); |
|
|
|
const userId = useGetUserIdFromLocal(); |
|
|
|
const roleId = computed(() => store.state.role.roleId); |
|
|
|
const timeNode = computed(() => store.state.task.timeNode); |
|
|
|
const timeUnit = computed(() => store.state.task.timeUnit); |
|
|
|
const tasks = computed(() => store.state.task.tasks); |
|
|
|
const newProjectInfo = computed(() => store.state.task.newProjectInfo); |
|
|
|
const showScrollTo = computed(() => store.state.task.showScrollTo); |
|
|
|
const timeGranularity = computed(() => store.getters['task/timeGranularity']); |
|
|
|
const projectId = computed(() => store.getters['project/projectId']); |
|
|
|
const height = ref(null); |
|
|
|
const timeLine = ref(null); |
|
|
|
|
|
|
|
onLoad(options => { |
|
|
|
if (options.share && options.share === '1') { |
|
|
@ -36,16 +19,19 @@ export default function useInit() { |
|
|
|
// height.value = `${system.windowHeight}px`;
|
|
|
|
// });
|
|
|
|
|
|
|
|
// 设置 初始显示角色信息
|
|
|
|
function setInitialRoleId(visibleList) { |
|
|
|
if (!visibleList || !visibleList.length) return; |
|
|
|
const index = visibleList.findIndex(item => +item.mine === 1); |
|
|
|
const currentRole = index > 0 ? visibleList[index] : visibleList[0]; |
|
|
|
const storageRoleId = uni.$storage.getStorageSync('roleId'); |
|
|
|
const currentRoleId = storageRoleId || (currentRole ? currentRole.id : ''); |
|
|
|
store.commit('role/setRoleId', currentRoleId); |
|
|
|
// 清空storage
|
|
|
|
uni.$storage.setStorageSync('roleId', ''); |
|
|
|
/** |
|
|
|
* 通过项目id获取项目信息 |
|
|
|
* @param {object} params 提交的参数 |
|
|
|
*/ |
|
|
|
async function getProjectById(params) { |
|
|
|
try { |
|
|
|
const data = await uni.$u.api.findProjectById(params); |
|
|
|
store.commit('project/setProject', data); |
|
|
|
// 根据项目id获取角色列表
|
|
|
|
getRoles(params); |
|
|
|
} catch (error) { |
|
|
|
console.log('error: ', error || '获取项目信息失败'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -65,44 +51,23 @@ export default function useInit() { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过项目id获取项目信息 |
|
|
|
* @param {object} params 提交的参数 |
|
|
|
*/ |
|
|
|
async function getProjectById(params) { |
|
|
|
try { |
|
|
|
const data = await uni.$u.api.findProjectById(params); |
|
|
|
store.commit('project/setProject', data); |
|
|
|
// 根据项目id获取角色列表
|
|
|
|
getRoles(params); |
|
|
|
} catch (error) { |
|
|
|
console.log('error: ', error || '获取项目信息失败'); |
|
|
|
} |
|
|
|
// 设置 初始显示角色信息
|
|
|
|
function setInitialRoleId(visibleList) { |
|
|
|
if (!visibleList || !visibleList.length) return; |
|
|
|
const index = visibleList.findIndex(item => +item.mine === 1); |
|
|
|
const currentRole = index > 0 ? visibleList[index] : visibleList[0]; |
|
|
|
const storageRoleId = uni.$storage.getStorageSync('roleId'); |
|
|
|
const currentRoleId = storageRoleId || (currentRole ? currentRole.id : ''); |
|
|
|
store.commit('role/setRoleId', currentRoleId); |
|
|
|
// 清空storage
|
|
|
|
uni.$storage.setStorageSync('roleId', ''); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化 |
|
|
|
* 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) { |
|
|
|
console.log('初始化init'); |
|
|
|
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); |
|
|
|
|
|
|
@ -114,43 +79,26 @@ export default function useInit() { |
|
|
|
uni.$storage.setStorageSync('roleId', ''); |
|
|
|
} |
|
|
|
// 根据项目id获取项目信息
|
|
|
|
const params = { |
|
|
|
projectId: options.p, |
|
|
|
num: 0, |
|
|
|
}; |
|
|
|
const params = { projectId: options.p, num: 0 }; |
|
|
|
getProjectById(params); |
|
|
|
// 查询医院是否填写了调查问卷
|
|
|
|
// this.handleQueryNotWrite(options.p);
|
|
|
|
// 根据项目id获取成员列表
|
|
|
|
store.dispatch('role/getAllMembers', { |
|
|
|
projectId: options.p, |
|
|
|
}); |
|
|
|
store.dispatch('role/getAllMembers', { projectId: options.p }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 分享链接来的初始化
|
|
|
|
async function shareInit(options) { |
|
|
|
console.log('分享链接来的初始化init'); |
|
|
|
const storageUser = uni.$storage.getStorageSync('user'); |
|
|
|
const user = storageUser ? JSON.parse(storageUser) : null; |
|
|
|
if (user && user.id) { |
|
|
|
await store.dispatch('user/getToken', user.id); |
|
|
|
const res = await clickShare({ |
|
|
|
code: options.shareId, |
|
|
|
}); |
|
|
|
const res = await clickShare({ code: options.shareId }); |
|
|
|
if (res && res.projectId) { |
|
|
|
let query = { |
|
|
|
...uni.$route.query, |
|
|
|
}; |
|
|
|
query = { |
|
|
|
u: user.id, |
|
|
|
p: res.projectId, |
|
|
|
}; |
|
|
|
uni.$router.push({ |
|
|
|
path: uni.$route.path, |
|
|
|
query, |
|
|
|
}); |
|
|
|
console.log('query', query); |
|
|
|
let query = { ...uni.$route.query }; |
|
|
|
query = { u: user.id, p: res.projectId }; |
|
|
|
uni.$router.push({ path: uni.$route.path, query }); |
|
|
|
init(query); |
|
|
|
} |
|
|
|
} else { |
|
|
@ -158,7 +106,5 @@ export default function useInit() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
init, |
|
|
|
}; |
|
|
|
return { init }; |
|
|
|
} |
|
|
|