diff --git a/src/api/app/app-menu.ts b/src/api/app/app-menu.ts new file mode 100644 index 0000000..67c8057 --- /dev/null +++ b/src/api/app/app-menu.ts @@ -0,0 +1,40 @@ +import request from "/@/utils/request" + +export function fetchList(query?: Object) { + return request({ + url: "/app/app-menu/page", + method: "get", + params: query, + }) +} + +export function addObj(obj?: Object) { + return request({ + url: "/app/app-menu", + method: "post", + data: obj, + }) +} + +export function getObj(id?: string) { + return request({ + url: "/app/app-menu/" + id, + method: "get", + }) +} + +export function delObjs(ids?: Object) { + return request({ + url: "/app/app-menu", + method: "delete", + data: ids, + }) +} + +export function putObj(obj?: Object) { + return request({ + url: "/app/app-menu", + method: "put", + data: obj, + }) +} diff --git a/src/api/login/index.ts b/src/api/login/index.ts index 828f1f4..f09033a 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -1,171 +1,170 @@ -import request from '/@/utils/request'; -import {Session} from '/@/utils/storage'; -import {validateNull} from '/@/utils/validate'; -import {useUserInfo} from '/@/stores/userInfo'; -import other from '/@/utils/other'; +import request from "/@/utils/request" +import { Session } from "/@/utils/storage" +import { validateNull } from "/@/utils/validate" +import { useUserInfo } from "/@/stores/userInfo" +import other from "/@/utils/other" /** * https://www.ietf.org/rfc/rfc6749.txt * OAuth 协议 4.3.1 要求格式为 form 而不是 JSON 注意! */ -const FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded'; +const FORM_CONTENT_TYPE = "application/x-www-form-urlencoded" // 登录方式 export enum LoginTypeEnum { PASSWORD, MOBILE, REGISTER, - EXPIRE + EXPIRE, } // 登录错误信息 export enum LoginErrorEnum { - CREDENTIALS_EXPIRED = 'credentials_expired'// 密码过期 + CREDENTIALS_EXPIRED = "credentials_expired", // 密码过期 } - /** * 登录 * @param data */ export const login = (data: any) => { - const basicAuth = 'Basic ' + window.btoa(import.meta.env.VITE_OAUTH2_PASSWORD_CLIENT); - Session.set('basicAuth', basicAuth); + const basicAuth = "Basic " + window.btoa(import.meta.env.VITE_OAUTH2_PASSWORD_CLIENT) + Session.set("basicAuth", basicAuth) // 密码加密 - const encPassword = other.encryption(data.password, import.meta.env.VITE_PWD_ENC_KEY); - const { username, randomStr, code, grant_type, scope } = data; + const encPassword = other.encryption(data.password, import.meta.env.VITE_PWD_ENC_KEY) + const { username, randomStr, code, grant_type, scope } = data return request({ - url: '/auth/oauth2/token', - method: 'post', + url: "/auth/oauth2/token", + method: "post", params: { username, randomStr, code, grant_type, scope }, data: { password: encPassword }, headers: { skipToken: true, Authorization: basicAuth, - 'Content-Type': FORM_CONTENT_TYPE, + "Content-Type": FORM_CONTENT_TYPE, }, - }); -}; + }) +} export const loginByMobile = (mobile: any, code: any) => { - const grant_type = 'mobile'; - const scope = 'server'; - const basicAuth = 'Basic ' + window.btoa(import.meta.env.VITE_OAUTH2_MOBILE_CLIENT); - Session.set('basicAuth', basicAuth); + const grant_type = "mobile" + const scope = "server" + const basicAuth = "Basic " + window.btoa(import.meta.env.VITE_OAUTH2_MOBILE_CLIENT) + Session.set("basicAuth", basicAuth) return request({ - url: '/auth/oauth2/token', + url: "/auth/oauth2/token", headers: { skipToken: true, Authorization: basicAuth, - 'Content-Type': FORM_CONTENT_TYPE, + "Content-Type": FORM_CONTENT_TYPE, }, - method: 'post', - params: { mobile: 'SMS@' + mobile, code: code, grant_type, scope }, - }); -}; + method: "post", + params: { mobile: "SMS@" + mobile, code: code, grant_type, scope }, + }) +} export const loginBySocial = (state: string, code: string) => { - const grant_type = 'mobile'; - const scope = 'server'; - const basicAuth = 'Basic ' + window.btoa(import.meta.env.VITE_OAUTH2_SOCIAL_CLIENT); - Session.set('basicAuth', basicAuth); + const grant_type = "mobile" + const scope = "server" + const basicAuth = "Basic " + window.btoa(import.meta.env.VITE_OAUTH2_SOCIAL_CLIENT) + Session.set("basicAuth", basicAuth) return request({ - url: '/auth/oauth2/token', + url: "/auth/oauth2/token", headers: { skipToken: true, Authorization: basicAuth, - 'Content-Type': FORM_CONTENT_TYPE, + "Content-Type": FORM_CONTENT_TYPE, }, - method: 'post', - params: { mobile: state + '@' + code, code: code, grant_type, scope }, - }); -}; + method: "post", + params: { mobile: state + "@" + code, code: code, grant_type, scope }, + }) +} export const sendMobileCode = (mobile: string) => { return request({ - url: '/admin/sysMessage/send/smsCode', - method: 'get', - params: { mobile } - }); -}; + url: "/admin/sysMessage/send/smsCode", + method: "get", + params: { mobile }, + }) +} export const refreshTokenApi = (refresh_token: string) => { - const grant_type = 'refresh_token'; - const scope = 'server'; + const grant_type = "refresh_token" + const scope = "server" // 获取当前选中的 basic 认证信息 - const basicAuth = Session.get('basicAuth'); + const basicAuth = Session.get("basicAuth") return request({ - url: '/auth/oauth2/token', + url: "/auth/oauth2/token", headers: { skipToken: true, Authorization: basicAuth, - 'Content-Type': FORM_CONTENT_TYPE, + "Content-Type": FORM_CONTENT_TYPE, }, - method: 'post', + method: "post", params: { refresh_token, grant_type, scope }, - }); -}; + }) +} /** * 校验令牌,若有效期小于半小时自动续期 * @param refreshLock */ export const checkToken = (refreshTime: number, refreshLock: boolean) => { - const basicAuth = Session.get('basicAuth'); + const basicAuth = Session.get("basicAuth") request({ - url: '/auth/token/check_token', + url: "/auth/token/check_token", headers: { skipToken: true, Authorization: basicAuth, - 'Content-Type': FORM_CONTENT_TYPE, + "Content-Type": FORM_CONTENT_TYPE, }, - method: 'get', + method: "get", params: { token: Session.getToken() }, }) .then((response) => { if (validateNull(response) || response.code === 1) { - clearInterval(refreshTime); - return; + clearInterval(refreshTime) + return } - const expire = Date.parse(response.data.expiresAt); + const expire = Date.parse(response.data.expiresAt) if (expire) { - const expiredPeriod = expire - new Date().getTime(); + const expiredPeriod = expire - new Date().getTime() //小于半小时自动续约 if (expiredPeriod <= 30 * 60 * 1000) { if (!refreshLock) { - refreshLock = true; + refreshLock = true useUserInfo() .refreshToken() .catch(() => { - clearInterval(refreshTime); - }); - refreshLock = false; + clearInterval(refreshTime) + }) + refreshLock = false } } } }) .catch(() => { // 发生异常关闭定时器 - clearInterval(refreshTime); - }); -}; + clearInterval(refreshTime) + }) +} /** * 获取用户信息 */ export const getUserInfo = () => { return request({ - url: '/admin/user/info', - method: 'get', - }); -}; + url: "/admin/user/info", + method: "get", + }) +} export const logout = () => { return request({ - url: '/auth/token/logout', - method: 'delete', - }); -}; + url: "/auth/token/logout", + method: "delete", + }) +} diff --git a/src/views/biz/app/app-menu/form.vue b/src/views/biz/app/app-menu/form.vue new file mode 100644 index 0000000..4936a73 --- /dev/null +++ b/src/views/biz/app/app-menu/form.vue @@ -0,0 +1,146 @@ + + + \ No newline at end of file diff --git a/src/views/biz/app/app-menu/index.vue b/src/views/biz/app/app-menu/index.vue new file mode 100644 index 0000000..d697d71 --- /dev/null +++ b/src/views/biz/app/app-menu/index.vue @@ -0,0 +1,154 @@ + + + \ No newline at end of file