From c9592446c85964aa5f863e5aad049daa8528a155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Sun, 8 Oct 2023 22:59:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yi.App.Vue3/components.d.ts | 19 +++++ Yi.App.Vue3/src/api/articleApi.ts | 5 +- Yi.App.Vue3/src/api/login.ts | 2 +- Yi.App.Vue3/src/permission.ts | 2 +- Yi.App.Vue3/src/store/modules/user.ts | 12 +-- Yi.App.Vue3/src/utils/myaxios.ts | 80 +++++++++++-------- Yi.App.Vue3/src/view/login.vue | 8 +- Yi.App.Vue3/src/view/main/recommend.vue | 14 ++-- Yi.App.Vue3/src/view/my.vue | 2 +- Yi.App.Vue3/tsconfig.json | 2 +- Yi.BBS.Vue3/src/utils/request.js | 9 ++- Yi.Furion.Net6/Yi.Furion.Web.Core/Startup.cs | 2 +- .../Yi.Furion.Web.Entry.csproj | 3 + Yi.RuoYi.Vue3/src/utils/request.js | 30 ++++--- 14 files changed, 119 insertions(+), 71 deletions(-) diff --git a/Yi.App.Vue3/components.d.ts b/Yi.App.Vue3/components.d.ts index d4bc2f34..26d80cd0 100644 --- a/Yi.App.Vue3/components.d.ts +++ b/Yi.App.Vue3/components.d.ts @@ -14,14 +14,33 @@ declare module '@vue/runtime-core' { HelloWorld: typeof import('./src/components/HelloWorld.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] + VanActionBar: typeof import('vant/es')['ActionBar'] + VanActionBarButton: typeof import('vant/es')['ActionBarButton'] + VanActionBarIcon: typeof import('vant/es')['ActionBarIcon'] VanActionSheet: typeof import('vant/es')['ActionSheet'] VanButton: typeof import('vant/es')['Button'] + VanCell: typeof import('vant/es')['Cell'] + VanCellGroup: typeof import('vant/es')['CellGroup'] VanCol: typeof import('vant/es')['Col'] + VanDivider: typeof import('vant/es')['Divider'] VanField: typeof import('vant/es')['Field'] + VanGrid: typeof import('vant/es')['Grid'] + VanGridItem: typeof import('vant/es')['GridItem'] VanIcon: typeof import('vant/es')['Icon'] + VanImage: typeof import('vant/es')['Image'] + VanList: typeof import('vant/es')['List'] + VanLoading: typeof import('vant/es')['Loading'] VanNavBar: typeof import('vant/es')['NavBar'] + VanPopup: typeof import('vant/es')['Popup'] + VanPullRefresh: typeof import('vant/es')['PullRefresh'] VanRow: typeof import('vant/es')['Row'] + VanSticky: typeof import('vant/es')['Sticky'] + VanSwipe: typeof import('vant/es')['Swipe'] + VanSwipeItem: typeof import('vant/es')['SwipeItem'] + VanTab: typeof import('vant/es')['Tab'] VanTabbar: typeof import('vant/es')['Tabbar'] VanTabbarItem: typeof import('vant/es')['TabbarItem'] + VanTabs: typeof import('vant/es')['Tabs'] + VanUploader: typeof import('vant/es')['Uploader'] } } diff --git a/Yi.App.Vue3/src/api/articleApi.ts b/Yi.App.Vue3/src/api/articleApi.ts index c7ad11a1..b76f955e 100644 --- a/Yi.App.Vue3/src/api/articleApi.ts +++ b/Yi.App.Vue3/src/api/articleApi.ts @@ -1,17 +1,16 @@ import myaxios from '@/utils/myaxios' -import { ArticleEntity } from '@/type/interface/ArticleEntity' export default { add(data:any) { return myaxios({ - url: `/article/add`, + url: `/Trends`, method: 'post', data: data }) }, pageList(data:any) { return myaxios({ - url: '/article/pageList', + url: '/Trends', method: 'get', params: data }) diff --git a/Yi.App.Vue3/src/api/login.ts b/Yi.App.Vue3/src/api/login.ts index cb1f59c1..900fead9 100644 --- a/Yi.App.Vue3/src/api/login.ts +++ b/Yi.App.Vue3/src/api/login.ts @@ -33,7 +33,7 @@ export function register(data:any) { // 获取用户详细信息 export function getInfo() { return myaxios({ - url: '/account/getUserAllInfo', + url: '/account', method: 'get' }) } diff --git a/Yi.App.Vue3/src/permission.ts b/Yi.App.Vue3/src/permission.ts index 00dae628..a9a940df 100644 --- a/Yi.App.Vue3/src/permission.ts +++ b/Yi.App.Vue3/src/permission.ts @@ -4,7 +4,7 @@ import router from './router' // import 'nprogress/nprogress.css' import { getToken } from '@/utils/auth' // import { isHttp } from '@/utils/validate' -import useUserStore from '@/store/modules/user' +import useUserStore from '@/store/modules/user.js' import { isRelogin } from '@/utils/myaxios' // import useSettingsStore from '@/store/modules/settings' // import usePermissionStore from '@/store/modules/permission' diff --git a/Yi.App.Vue3/src/store/modules/user.ts b/Yi.App.Vue3/src/store/modules/user.ts index bb84d008..cbbec122 100644 --- a/Yi.App.Vue3/src/store/modules/user.ts +++ b/Yi.App.Vue3/src/store/modules/user.ts @@ -21,21 +21,23 @@ const useUserStore = defineStore( return new Promise((resolve, reject) => { login(username, password, code, uuid).then(res => { - if(!res.status) + if(!(res as any).succeeded) { reject(res) } setToken(res.data.token); this.token = res.data.token; - resolve(res); + + return resolve(res); }).catch(error => { - reject(error) + return reject(error) }) }) }, // 获取用户信息 getInfo() { return new Promise((resolve, reject) => { + getInfo().then(response => { const res=response.data; const user = res.user @@ -55,9 +57,9 @@ const useUserStore = defineStore( this.user.username = user.userName; this.user.nick=user.nick this.user.icon = user.icon; - resolve(res) + resolve(res) }).catch(error => { - reject(error) + reject(error) }) diff --git a/Yi.App.Vue3/src/utils/myaxios.ts b/Yi.App.Vue3/src/utils/myaxios.ts index 8b8ee565..726f9a2e 100644 --- a/Yi.App.Vue3/src/utils/myaxios.ts +++ b/Yi.App.Vue3/src/utils/myaxios.ts @@ -5,37 +5,43 @@ import axios from 'axios' import JsonBig from 'json-bigint' import { getToken } from '@/utils/auth' import { useRouter } from "vue-router"; -import useUserStore from '@/store/modules/user' +import useUserStore from '@/store/modules/user.js' import { Notify } from 'vant'; // import VuetifyDialogPlugin from 'vuetify-dialog/nuxt/index'; export let isRelogin = { show: false }; const myaxios = axios.create({ - // baseURL:'/'// - baseURL: import.meta.env.VITE_APP_BASE_API, // /dev-apis - timeout: 50000, - headers: { - 'Authorization': 'Bearer ' + "" - }, - //雪花id精度问题 - transformResponse: [ data => { - const json = JsonBig({ - storeAsString: true - }) - return json.parse(data) - }], - }) - // 请求拦截器 -myaxios.interceptors.request.use(function(config:any) { - const isToken = (config.headers || {}).isToken === false - // 是否需要防止数据重复提交 - const isRepeatSubmit = (config.headers || {}).repeatSubmit === false - if (getToken() && !isToken) { - config.headers['Authorization'] = 'Bearer ' + getToken() - } - // store.dispatch("openLoad"); - return config; -}, function(error) { - return Promise.reject(error); + // baseURL:'/'// + baseURL: import.meta.env.VITE_APP_BASE_API, // /dev-apis + timeout: 50000, + headers: { + 'Authorization': 'Bearer ' + "" + }, + //雪花id精度问题 + transformResponse: [data => { + const json = JsonBig({ + storeAsString: true + }); + try { + return json.parse(data); + } + catch + { + return data; + } + }], +}) +// 请求拦截器 +myaxios.interceptors.request.use(function (config:any) { + const isToken = (config.headers || {}).isToken === false + // 是否需要防止数据重复提交 + const isRepeatSubmit = (config.headers || {}).repeatSubmit === false + if (getToken() && !isToken) { + config.headers['Authorization'] = 'Bearer ' + getToken() + } + // store.dispatch("openLoad"); + return config; +}, function (error) { + return Promise.reject(error); }); // 响应拦截器 @@ -53,18 +59,25 @@ myaxios.interceptors.response.use(async function(response) { } // store.dispatch("closeLoad"); return resp; -}, async function(error) { +}, +async function(error) { +const code=error.response.status; +const message=error.message; //未授权、失败 if(error.response==undefined) { Notify({ type: 'danger', message: `服务器异常:${error.message}` }); + + // useUserStore().logOut().then(() => { + // location.href = '/'; + // }) + return Promise.reject(error);; } -const resp = error.response.data -if (resp.code == undefined && resp.message == undefined) { +if (code == undefined &&message == undefined) { Notify({ type: 'danger', message: '未知错误' }); -} else if (resp.code == 401) { +} else if (code == 401) { // if (!isRelogin.show) { Notify({ type: 'warning', message: '登录过期' }); //登出 @@ -73,9 +86,10 @@ if (resp.code == undefined && resp.message == undefined) { }) isRelogin.show = false; // } -} else if (resp.code !== 200) { - Notify({ type: 'danger', message: `错误代码:${resp.code},原因:${resp.message}` }); +} else if (code !== 200) { + Notify({ type: 'danger', message: `错误代码:${code},原因:${message}` }); } return Promise.reject(error); }); + export default myaxios \ No newline at end of file diff --git a/Yi.App.Vue3/src/view/login.vue b/Yi.App.Vue3/src/view/login.vue index 0bd37a7e..14072869 100644 --- a/Yi.App.Vue3/src/view/login.vue +++ b/Yi.App.Vue3/src/view/login.vue @@ -36,8 +36,9 @@