增加处理待办前,判断openId

This commit is contained in:
ywyonui 2025-08-02 14:23:51 +08:00
parent b0a8ead56a
commit cb611b2d0c
7 changed files with 196 additions and 112 deletions

View File

@ -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 {
// urlidXxts // urlidXxts
const xxtsRes = await xxtsFindByIdApi({ id: data.id }); const xxtsRes = await xxtsFindByIdApi({ id: data.id });

View File

@ -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 {
// urlidXxts // urlidXxts
const xxtsRes = await xxtsFindByIdApi({ id: data.id }); const xxtsRes = await xxtsFindByIdApi({ id: data.id });

View File

@ -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 {
// urlidXxts // urlidXxts
const xxtsRes = await xxtsFindByIdApi({ id: data.id }); const xxtsRes = await xxtsFindByIdApi({ id: data.id });

View File

@ -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 {
// urlidXxts // urlidXxts
const xxtsRes = await xxtsFindByIdApi({ id: data.id }); const xxtsRes = await xxtsFindByIdApi({ id: data.id });

View File

@ -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 {
// urlidXxts // urlidXxts
const xxtsRes = await xxtsFindByIdApi({ id: data.id }); const xxtsRes = await xxtsFindByIdApi({ id: data.id });

View File

@ -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 {
// urlidXxts // urlidXxts
const xxtsRes = await xxtsFindByIdApi({ id: data.id }); const xxtsRes = await xxtsFindByIdApi({ id: data.id });

View File

@ -1,118 +1,156 @@
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";
interface UserState { 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({
id: "app-user", id: "app-user",
state: (): UserState => ({ state: (): UserState => ({
//用户数据 //用户数据
userdata: {}, userdata: {},
//用户数据 //用户数据
jsData: {}, jsData: {},
// token // token
token: '', token: "",
//用户注册信息 //用户注册信息
auth: [], auth: [],
}), }),
getters: { getters: {
getToken(): string { getToken(): string {
return this.token; return this.token;
}, },
getUser(): any { getUser(): any {
return this.userdata; return this.userdata;
}, },
getJs(): any { getJs(): any {
return this.jsData; return this.jsData;
}, },
getAuth(): string[] { getAuth(): string[] {
return this.auth; return this.auth;
},
},
actions: {
setToken(token: string) {
this.token = token;
},
setUser(data: any) {
this.userdata = data;
},
setJs(data: any) {
this.jsData = data;
},
setAuth(data: string[]) {
this.auth = data;
},
/**
* @description:
*/
async codeLogin(params: { phone: number | string; code: number | string }) {
try {
const { result } = await loginCode({
phone: params.phone,
code: params.code,
});
this.afterLoginAction(result);
} catch (e) {
console.log(e);
}
},
/**
* @description:
*/
async passwordLogin(params: { name: string; password: string }) {
try {
const { result } = await loginPass({
username: params.name,
password: params.password,
});
this.afterLoginAction(result);
} catch (e) {}
},
/**
* @description:
*/
async weChatLogin(params: { code: string }) {
try {
const { result } = await weChatLogin({ code: params.code });
this.afterLoginAction(result);
} catch (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;
}
}, },
actions: { /**
setToken(token: string) { * @description:
this.token = token */
}, afterLoginAction(value: any) {
setUser(data: any) { this.setUser(value);
this.userdata = data; this.setJs(value.js);
}, if (value[AUTH_KEY]) {
setJs(data: any) { this.setToken(value[AUTH_KEY]);
this.jsData = data; }
}, authenticationApi({ userId: value.id }).then(({ result }) => {
setAuth(data: string[]) { if (result) {
this.auth = data; this.setAuth(result);
}, }
/** });
* @description:
*/
async codeLogin(params: { phone: number | string, code: number | string }) {
try {
const {result} = await loginCode({phone: params.phone, code: params.code});
this.afterLoginAction(result)
} catch (e) {
console.log(e)
}
},
/**
* @description:
*/
async passwordLogin(params: { name: string, password: string }) {
try {
const {result} = await loginPass({username: params.name, password: params.password});
this.afterLoginAction(result)
} catch (e) {
}
},
/**
* @description:
*/
async weChatLogin(params: { code: string }) {
try {
const {result} = await weChatLogin({code: params.code})
this.afterLoginAction(result)
} catch (e) {
console.log(e)
}
},
/**
* @description:
*/
afterLoginAction(value: any) {
this.setUser(value)
this.setJs(value.js);
if (value[AUTH_KEY]) {
this.setToken(value[AUTH_KEY])
}
authenticationApi({userId: value.id}).then(({result}) => {
if (result) {
this.setAuth(result)
}
})
},
/**
* @description:
*/
logout() {
this.setToken('')
this.setUser({})
this.setJs({})
this.setAuth([])
useDicStore().setData({});
useCommonStore().setData({});
},
}, },
persist: { /**
enabled: true, * @description:
detached: true, */
H5Storage: localStorage logout() {
this.setToken("");
this.setUser({});
this.setJs({});
this.setAuth([]);
useDicStore().setData({});
useCommonStore().setData({});
}, },
},
persist: {
enabled: true,
detached: true,
H5Storage: localStorage,
},
}); });