From 2caaffc58192420db369638113a39848867be2d1 Mon Sep 17 00:00:00 2001 From: Net Date: Fri, 30 May 2025 15:06:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8A=A9=E6=95=99=E7=AB=AF?= =?UTF-8?q?=20=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/system/launchPage/launchPage.vue | 1 - src/pages/system/login/login.vue | 45 ++-- src/utils/request/index.ts | 294 ++++++++++++--------- 3 files changed, 199 insertions(+), 141 deletions(-) diff --git a/src/pages/system/launchPage/launchPage.vue b/src/pages/system/launchPage/launchPage.vue index b73d98f..ea8e11a 100644 --- a/src/pages/system/launchPage/launchPage.vue +++ b/src/pages/system/launchPage/launchPage.vue @@ -34,7 +34,6 @@ function toHome(data: any) { } } onLoad(async (data: any) => { - console.log(data); if (data && data.openId) { setGlobal(data); checkOpenId({ diff --git a/src/pages/system/login/login.vue b/src/pages/system/login/login.vue index fe0fe1c..838e3e3 100644 --- a/src/pages/system/login/login.vue +++ b/src/pages/system/login/login.vue @@ -96,7 +96,6 @@ import { updateUserApi, } from "@/api/system/login"; import { useUserStore } from "@/store/modules/user"; -import pages from "@/pages.json"; const { getGlobal } = useDataStore(); const formData = reactive({ loginName: "", @@ -179,30 +178,34 @@ const handleVerify = async () => { appCode: getGlobal.type == 1 ? "ZB" : "JS", }); if (result.resultCode == 1) { - afterLoginAction(result.result); - uni.showToast({ title: "验证成功", icon: "success" }); - if (getGlobal.type == 1) { - toHome(getGlobal); - } else { - const findJsByPhoneResult = await findJsByPhoneApi({ - phone: formData.phone, - }); - if (findJsByPhoneResult.resultCode == 1) { - if (findJsByPhoneResult.result) { - if (findJsByPhoneResult.result["confirmStatus"] == "A") { - toHome(getGlobal); + if (result.result) { + afterLoginAction(result.result); + uni.showToast({ title: "验证成功", icon: "success" }); + if (getGlobal.type == 1) { + toHome(getGlobal); + } else { + const findJsByPhoneResult = await findJsByPhoneApi({ + phone: formData.phone, + }); + if (findJsByPhoneResult.resultCode == 1) { + if (findJsByPhoneResult.result) { + if (findJsByPhoneResult.result["confirmStatus"] == "A") { + toHome(getGlobal); + } else { + setFile(findJsByPhoneResult.result); + setTimeout(() => { + uni.reLaunch({ + url: "/pages/view/hr/teacherProfile/index", + }); + }, 1500); + } } else { - setFile(findJsByPhoneResult.result); - setTimeout(() => { - uni.reLaunch({ - url: "/pages/view/hr/teacherProfile/index", - }); - }, 1500); + toHome(getGlobal); } - } else { - toHome(getGlobal); } } + } else { + uni.showToast({ title: result.message || "验证失败", icon: "none" }); } } else { uni.showToast({ title: result.message || "验证失败", icon: "none" }); diff --git a/src/utils/request/index.ts b/src/utils/request/index.ts index 1685e80..004a099 100644 --- a/src/utils/request/index.ts +++ b/src/utils/request/index.ts @@ -1,133 +1,189 @@ -import {AUTH_KEY, BASE_URL, HOMEAGENT, RESULT_CODE_NOT_LOGIN} from "@/config"; -import {useUserStore} from "@/store/modules/user"; -import {getLogin} from "../permission"; -import {request} from "@/utils/request/request"; -import {showToast} from "@/utils/uniapp"; +import { AUTH_KEY, BASE_URL, HOMEAGENT, RESULT_CODE_NOT_LOGIN } from "@/config"; +import { useUserStore } from "@/store/modules/user"; +import { getLogin } from "../permission"; +import { request } from "@/utils/request/request"; +import { showToast } from "@/utils/uniapp"; let count: boolean = false; function _loginExpiredModal() { - const store = useUserStore(); - store.logout() - uni.showModal({ - title: '提示', - content: '登录过期,请重新登录', - showCancel: false, - success: function (res) { - if (res.confirm) { - count = false - getLogin() - } else if (res.cancel) { - count = false - uni.navigateBack({ - delta: 1, - fail: (err) => { - console.log(err) - } - }) - } - } - }); + const store = useUserStore(); + store.logout(); + uni.showModal({ + title: "提示", + content: "登录过期,请重新登录", + showCancel: false, + success: function (res) { + if (res.confirm) { + count = false; + getLogin(); + } else if (res.cancel) { + count = false; + uni.navigateBack({ + delta: 1, + fail: (err) => { + console.log(err); + }, + }); + } + }, + }); } export const config = { - baseUrl: process.env.NODE_ENV == 'development' ? HOMEAGENT ? '/base' : BASE_URL : BASE_URL, - header: {} -} + baseUrl: + process.env.NODE_ENV == "development" + ? HOMEAGENT + ? "/base" + : BASE_URL + : BASE_URL, + header: {}, +}; export const interceptor = { - request: (config: UniNamespace.UploadFileOption | UniNamespace.RequestOptions) => { - const store = useUserStore(); - if (store.getToken) { - config.header = { - [AUTH_KEY]: store.getToken - }; - } - }, - response: (response: any) => { - if (response.data && RESULT_CODE_NOT_LOGIN == response.data.resultCode) { - if (!count) { - _loginExpiredModal() - } - count = true; - return; - } - if (response.config.name === "files") { - return JSON.parse(response.data); - } - if (response.data) { - return response.data; - } else { - console.log('接口无返回值', response) - } + request: ( + config: UniNamespace.UploadFileOption | UniNamespace.RequestOptions + ) => { + const store = useUserStore(); + if (store.getToken) { + config.header = { + [AUTH_KEY]: store.getToken, + }; } + }, + response: (response: any) => { + if (response.data && RESULT_CODE_NOT_LOGIN == response.data.resultCode) { + if (!count) { + _loginExpiredModal(); + } + count = true; + return; + } + if (response.config.name === "files") { + return JSON.parse(response.data); + } + if (response.data) { + return response.data; + } else { + console.log("接口无返回值", response); + } + }, +}; + +export function get( + url: string, + data?: any, + options?: UniNamespace.RequestOptions +): Promise> { + return new Promise((resolve, reject) => { + request( + Object.assign( + {}, + { + url, + data, + method: "GET", + dataType: "json", + responseType: "text", + }, + options + ) + ).then((res) => { + if (res.resultCode == 1) { + resolve(res); + } else { + if (res.resultCode) { + if (res.resultCode != RESULT_CODE_NOT_LOGIN) { + showToast(res.message || "接口异常"); + reject(res); + } + } else { + if (res.rows) { + resolve(res); + } else { + showToast(res.message || "接口异常"); + reject(res); + } + } + } + }); + }); } -export function get(url: string, data?: any, options?: UniNamespace.RequestOptions): Promise> { - return new Promise((resolve, reject) => { - request(Object.assign({}, { - url, - data, - method: 'GET', - dataType: 'json', - responseType: 'text', - }, options)).then(res => { - if (res.resultCode == 1) { - resolve(res) - } else { - if (res.resultCode) { - if (res.resultCode != RESULT_CODE_NOT_LOGIN) { - showToast(res.message || '接口异常') - reject(res) - } - } else { - if (res.rows) { - resolve(res) - } else { - showToast(res.message || '接口异常') - reject(res) - } - } - } - }) - }) +export function post( + url: string, + data?: any, + options?: UniNamespace.RequestOptions +): Promise> { + return new Promise((resolve, reject) => { + request( + Object.assign( + {}, + { + url, + data, + method: "POST", + dataType: "json", + responseType: "text", + }, + options + ) + ).then((res) => { + if (res.resultCode == 1) { + resolve(res); + } else { + if (res.resultCode) { + if (res.resultCode != RESULT_CODE_NOT_LOGIN) { + showToast(res.message || "接口异常"); + reject(res); + } + } else { + if (res.rows) { + resolve(res); + } else { + showToast(res.message || "接口异常"); + reject(res); + } + } + } + }); + }); } - -export function post(url: string, data?: any, options?: UniNamespace.RequestOptions): Promise> { - return new Promise((resolve, reject) => { - request(Object.assign({}, { - url, - data, - method: 'POST', - dataType: 'json', - responseType: 'text', - }, options)).then(res => { - if (res.resultCode == 1) { - resolve(res) - } else { - if (res.resultCode) { - if (res.resultCode != RESULT_CODE_NOT_LOGIN) { - showToast(res.message || '接口异常') - reject(res) - } - } else { - if (res.rows) { - resolve(res) - } else { - showToast(res.message || '接口异常') - reject(res) - } - } - } - }) - }) +export function file( + url: string, + data: Blob, + options?: UniNamespace.UploadFileOption +) { + return new Promise((resolve, reject) => { + request( + Object.assign( + {}, + { + url, + filePath: data, + name: "files", + }, + options + ), + true + ).then((res) => { + if (res.resultCode == 1) { + resolve(res); + } else { + if (res.resultCode) { + if (res.resultCode != RESULT_CODE_NOT_LOGIN) { + showToast(res.message || "接口异常"); + reject(res); + } + } else { + if (res.rows) { + resolve(res); + } else { + showToast(res.message || "接口异常"); + reject(res); + } + } + } + }); + }); } - -export function file(url: string, data: Blob, options?: UniNamespace.UploadFileOption) { - return request(Object.assign({}, { - url, - filePath: data, - name: 'files', - }, options), true) -} -