增加处理待办前,判断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 { navigateBack } from "@/utils/uniapp";
|
||||
import { xsQjFindByIdApi, xsQjSpApi } from "@/api/base/server";
|
||||
import { useDataStore } from "@/store/modules/data";
|
||||
import { useUserStore } from "@/store/modules/user";
|
||||
import { useDataStore } from "@/store/modules/data";
|
||||
import { ref, nextTick } from "vue";
|
||||
import { xxtsFindByIdApi, xxtsBlApi } from "@/api/base/server";
|
||||
|
||||
const { getJs, loginByOpenId } = useUserStore();
|
||||
const { getData, setXxts, setData, getXxts } = useDataStore();
|
||||
const { getJs } = useUserStore();
|
||||
|
||||
const dbFlag = ref(false);
|
||||
|
||||
@ -141,6 +141,13 @@ onLoad(async (data: any) => {
|
||||
if (data && data.from && data.from == "db") {
|
||||
dbFlag.value = true;
|
||||
|
||||
// 检查登录状态
|
||||
const isLoggedIn = await loginByOpenId(data.openId);
|
||||
if (!isLoggedIn) {
|
||||
console.log("用户未登录,跳过处理");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 优先从后端根据url中的id去查询Xxts
|
||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||
|
||||
@ -8,8 +8,12 @@
|
||||
import { findQjById } from "@/api/base/jsQjApi";
|
||||
import { xxtsFindByIdApi } from "@/api/base/server";
|
||||
import { useDataStore } from "@/store/modules/data";
|
||||
import { useUserStore } from "@/store/modules/user";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { ref, computed, nextTick } from "vue";
|
||||
import JsQjEdit from "./components/jsQjEdit.vue";
|
||||
|
||||
const { getJs, loginByOpenId } = useUserStore();
|
||||
const { setData, getData, setXxts, getXxts } = useDataStore();
|
||||
|
||||
const dbFlag = ref(false);
|
||||
@ -21,6 +25,13 @@ onLoad(async (data: any) => {
|
||||
if (data && data.from && data.from == "db") {
|
||||
dbFlag.value = true;
|
||||
|
||||
// 检查登录状态
|
||||
const isLoggedIn = await loginByOpenId(data.openId);
|
||||
if (!isLoggedIn) {
|
||||
console.log("用户未登录,跳过处理");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 优先从后端根据url中的id去查询Xxts
|
||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||
|
||||
@ -96,7 +96,7 @@ import { navigateBack } from "@/utils/uniapp";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { ref } from "vue";
|
||||
import JsQjDetail from "./components/jsQjDetail.vue";
|
||||
const { getJs } = useUserStore();
|
||||
const { getJs, loginByOpenId } = useUserStore();
|
||||
const { setData, getData, setXxts, getXxts } = useDataStore();
|
||||
|
||||
const dkList = ref<any>([]);
|
||||
@ -191,6 +191,13 @@ onLoad(async (data: any) => {
|
||||
if (data && data.from && data.from == "db") {
|
||||
dbFlag.value = true;
|
||||
|
||||
// 检查登录状态
|
||||
const isLoggedIn = await loginByOpenId(data.openId);
|
||||
if (!isLoggedIn) {
|
||||
console.log("用户未登录,跳过处理");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 优先从后端根据url中的id去查询Xxts
|
||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||
|
||||
@ -77,7 +77,7 @@ import { navigateBack } from "@/utils/uniapp";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { ref } from "vue";
|
||||
import JsQjDetail from "./components/jsQjDetail.vue";
|
||||
const { getJs } = useUserStore();
|
||||
const { getJs, loginByOpenId } = useUserStore();
|
||||
const { setData, getData, setXxts, getXxts } = useDataStore();
|
||||
|
||||
const dbFlag = ref(false);
|
||||
@ -185,6 +185,13 @@ onLoad(async (data: any) => {
|
||||
if (data && data.from && data.from == "db") {
|
||||
dbFlag.value = true;
|
||||
|
||||
// 检查登录状态
|
||||
const isLoggedIn = await loginByOpenId(data.openId);
|
||||
if (!isLoggedIn) {
|
||||
console.log("用户未登录,跳过处理");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 优先从后端根据url中的id去查询Xxts
|
||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||
|
||||
@ -56,7 +56,7 @@ import { onLoad } from "@dcloudio/uni-app";
|
||||
import { ref, nextTick } from "vue";
|
||||
import JsQjDetail from "./components/jsQjDetail.vue";
|
||||
import JsQjDkEdit from "./components/jsQjDkEdit.vue";
|
||||
const { getJs } = useUserStore();
|
||||
const { getJs, loginByOpenId } = useUserStore();
|
||||
const { setData, getData, setXxts, getXxts } = useDataStore();
|
||||
|
||||
const dkRef = ref<any>(null);
|
||||
@ -132,6 +132,13 @@ onLoad(async (data: any) => {
|
||||
if (data && data.from && data.from == "db") {
|
||||
dbFlag.value = true;
|
||||
|
||||
// 检查登录状态
|
||||
const isLoggedIn = await loginByOpenId(data.openId);
|
||||
if (!isLoggedIn) {
|
||||
console.log("用户未登录,跳过处理");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 优先从后端根据url中的id去查询Xxts
|
||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||
|
||||
@ -54,7 +54,7 @@ import { navigateBack } from "@/utils/uniapp";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { ref } from "vue";
|
||||
import JsQjDetail from "./components/jsQjDetail.vue";
|
||||
const { getJs } = useUserStore();
|
||||
const { getJs, loginByOpenId } = useUserStore();
|
||||
const { setData, getData, setXxts, getXxts } = useDataStore();
|
||||
|
||||
const dbFlag = ref(false);
|
||||
@ -116,6 +116,13 @@ onLoad(async (data: any) => {
|
||||
if (data && data.from && data.from == "db") {
|
||||
dbFlag.value = true;
|
||||
|
||||
// 检查登录状态
|
||||
const isLoggedIn = await loginByOpenId(data.openId);
|
||||
if (!isLoggedIn) {
|
||||
console.log("用户未登录,跳过处理");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 优先从后端根据url中的id去查询Xxts
|
||||
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
|
||||
|
||||
@ -1,118 +1,156 @@
|
||||
import {defineStore} from "pinia";
|
||||
import {authenticationApi, loginCode, loginPass, weChatLogin} from "@/api/system/login";
|
||||
import {AUTH_KEY} from "@/config";
|
||||
import { defineStore } from "pinia";
|
||||
import {
|
||||
authenticationApi,
|
||||
loginCode,
|
||||
loginPass,
|
||||
weChatLogin,
|
||||
checkOpenId,
|
||||
} from "@/api/system/login";
|
||||
import { AUTH_KEY } from "@/config";
|
||||
import { useDicStore } from "@/store/modules/dic";
|
||||
import { useCommonStore } from "@/store/modules/common";
|
||||
|
||||
interface UserState {
|
||||
userdata: any;
|
||||
jsData: any;
|
||||
token: string;
|
||||
auth: string[]
|
||||
userdata: any;
|
||||
jsData: any;
|
||||
token: string;
|
||||
auth: string[];
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore({
|
||||
id: "app-user",
|
||||
state: (): UserState => ({
|
||||
//用户数据
|
||||
userdata: {},
|
||||
//用户数据
|
||||
jsData: {},
|
||||
// token
|
||||
token: '',
|
||||
//用户注册信息
|
||||
auth: [],
|
||||
}),
|
||||
getters: {
|
||||
getToken(): string {
|
||||
return this.token;
|
||||
},
|
||||
getUser(): any {
|
||||
return this.userdata;
|
||||
},
|
||||
getJs(): any {
|
||||
return this.jsData;
|
||||
},
|
||||
getAuth(): string[] {
|
||||
return this.auth;
|
||||
id: "app-user",
|
||||
state: (): UserState => ({
|
||||
//用户数据
|
||||
userdata: {},
|
||||
//用户数据
|
||||
jsData: {},
|
||||
// token
|
||||
token: "",
|
||||
//用户注册信息
|
||||
auth: [],
|
||||
}),
|
||||
getters: {
|
||||
getToken(): string {
|
||||
return this.token;
|
||||
},
|
||||
getUser(): any {
|
||||
return this.userdata;
|
||||
},
|
||||
getJs(): any {
|
||||
return this.jsData;
|
||||
},
|
||||
getAuth(): string[] {
|
||||
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) {
|
||||
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)
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @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({});
|
||||
},
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
});
|
||||
},
|
||||
persist: {
|
||||
enabled: true,
|
||||
detached: true,
|
||||
H5Storage: localStorage
|
||||
/**
|
||||
* @description: 注销
|
||||
*/
|
||||
logout() {
|
||||
this.setToken("");
|
||||
this.setUser({});
|
||||
this.setJs({});
|
||||
this.setAuth([]);
|
||||
useDicStore().setData({});
|
||||
useCommonStore().setData({});
|
||||
},
|
||||
},
|
||||
persist: {
|
||||
enabled: true,
|
||||
detached: true,
|
||||
H5Storage: localStorage,
|
||||
},
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user