增加处理待办前,判断openId
This commit is contained in:
parent
b0a8ead56a
commit
cb611b2d0c
@ -71,13 +71,13 @@ import { onLoad } from "@dcloudio/uni-app";
|
|||||||
import { useForm } from "@/components/BasicForm/hooks/useForm";
|
import { useForm } from "@/components/BasicForm/hooks/useForm";
|
||||||
import { navigateBack } from "@/utils/uniapp";
|
import { navigateBack } from "@/utils/uniapp";
|
||||||
import { xsQjFindByIdApi, xsQjSpApi } from "@/api/base/server";
|
import { xsQjFindByIdApi, xsQjSpApi } from "@/api/base/server";
|
||||||
import { useDataStore } from "@/store/modules/data";
|
|
||||||
import { useUserStore } from "@/store/modules/user";
|
import { useUserStore } from "@/store/modules/user";
|
||||||
|
import { useDataStore } from "@/store/modules/data";
|
||||||
import { ref, nextTick } from "vue";
|
import { ref, nextTick } from "vue";
|
||||||
import { xxtsFindByIdApi, xxtsBlApi } from "@/api/base/server";
|
import { xxtsFindByIdApi, xxtsBlApi } from "@/api/base/server";
|
||||||
|
|
||||||
|
const { getJs, loginByOpenId } = useUserStore();
|
||||||
const { getData, setXxts, setData, getXxts } = useDataStore();
|
const { getData, setXxts, setData, getXxts } = useDataStore();
|
||||||
const { getJs } = useUserStore();
|
|
||||||
|
|
||||||
const dbFlag = ref(false);
|
const dbFlag = ref(false);
|
||||||
|
|
||||||
@ -141,6 +141,13 @@ onLoad(async (data: any) => {
|
|||||||
if (data && data.from && data.from == "db") {
|
if (data && data.from && data.from == "db") {
|
||||||
dbFlag.value = true;
|
dbFlag.value = true;
|
||||||
|
|
||||||
|
// 检查登录状态
|
||||||
|
const isLoggedIn = await loginByOpenId(data.openId);
|
||||||
|
if (!isLoggedIn) {
|
||||||
|
console.log("用户未登录,跳过处理");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 优先从后端根据url中的id去查询Xxts
|
// 优先从后端根据url中的id去查询Xxts
|
||||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||||
|
|||||||
@ -8,8 +8,12 @@
|
|||||||
import { findQjById } from "@/api/base/jsQjApi";
|
import { findQjById } from "@/api/base/jsQjApi";
|
||||||
import { xxtsFindByIdApi } from "@/api/base/server";
|
import { xxtsFindByIdApi } from "@/api/base/server";
|
||||||
import { useDataStore } from "@/store/modules/data";
|
import { useDataStore } from "@/store/modules/data";
|
||||||
|
import { useUserStore } from "@/store/modules/user";
|
||||||
import { onLoad } from "@dcloudio/uni-app";
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
|
import { ref, computed, nextTick } from "vue";
|
||||||
import JsQjEdit from "./components/jsQjEdit.vue";
|
import JsQjEdit from "./components/jsQjEdit.vue";
|
||||||
|
|
||||||
|
const { getJs, loginByOpenId } = useUserStore();
|
||||||
const { setData, getData, setXxts, getXxts } = useDataStore();
|
const { setData, getData, setXxts, getXxts } = useDataStore();
|
||||||
|
|
||||||
const dbFlag = ref(false);
|
const dbFlag = ref(false);
|
||||||
@ -21,6 +25,13 @@ onLoad(async (data: any) => {
|
|||||||
if (data && data.from && data.from == "db") {
|
if (data && data.from && data.from == "db") {
|
||||||
dbFlag.value = true;
|
dbFlag.value = true;
|
||||||
|
|
||||||
|
// 检查登录状态
|
||||||
|
const isLoggedIn = await loginByOpenId(data.openId);
|
||||||
|
if (!isLoggedIn) {
|
||||||
|
console.log("用户未登录,跳过处理");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 优先从后端根据url中的id去查询Xxts
|
// 优先从后端根据url中的id去查询Xxts
|
||||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||||
|
|||||||
@ -96,7 +96,7 @@ import { navigateBack } from "@/utils/uniapp";
|
|||||||
import { onLoad } from "@dcloudio/uni-app";
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import JsQjDetail from "./components/jsQjDetail.vue";
|
import JsQjDetail from "./components/jsQjDetail.vue";
|
||||||
const { getJs } = useUserStore();
|
const { getJs, loginByOpenId } = useUserStore();
|
||||||
const { setData, getData, setXxts, getXxts } = useDataStore();
|
const { setData, getData, setXxts, getXxts } = useDataStore();
|
||||||
|
|
||||||
const dkList = ref<any>([]);
|
const dkList = ref<any>([]);
|
||||||
@ -191,6 +191,13 @@ onLoad(async (data: any) => {
|
|||||||
if (data && data.from && data.from == "db") {
|
if (data && data.from && data.from == "db") {
|
||||||
dbFlag.value = true;
|
dbFlag.value = true;
|
||||||
|
|
||||||
|
// 检查登录状态
|
||||||
|
const isLoggedIn = await loginByOpenId(data.openId);
|
||||||
|
if (!isLoggedIn) {
|
||||||
|
console.log("用户未登录,跳过处理");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 优先从后端根据url中的id去查询Xxts
|
// 优先从后端根据url中的id去查询Xxts
|
||||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||||
|
|||||||
@ -77,7 +77,7 @@ import { navigateBack } from "@/utils/uniapp";
|
|||||||
import { onLoad } from "@dcloudio/uni-app";
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import JsQjDetail from "./components/jsQjDetail.vue";
|
import JsQjDetail from "./components/jsQjDetail.vue";
|
||||||
const { getJs } = useUserStore();
|
const { getJs, loginByOpenId } = useUserStore();
|
||||||
const { setData, getData, setXxts, getXxts } = useDataStore();
|
const { setData, getData, setXxts, getXxts } = useDataStore();
|
||||||
|
|
||||||
const dbFlag = ref(false);
|
const dbFlag = ref(false);
|
||||||
@ -185,6 +185,13 @@ onLoad(async (data: any) => {
|
|||||||
if (data && data.from && data.from == "db") {
|
if (data && data.from && data.from == "db") {
|
||||||
dbFlag.value = true;
|
dbFlag.value = true;
|
||||||
|
|
||||||
|
// 检查登录状态
|
||||||
|
const isLoggedIn = await loginByOpenId(data.openId);
|
||||||
|
if (!isLoggedIn) {
|
||||||
|
console.log("用户未登录,跳过处理");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 优先从后端根据url中的id去查询Xxts
|
// 优先从后端根据url中的id去查询Xxts
|
||||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||||
|
|||||||
@ -56,7 +56,7 @@ import { onLoad } from "@dcloudio/uni-app";
|
|||||||
import { ref, nextTick } from "vue";
|
import { ref, nextTick } from "vue";
|
||||||
import JsQjDetail from "./components/jsQjDetail.vue";
|
import JsQjDetail from "./components/jsQjDetail.vue";
|
||||||
import JsQjDkEdit from "./components/jsQjDkEdit.vue";
|
import JsQjDkEdit from "./components/jsQjDkEdit.vue";
|
||||||
const { getJs } = useUserStore();
|
const { getJs, loginByOpenId } = useUserStore();
|
||||||
const { setData, getData, setXxts, getXxts } = useDataStore();
|
const { setData, getData, setXxts, getXxts } = useDataStore();
|
||||||
|
|
||||||
const dkRef = ref<any>(null);
|
const dkRef = ref<any>(null);
|
||||||
@ -132,6 +132,13 @@ onLoad(async (data: any) => {
|
|||||||
if (data && data.from && data.from == "db") {
|
if (data && data.from && data.from == "db") {
|
||||||
dbFlag.value = true;
|
dbFlag.value = true;
|
||||||
|
|
||||||
|
// 检查登录状态
|
||||||
|
const isLoggedIn = await loginByOpenId(data.openId);
|
||||||
|
if (!isLoggedIn) {
|
||||||
|
console.log("用户未登录,跳过处理");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 优先从后端根据url中的id去查询Xxts
|
// 优先从后端根据url中的id去查询Xxts
|
||||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||||
|
|||||||
@ -54,7 +54,7 @@ import { navigateBack } from "@/utils/uniapp";
|
|||||||
import { onLoad } from "@dcloudio/uni-app";
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import JsQjDetail from "./components/jsQjDetail.vue";
|
import JsQjDetail from "./components/jsQjDetail.vue";
|
||||||
const { getJs } = useUserStore();
|
const { getJs, loginByOpenId } = useUserStore();
|
||||||
const { setData, getData, setXxts, getXxts } = useDataStore();
|
const { setData, getData, setXxts, getXxts } = useDataStore();
|
||||||
|
|
||||||
const dbFlag = ref(false);
|
const dbFlag = ref(false);
|
||||||
@ -116,6 +116,13 @@ onLoad(async (data: any) => {
|
|||||||
if (data && data.from && data.from == "db") {
|
if (data && data.from && data.from == "db") {
|
||||||
dbFlag.value = true;
|
dbFlag.value = true;
|
||||||
|
|
||||||
|
// 检查登录状态
|
||||||
|
const isLoggedIn = await loginByOpenId(data.openId);
|
||||||
|
if (!isLoggedIn) {
|
||||||
|
console.log("用户未登录,跳过处理");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 优先从后端根据url中的id去查询Xxts
|
// 优先从后端根据url中的id去查询Xxts
|
||||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||||
|
|||||||
@ -1,6 +1,12 @@
|
|||||||
import {defineStore} from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import {authenticationApi, loginCode, loginPass, weChatLogin} from "@/api/system/login";
|
import {
|
||||||
import {AUTH_KEY} from "@/config";
|
authenticationApi,
|
||||||
|
loginCode,
|
||||||
|
loginPass,
|
||||||
|
weChatLogin,
|
||||||
|
checkOpenId,
|
||||||
|
} from "@/api/system/login";
|
||||||
|
import { AUTH_KEY } from "@/config";
|
||||||
import { useDicStore } from "@/store/modules/dic";
|
import { useDicStore } from "@/store/modules/dic";
|
||||||
import { useCommonStore } from "@/store/modules/common";
|
import { useCommonStore } from "@/store/modules/common";
|
||||||
|
|
||||||
@ -8,7 +14,7 @@ interface UserState {
|
|||||||
userdata: any;
|
userdata: any;
|
||||||
jsData: any;
|
jsData: any;
|
||||||
token: string;
|
token: string;
|
||||||
auth: string[]
|
auth: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useUserStore = defineStore({
|
export const useUserStore = defineStore({
|
||||||
@ -19,7 +25,7 @@ export const useUserStore = defineStore({
|
|||||||
//用户数据
|
//用户数据
|
||||||
jsData: {},
|
jsData: {},
|
||||||
// token
|
// token
|
||||||
token: '',
|
token: "",
|
||||||
//用户注册信息
|
//用户注册信息
|
||||||
auth: [],
|
auth: [],
|
||||||
}),
|
}),
|
||||||
@ -35,11 +41,11 @@ export const useUserStore = defineStore({
|
|||||||
},
|
},
|
||||||
getAuth(): string[] {
|
getAuth(): string[] {
|
||||||
return this.auth;
|
return this.auth;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
setToken(token: string) {
|
setToken(token: string) {
|
||||||
this.token = token
|
this.token = token;
|
||||||
},
|
},
|
||||||
setUser(data: any) {
|
setUser(data: any) {
|
||||||
this.userdata = data;
|
this.userdata = data;
|
||||||
@ -53,59 +59,91 @@ export const useUserStore = defineStore({
|
|||||||
/**
|
/**
|
||||||
* @description: 验证码登录
|
* @description: 验证码登录
|
||||||
*/
|
*/
|
||||||
async codeLogin(params: { phone: number | string, code: number | string }) {
|
async codeLogin(params: { phone: number | string; code: number | string }) {
|
||||||
try {
|
try {
|
||||||
const {result} = await loginCode({phone: params.phone, code: params.code});
|
const { result } = await loginCode({
|
||||||
this.afterLoginAction(result)
|
phone: params.phone,
|
||||||
|
code: params.code,
|
||||||
|
});
|
||||||
|
this.afterLoginAction(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @description: 密码登录
|
* @description: 密码登录
|
||||||
*/
|
*/
|
||||||
async passwordLogin(params: { name: string, password: string }) {
|
async passwordLogin(params: { name: string; password: string }) {
|
||||||
try {
|
try {
|
||||||
const {result} = await loginPass({username: params.name, password: params.password});
|
const { result } = await loginPass({
|
||||||
this.afterLoginAction(result)
|
username: params.name,
|
||||||
} catch (e) {
|
password: params.password,
|
||||||
|
});
|
||||||
}
|
this.afterLoginAction(result);
|
||||||
|
} catch (e) {}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @description: 微信登录
|
* @description: 微信登录
|
||||||
*/
|
*/
|
||||||
async weChatLogin(params: { code: string }) {
|
async weChatLogin(params: { code: string }) {
|
||||||
try {
|
try {
|
||||||
const {result} = await weChatLogin({code: params.code})
|
const { result } = await weChatLogin({ code: params.code });
|
||||||
this.afterLoginAction(result)
|
this.afterLoginAction(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async loginByOpenId(openId: string) {
|
||||||
|
try {
|
||||||
|
// 先校验当前登录的用户的openid,如果和传入的openid匹配,直接返回true
|
||||||
|
if (this.userdata && this.userdata.openId && openId && this.userdata.openId === openId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 如果当前登录的用户的openid和传入的openid不匹配,则调用checkOpenId接口进行校验
|
||||||
|
const res = await checkOpenId({
|
||||||
|
openId,
|
||||||
|
appCode: "JS",
|
||||||
|
});
|
||||||
|
if (res.resultCode == 1 && res.result) {
|
||||||
|
this.afterLoginAction(res.result);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
uni.reLaunch({
|
||||||
|
url: "/pages/system/login/login",
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
uni.reLaunch({
|
||||||
|
url: "/pages/system/login/login",
|
||||||
|
});
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @description: 登录成功后的操作
|
* @description: 登录成功后的操作
|
||||||
*/
|
*/
|
||||||
afterLoginAction(value: any) {
|
afterLoginAction(value: any) {
|
||||||
this.setUser(value)
|
this.setUser(value);
|
||||||
this.setJs(value.js);
|
this.setJs(value.js);
|
||||||
if (value[AUTH_KEY]) {
|
if (value[AUTH_KEY]) {
|
||||||
this.setToken(value[AUTH_KEY])
|
this.setToken(value[AUTH_KEY]);
|
||||||
}
|
}
|
||||||
authenticationApi({userId: value.id}).then(({result}) => {
|
authenticationApi({ userId: value.id }).then(({ result }) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
this.setAuth(result)
|
this.setAuth(result);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @description: 注销
|
* @description: 注销
|
||||||
*/
|
*/
|
||||||
logout() {
|
logout() {
|
||||||
this.setToken('')
|
this.setToken("");
|
||||||
this.setUser({})
|
this.setUser({});
|
||||||
this.setJs({})
|
this.setJs({});
|
||||||
this.setAuth([])
|
this.setAuth([]);
|
||||||
useDicStore().setData({});
|
useDicStore().setData({});
|
||||||
useCommonStore().setData({});
|
useCommonStore().setData({});
|
||||||
},
|
},
|
||||||
@ -113,6 +151,6 @@ export const useUserStore = defineStore({
|
|||||||
persist: {
|
persist: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
detached: true,
|
detached: true,
|
||||||
H5Storage: localStorage
|
H5Storage: localStorage,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user