增加处理待办前,判断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,5 +1,11 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import {authenticationApi, loginCode, loginPass, weChatLogin} from "@/api/system/login"; import {
authenticationApi,
loginCode,
loginPass,
weChatLogin,
checkOpenId,
} from "@/api/system/login";
import { AUTH_KEY } from "@/config"; 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,
}, },
}); });