From 32599726a6a4db4b55780134872e1dcdd1baf227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Sat, 30 Nov 2024 10:16:55 +0800 Subject: [PATCH 01/18] =?UTF-8?q?[*]=20Turnstile=20=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 5 ++-- src/api/v2/auth/login.api.ts | 5 ++-- src/views/auth/LoginView.vue | 57 +++++++++++++++--------------------- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index bbeb6da..c5f2097 100644 --- a/package.json +++ b/package.json @@ -10,11 +10,11 @@ "format": "prettier --write src/" }, "dependencies": { + "@vicons/fa": "^0.12.0", + "@vicons/fluent": "^0.12.0", "@vicons/ionicons4": "^0.12.0", "@vicons/ionicons5": "^0.12.0", "@vicons/material": "^0.12.0", - "@vicons/fa": "^0.12.0", - "@vicons/fluent": "^0.12.0", "axios": "^1.7.7", "highlight.js": "^11.10.0", "js-cookie": "^3.0.5", @@ -33,6 +33,7 @@ "vue-native-websocket": "^2.0.15", "vue-route": "^1.5.1", "vue-router": "^4.4.5", + "vue-turnstile": "^1.0.11", "vuex": "^4.1.0" }, "devDependencies": { diff --git a/src/api/v2/auth/login.api.ts b/src/api/v2/auth/login.api.ts index 01748d2..fad0b8b 100644 --- a/src/api/v2/auth/login.api.ts +++ b/src/api/v2/auth/login.api.ts @@ -2,10 +2,11 @@ import { post } from '@/utils/request' import base from '@/api/base' -const login = async (username: string, password: string) => { +const login = async (username: string, password: string, captcha_response_token: string) => { const rs = post(`${base.api_v2_url}/auth/login`, { username: username, - password: password + password: password, + captcha_response_token: captcha_response_token }) return base.buildResponse(await rs) } diff --git a/src/views/auth/LoginView.vue b/src/views/auth/LoginView.vue index d1c1412..03cb1ac 100644 --- a/src/views/auth/LoginView.vue +++ b/src/views/auth/LoginView.vue @@ -43,7 +43,18 @@ > 没有账户?去注册 - 登录 + 登录 + + + + @@ -53,7 +64,7 @@ From bed812a5e6d959e8fa013b5080a42549dccb257f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Tue, 3 Dec 2024 21:27:12 +0800 Subject: [PATCH 07/18] [*] Format code --- src/api/v2/app/index.ts | 2 +- src/api/v2/app/info.api.ts | 2 +- src/api/v2/auth/oauth/authorize.api.ts | 2 +- src/api/v2/auth/oauth/permission/all.api.ts | 2 +- src/api/v2/auth/oauth/permission/index.ts | 2 +- src/views/auth/oauth/AppAuthView.vue | 42 +++++++++++---------- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/api/v2/app/index.ts b/src/api/v2/app/index.ts index ecd3e2d..ded26e9 100644 --- a/src/api/v2/app/index.ts +++ b/src/api/v2/app/index.ts @@ -2,4 +2,4 @@ import info from './info.api' export default { info: info -} \ No newline at end of file +} diff --git a/src/api/v2/app/info.api.ts b/src/api/v2/app/info.api.ts index c8800f0..0819d0f 100644 --- a/src/api/v2/app/info.api.ts +++ b/src/api/v2/app/info.api.ts @@ -5,7 +5,7 @@ import base from '@/api/base' const info = async (user_id: number, app_id: number) => { const rs = get(`${base.api_v2_url}/app/info`, { user_id: user_id, - app_id: app_id, + app_id: app_id }) return base.buildResponse(await rs) } diff --git a/src/api/v2/auth/oauth/authorize.api.ts b/src/api/v2/auth/oauth/authorize.api.ts index 9b73698..abde523 100644 --- a/src/api/v2/auth/oauth/authorize.api.ts +++ b/src/api/v2/auth/oauth/authorize.api.ts @@ -5,7 +5,7 @@ import base from '@/api/base' const authorize = async ( user_id: number, app_id: number, - request_permission_ids: Array, + request_permission_ids: Array ) => { const rs = post(`${base.api_v2_url}/auth/oauth/authorize`, { user_id: user_id, diff --git a/src/api/v2/auth/oauth/permission/all.api.ts b/src/api/v2/auth/oauth/permission/all.api.ts index a349bf5..90575b7 100644 --- a/src/api/v2/auth/oauth/permission/all.api.ts +++ b/src/api/v2/auth/oauth/permission/all.api.ts @@ -4,7 +4,7 @@ import base from '@/api/base' const all = async (user_id: number) => { const rs = get(`${base.api_v2_url}/auth/oauth/permission/all`, { - user_id: user_id, + user_id: user_id }) return base.buildResponse(await rs) } diff --git a/src/api/v2/auth/oauth/permission/index.ts b/src/api/v2/auth/oauth/permission/index.ts index c336f37..b597983 100644 --- a/src/api/v2/auth/oauth/permission/index.ts +++ b/src/api/v2/auth/oauth/permission/index.ts @@ -2,4 +2,4 @@ import all from './all.api' export default { all: all -} \ No newline at end of file +} diff --git a/src/views/auth/oauth/AppAuthView.vue b/src/views/auth/oauth/AppAuthView.vue index d10687a..0ecddc0 100644 --- a/src/views/auth/oauth/AppAuthView.vue +++ b/src/views/auth/oauth/AppAuthView.vue @@ -29,24 +29,21 @@ :disabled="acceptLoading" type="primary" @click="doAuthorize" - >同意 - 拒绝 + >同意 + 拒绝 -
+
授权后,您将被重定向到以下地址: -
+
{{ urlKeys.redirectUrl }}
- 无效请求,请检查 URL 参数 + 无效请求,请检查 URL 参数
@@ -111,33 +108,37 @@ const acceptLoading = ref(false) const denyLoading = ref(false) async function doAuthorize() { - acceptLoading.value = true; + acceptLoading.value = true let permissionIds: Array = [] - applicationPermissionRequested.value.forEach(permission => { + applicationPermissionRequested.value.forEach((permission) => { permissionIds.push(permission.id) }) let rs try { - rs = await api.v2.auth.oauth.authorize(userData.getters.get_user_id, urlKeys.appId, permissionIds) + rs = await api.v2.auth.oauth.authorize( + userData.getters.get_user_id, + urlKeys.appId, + permissionIds + ) } catch (e) { logger.error(e) - sendErrorMessage("授权失败: " + e) + sendErrorMessage('授权失败: ' + e) acceptLoading.value = false return } if (rs != null) { if (rs.status === 200) { - sendSuccessMessage("授权成功,正在重定向,请不要刷新浏览器") + sendSuccessMessage('授权成功,正在重定向,请不要刷新浏览器') window.location.href = `${urlKeys.redirectUrl}?refresh_token=${rs.data.refresh_token}` } else { - sendErrorMessage("授权失败: " + rs.message) + sendErrorMessage('授权失败: ' + rs.message) } } acceptLoading.value = false } function deny() { - denyLoading.value = true; - window.location.href = urlKeys.redirectUrl + "?error=User.Deny"; + denyLoading.value = true + window.location.href = urlKeys.redirectUrl + '?error=User.Deny' } onMounted(async () => { @@ -158,7 +159,7 @@ onMounted(async () => { applicationDescription.value = rs.data.description return true } else if (rs.status === 404) { - sendErrorMessage("未找到此应用程序") + sendErrorMessage('未找到此应用程序') valid.value = false return true } else { @@ -191,8 +192,9 @@ onMounted(async () => { async function initAppPermissions(): Promise { const permissions = urlKeys.scopes.split(',') - permissionList.forEach(permission => { - if (permissions.includes(permission.node)) applicationPermissionRequested.value.push(permission) + permissionList.forEach((permission) => { + if (permissions.includes(permission.node)) + applicationPermissionRequested.value.push(permission) }) return true // applicationPermissionRequested From 686f9337de9670a098b71783b085b2cd1e094049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Tue, 3 Dec 2024 22:15:28 +0800 Subject: [PATCH 08/18] [*] Migrate all v1 API to v2 --- src/api/index.ts | 2 -- src/api/v1/Donate/GetDonateInfo.ts | 15 -------- src/api/v1/Donate/index.ts | 5 --- src/api/v1/Proxies/GetRandomPort.ts | 21 ------------ src/api/v1/Proxies/index.ts | 5 --- src/api/v1/index.ts | 7 ---- src/api/v2/donate/index.ts | 2 ++ src/api/v2/donate/info.api.ts | 16 +++++++++ src/api/v2/node/all.api.ts | 6 ++-- src/api/v2/node/index.ts | 4 ++- src/api/v2/node/port/index.ts | 5 +++ src/api/v2/node/port/random.api.ts | 13 +++++++ src/views/DonateView.vue | 6 ++-- src/views/auth/oauth/AppAuthView.vue | 51 +++++++++++++--------------- src/views/games/MinecraftView.vue | 2 ++ src/views/proxies/AddView.vue | 6 ++-- src/views/proxies/ConfigView.vue | 2 +- src/views/proxies/ProxiesView.vue | 2 +- 18 files changed, 77 insertions(+), 93 deletions(-) delete mode 100644 src/api/v1/Donate/GetDonateInfo.ts delete mode 100644 src/api/v1/Donate/index.ts delete mode 100644 src/api/v1/Proxies/GetRandomPort.ts delete mode 100644 src/api/v1/Proxies/index.ts delete mode 100644 src/api/v1/index.ts create mode 100644 src/api/v2/donate/info.api.ts create mode 100644 src/api/v2/node/port/index.ts create mode 100644 src/api/v2/node/port/random.api.ts diff --git a/src/api/index.ts b/src/api/index.ts index 242338f..9d64fa4 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,8 +1,6 @@ -import v1 from './v1' import v2 from './v2' const api = { - v1: v1, v2: v2 } diff --git a/src/api/v1/Donate/GetDonateInfo.ts b/src/api/v1/Donate/GetDonateInfo.ts deleted file mode 100644 index 7b6748f..0000000 --- a/src/api/v1/Donate/GetDonateInfo.ts +++ /dev/null @@ -1,15 +0,0 @@ -import base from '@/api/base' -//@ts-ignore -import { get } from '@/utils/request' - -/** - * 列出赞助列表 - */ -const GetDonateInfo = async (trade_no: string) => { - const rs = get(`${base.api_v1_url}/Donate/GetDonateInfo`, { - trade_no: trade_no - }) - return base.buildResponse(await rs, false) -} - -export default GetDonateInfo diff --git a/src/api/v1/Donate/index.ts b/src/api/v1/Donate/index.ts deleted file mode 100644 index cef8189..0000000 --- a/src/api/v1/Donate/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import GetDonateInfo from './GetDonateInfo' - -export default { - GetDonateInfo: GetDonateInfo -} diff --git a/src/api/v1/Proxies/GetRandomPort.ts b/src/api/v1/Proxies/GetRandomPort.ts deleted file mode 100644 index 384be6e..0000000 --- a/src/api/v1/Proxies/GetRandomPort.ts +++ /dev/null @@ -1,21 +0,0 @@ -import base from '@/api/base' -//@ts-ignore -import { get } from '@/utils/request' - -/** - * 获取随机端口 - * @returns { - * status: int, - * data: { - * port: string - * } - * } - */ -const GetRandomPort = async (id: number) => { - const rs = await get(`${base.api_v1_url}/Proxies/GetRandomPort`, { - id: id - }) - return base.buildResponse(rs, false) -} - -export default GetRandomPort diff --git a/src/api/v1/Proxies/index.ts b/src/api/v1/Proxies/index.ts deleted file mode 100644 index df75618..0000000 --- a/src/api/v1/Proxies/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import GetRandomPort from './GetRandomPort' - -export default { - GetRandomPort: GetRandomPort -} diff --git a/src/api/v1/index.ts b/src/api/v1/index.ts deleted file mode 100644 index a0ad471..0000000 --- a/src/api/v1/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import Proxies from './Proxies' -import Donate from './Donate' - -export default { - Proxies: Proxies, - Donate: Donate -} diff --git a/src/api/v2/donate/index.ts b/src/api/v2/donate/index.ts index 7f9b0d6..35f53b1 100644 --- a/src/api/v2/donate/index.ts +++ b/src/api/v2/donate/index.ts @@ -1,9 +1,11 @@ import root from './root.api' import list from './list.api' +import info from './info.api' import say from './say' export default { root: root, list: list, + info: info, say: say } diff --git a/src/api/v2/donate/info.api.ts b/src/api/v2/donate/info.api.ts new file mode 100644 index 0000000..84ceca5 --- /dev/null +++ b/src/api/v2/donate/info.api.ts @@ -0,0 +1,16 @@ +import base from '@/api/base' +//@ts-ignore +import { get } from '@/utils/request' + +/** + * 获取捐赠订单信息 + */ +const list = async (user_id: number, trade_no: string) => { + const rs = get(`${base.api_v2_url}/donate/info`, { + user_id: user_id, + trade_no: trade_no + }) + return base.buildResponse(await rs) +} + +export default list diff --git a/src/api/v2/node/all.api.ts b/src/api/v2/node/all.api.ts index efcbc41..a4b2059 100644 --- a/src/api/v2/node/all.api.ts +++ b/src/api/v2/node/all.api.ts @@ -2,8 +2,10 @@ import base from '@/api/base' //@ts-ignore import { get } from '@/utils/request' -const all = async () => { - const rs = get(`${base.api_v2_url}/node/all`, {}) +const all = async (user_id: number) => { + const rs = get(`${base.api_v2_url}/node/all`, { + user_id: user_id + }) return base.buildResponse(await rs) } diff --git a/src/api/v2/node/index.ts b/src/api/v2/node/index.ts index b597983..bb895da 100644 --- a/src/api/v2/node/index.ts +++ b/src/api/v2/node/index.ts @@ -1,5 +1,7 @@ import all from './all.api' +import port from './port' export default { - all: all + all: all, + port: port } diff --git a/src/api/v2/node/port/index.ts b/src/api/v2/node/port/index.ts new file mode 100644 index 0000000..d3fd61b --- /dev/null +++ b/src/api/v2/node/port/index.ts @@ -0,0 +1,5 @@ +import random from './random.api' + +export default { + random: random +} diff --git a/src/api/v2/node/port/random.api.ts b/src/api/v2/node/port/random.api.ts new file mode 100644 index 0000000..fbaf054 --- /dev/null +++ b/src/api/v2/node/port/random.api.ts @@ -0,0 +1,13 @@ +import base from '@/api/base' +//@ts-ignore +import { get } from '@/utils/request' + +const random = async (user_id: number, node_id: number) => { + const rs = get(`${base.api_v2_url}/node/port/random`, { + user_id: user_id, + node_id: node_id + }) + return base.buildResponse(await rs) +} + +export default random diff --git a/src/views/DonateView.vue b/src/views/DonateView.vue index 069acfb..229fdce 100644 --- a/src/views/DonateView.vue +++ b/src/views/DonateView.vue @@ -147,7 +147,6 @@ const displayMessagesDefault = ref(5) const displayAllMessages = ref(false) const tradeInfo = ref({ id: 1, - username: '', message: null, trade_name: '', trade_no: '', @@ -170,14 +169,13 @@ onMounted(async () => { showModal.value = true let rs try { - rs = await api.v2.Donate.GetDonateInfo(inputTradeNo) + rs = await api.v2.donate.info(userData.getters.get_user_id, inputTradeNo) } catch (e) { sendErrorMessage('请求列表失败: ' + e) } if (!rs) return if (rs.status === 200) { - if (rs.data) tradeInfo.value = rs.data - else sendErrorMessage('返回数据无效') + tradeInfo.value = rs.data } else { sendErrorMessage(rs.message) } diff --git a/src/views/auth/oauth/AppAuthView.vue b/src/views/auth/oauth/AppAuthView.vue index 0ecddc0..ed7c79a 100644 --- a/src/views/auth/oauth/AppAuthView.vue +++ b/src/views/auth/oauth/AppAuthView.vue @@ -126,13 +126,12 @@ async function doAuthorize() { acceptLoading.value = false return } - if (rs != null) { - if (rs.status === 200) { - sendSuccessMessage('授权成功,正在重定向,请不要刷新浏览器') - window.location.href = `${urlKeys.redirectUrl}?refresh_token=${rs.data.refresh_token}` - } else { - sendErrorMessage('授权失败: ' + rs.message) - } + if (!rs) return + if (rs.status === 200) { + sendSuccessMessage('授权成功,正在重定向,请不要刷新浏览器') + window.location.href = `${urlKeys.redirectUrl}?refresh_token=${rs.data.refresh_token}` + } else { + sendErrorMessage('授权失败: ' + rs.message) } acceptLoading.value = false } @@ -153,18 +152,17 @@ onMounted(async () => { sendErrorMessage(e) return false } - if (rs != null) { - if (rs.status === 200) { - applicationName.value = rs.data.name - applicationDescription.value = rs.data.description - return true - } else if (rs.status === 404) { - sendErrorMessage('未找到此应用程序') - valid.value = false - return true - } else { - sendErrorMessage(rs.message) - } + if (rs) return false + if (rs.status === 200) { + applicationName.value = rs.data.name + applicationDescription.value = rs.data.description + return true + } else if (rs.status === 404) { + sendErrorMessage('未找到此应用程序') + valid.value = false + return true + } else { + sendErrorMessage(rs.message) } return false } @@ -178,14 +176,13 @@ onMounted(async () => { sendErrorMessage(e) return false } - if (rs != null) { - if (rs.status === 200) { - // logger.info(rs.data) - permissionList = rs.data.list - return true - } else { - sendErrorMessage(rs.message) - } + if (!rs) return false + if (rs.status === 200) { + // logger.info(rs.data) + permissionList = rs.data.list + return true + } else { + sendErrorMessage(rs.message) } return false } diff --git a/src/views/games/MinecraftView.vue b/src/views/games/MinecraftView.vue index f1c7c4c..64e392b 100644 --- a/src/views/games/MinecraftView.vue +++ b/src/views/games/MinecraftView.vue @@ -102,6 +102,8 @@ async function initProxyList() { }) }) if (proxies.length !== 0) selected.value = proxies[0].id + } else if (rs.status === 404) { + // Nothing to do here } else { sendErrorMessage(rs.message) } diff --git a/src/views/proxies/AddView.vue b/src/views/proxies/AddView.vue index fe0e4a8..db348f9 100644 --- a/src/views/proxies/AddView.vue +++ b/src/views/proxies/AddView.vue @@ -287,7 +287,7 @@ async function randomPort() { } let rs try { - rs = await api.v1.Proxies.GetRandomPort(proxyInfo.value.nodeId) + rs = await api.v2.node.port.random(userData.getters.get_user_id, proxyInfo.value.nodeId) } catch (e) { logger.error(e) sendErrorMessage('请求隧道端口失败: ' + e) @@ -295,6 +295,8 @@ async function randomPort() { if (!rs) return if (rs.status === 200) { proxyInfo.value.remotePort = rs.data.port + } else { + sendErrorMessage(rs.message) } } @@ -351,7 +353,7 @@ onMounted(async () => { loading.value = true let rs try { - rs = await api.v2.node.all() + rs = await api.v2.node.all(userData.getters.get_user_id) } catch (e) { logger.error(e) sendErrorMessage('请求节点列表失败: ' + e) diff --git a/src/views/proxies/ConfigView.vue b/src/views/proxies/ConfigView.vue index 0438c3f..811ba19 100644 --- a/src/views/proxies/ConfigView.vue +++ b/src/views/proxies/ConfigView.vue @@ -99,7 +99,7 @@ const code = ref('') onMounted(async () => { let rs try { - rs = await api.v2.node.all() + rs = await api.v2.node.all(userData.getters.get_user_id) } catch (e) { logger.error(e) sendErrorMessage('请求节点列表失败: ' + e) diff --git a/src/views/proxies/ProxiesView.vue b/src/views/proxies/ProxiesView.vue index 8721289..55fc35a 100644 --- a/src/views/proxies/ProxiesView.vue +++ b/src/views/proxies/ProxiesView.vue @@ -528,7 +528,7 @@ const serverList = ref([ async function initList() { let rs1 try { - rs1 = await api.v2.node.all() + rs1 = await api.v2.node.all(userData.getters.get_user_id) } catch (e) { sendErrorMessage('请求节点列表失败: ' + e) } From e60ecdc149fafb613580aa569cd46196bb49dacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Wed, 4 Dec 2024 19:52:24 +0800 Subject: [PATCH 09/18] =?UTF-8?q?[*]=20=E9=87=8D=E6=96=B0=E5=B0=81?= =?UTF-8?q?=E8=A3=85=E4=BA=86=20message.js,=20dialog.js=20=E5=92=8C=20noti?= =?UTF-8?q?fication.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 12 +-- src/components/UserInfo.vue | 54 +++++-------- src/main.js | 4 +- src/utils/dialog.js | 77 ++++++++++++++----- src/utils/message.js | 24 +++--- src/utils/notice.js | 6 +- src/utils/notification.js | 66 ++++++++-------- src/utils/profile.js | 49 ------------ src/utils/request.js | 6 +- src/utils/title.js | 2 +- src/views/DashboardView.vue | 21 +++-- src/views/DonateView.vue | 43 ++++++----- src/views/IcpCheckView.vue | 41 +++++----- src/views/SignView.vue | 19 +++-- src/views/VerificationView.vue | 44 ++++++----- src/views/activities/NewYearView.vue | 6 +- src/views/auth/LoginView.vue | 21 ++--- src/views/auth/oauth/AppAuthView.vue | 20 ++--- src/views/callback/auth/oauth/qq/BindView.vue | 8 +- .../callback/auth/oauth/qq/LoginView.vue | 10 ++- src/views/games/MinecraftView.vue | 26 ++++--- src/views/proxies/AddView.vue | 25 +++--- src/views/proxies/ConfigView.vue | 14 ++-- src/views/proxies/ProxiesView.vue | 63 ++++++--------- 24 files changed, 325 insertions(+), 336 deletions(-) diff --git a/src/App.vue b/src/App.vue index a463f53..dec3d53 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,7 +7,7 @@ - + @@ -57,7 +57,7 @@ import { NNotificationProvider, useOsTheme } from 'naive-ui' -import Notification from '@components/TheNotification.vue' +import TheNotification from '@components/TheNotification.vue' import TheFooter from '@components/TheFooter.vue' import TheHeader from '@components/TheHeader.vue' import UserInfo from '@components/UserInfo.vue' @@ -73,11 +73,13 @@ import hljs from 'highlight.js/lib/core' import ini from 'highlight.js/lib/languages/ini' import nginx from 'highlight.js/lib/languages/nginx' import api from '@/api' -import { sendWarningMessage } from '@/utils/message' +import Notification from '@/utils/notification' import { logout } from '@/utils/profile' import router from '@router' import { useRoute, useRouter } from 'vue-router' +const notification = new Notification() + // 手机状态下收缩菜单栏 const collapsed = ref(true) if (document.body.clientWidth >= 1000) { @@ -123,7 +125,7 @@ async function fetchUserInfo() { try { rs = await api.v2.user.info.root.get(userData.getters.get_user_id) } catch (e) { - sendWarningMessage('查询用户信息失败: ' + e + ',请重新登录后台!') + notification.warning('查询用户信息失败', e + ',请重新登录后台!') } if (!rs) return if (rs.status === 200) { @@ -142,7 +144,7 @@ async function fetchUserInfo() { return true } if (rs.status === 401) { - sendWarningMessage('登录过期或未登录,请重新登录后台!') + notification.warning('授权失效', '请重新登录后台!') logout() } return false diff --git a/src/components/UserInfo.vue b/src/components/UserInfo.vue index 432e804..ad55df0 100644 --- a/src/components/UserInfo.vue +++ b/src/components/UserInfo.vue @@ -92,20 +92,24 @@ diff --git a/src/main.js b/src/main.js index 0bff9be..5e865e6 100644 --- a/src/main.js +++ b/src/main.js @@ -10,10 +10,10 @@ import axios from 'axios' import VueAxios from 'vue-axios' import userData from '@/utils/stores/userData/store' import userDataLocal from '@/utils/stores/userData/local' -import { printTitle } from '@/utils/title' +import banner from '@/utils/title' import Clipboard from 'v-clipboard' -printTitle() +banner() const app = createApp(App) app.use(userData) diff --git a/src/utils/dialog.js b/src/utils/dialog.js index c479ebe..0992e48 100644 --- a/src/utils/dialog.js +++ b/src/utils/dialog.js @@ -1,23 +1,58 @@ -export const sendSuccessDialog = (message) => { - window.$dialog.success({ - title: '厉害捏!', - content: message, - positiveText: '收到' - }) +class Dialog { + success( + message, + options = { + onPositiveClick: null, + onNegativeClick: null, + onMaskClick: null + } + ) { + window.$dialog.success({ + title: '厉害捏!', + content: message, + positiveText: '收到', + negativeText: '不要', + onPositiveClick: options.onPositiveClick, + onNegativeClick: options.onNegativeClick, + onMaskClick: options.onMaskClick + }) + } + warning( + message, + options = { + onPositiveClick: null, + onNegativeClick: null, + onMaskClick: null + } + ) { + window.$dialog.warning({ + title: '这只是个警告罢了~', + content: message, + positiveText: '收到', + negativeText: '不要', + onPositiveClick: options.onPositiveClick, + onNegativeClick: options.onNegativeClick, + onMaskClick: options.onMaskClick + }) + } + error( + message, + options = { + onPositiveClick: null, + onNegativeClick: null, + onMaskClick: null + } + ) { + window.$dialog.error({ + title: '发生了点小错误...', + content: message, + positiveText: '收到', + negativeText: '不要', + onPositiveClick: options.onPositiveClick, + onNegativeClick: options.onNegativeClick, + onMaskClick: options.onMaskClick + }) + } } -export const sendWarningDialog = (message) => { - window.$dialog.warning({ - title: '这只是个警告罢了~', - content: message, - positiveText: '收到' - }) -} - -export const sendErrorDialog = (message) => { - window.$dialog.error({ - title: '发生了点小错误...', - content: message, - positiveText: '收到' - }) -} +export default Dialog diff --git a/src/utils/message.js b/src/utils/message.js index 4c1298c..5ced20a 100644 --- a/src/utils/message.js +++ b/src/utils/message.js @@ -1,16 +1,14 @@ // 2024-09-06 Muska_Ami: 他妈的 为什么要再造轮子啊 - -export const sendSuccessMessage = (message) => { - // 需要确保已经在 setup 中执行了 window.$message = message - window.$message.success(message) -} - -export const sendWarningMessage = (message) => { - // 需要确保已经在 setup 中执行了 window.$message = message - window.$message.warning(message) +class Message { + success(message, options = {}) { + window.$message.success(message, options) + } + warning(message, options = {}) { + window.$message.warning(message, options) + } + error(message, options = {}) { + window.$message.error(message, options) + } } -export const sendErrorMessage = (message) => { - // 需要确保已经在 setup 中执行了 window.$message = message - window.$message.error(message) -} +export default Message diff --git a/src/utils/notice.js b/src/utils/notice.js index 52c04e7..f8b6502 100644 --- a/src/utils/notice.js +++ b/src/utils/notice.js @@ -1,8 +1,10 @@ import api from '@/api' import logger from '@/utils/logger' -import { sendErrorMessage } from '@/utils/message' +import Message from '@/utils/message' import { marked } from 'marked' +const message = new Message() + let notice = { getNotice: getNotice } @@ -14,7 +16,7 @@ async function getNotice() { res = await api.v2.notice.root.get() } catch (e) { logger.error(e) - sendErrorMessage('获取 Notice 失败: ' + e) + message.error('获取 Notice 失败: ' + e) } // console.log(res) if (!res) return diff --git a/src/utils/notification.js b/src/utils/notification.js index 431da16..bc48c9e 100644 --- a/src/utils/notification.js +++ b/src/utils/notification.js @@ -1,32 +1,36 @@ -export const sendSuccessNotification = (message) => { - window.notification['success']({ - content: '成功', - meta: message, - duration: 2500, - keepAliveOnHover: true - }) -} -export const sendWarningNotification = (message) => { - window.notification['warning']({ - content: '警告', - meta: message, - duration: 2500, - keepAliveOnHover: true - }) -} -export const sendErrorNotification = (message) => { - window.notification['error']({ - content: '错误', - meta: message, - duration: 2500, - keepAliveOnHover: true - }) -} -export const sendInfoNotification = (message) => { - window.notification['info']({ - content: '信息', - meta: message, - duration: 2500, - keepAliveOnHover: true - }) +class Notification { + info(title, message) { + window.notification['info']({ + content: title, + meta: message, + duration: 2500, + keepAliveOnHover: true + }) + } + success(title, message) { + window.notification['success']({ + content: title, + meta: message, + duration: 2500, + keepAliveOnHover: true + }) + } + warning(title, message) { + window.notification['warning']({ + content: title, + meta: message, + duration: 2500, + keepAliveOnHover: true + }) + } + error(title, message) { + window.notification['error']({ + content: title, + meta: message, + duration: 2500, + keepAliveOnHover: true + }) + } } + +export default Notification diff --git a/src/utils/profile.js b/src/utils/profile.js index 5f6265c..b5012f8 100644 --- a/src/utils/profile.js +++ b/src/utils/profile.js @@ -1,53 +1,4 @@ -import axios from 'axios' -import { ref } from 'vue' import userData from './stores/userData/store' -import router from '@router' -import { get } from './request' -import { sendWarningMessage } from './message' - -export function getNotice() { - const rs = ref('') - axios({ - method: 'get', - url: 'https://api.locyanfrp.cn/App' - }).then((res) => { - rs.value = res.data - }) - return rs -} - -export function getLoginStatus(username, token) { - const rs = get( - 'https://api.locyanfrp.cn/Account/info?username=' + username + '&token=' + token, - [] - ) - const return_res = ref('') - rs.then((res) => { - if (res.status !== 0) { - sendWarningMessage('登录过期或未登录,请使用 LCF 账户登录后台!') - logout() - } else { - return_res.value = res - return return_res - } - }) - return return_res -} - -export function getProxies(username, token) { - const rs = get( - 'https://api.locyanfrp.cn/Proxies/GetProxiesList?username=' + username + '&token=' + token, - [] - ) - rs.then((res) => { - if (res.status !== 0) { - return res - } else { - localStorage.setItem('proxies', res.count) - return res.proxies - } - }) -} export function logout() { userData.commit('delete_user_info') diff --git a/src/utils/request.js b/src/utils/request.js index 3e1e5d6..d2f1046 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -6,9 +6,11 @@ import QS from 'qs' import userData from './stores/userData/store' import router from '@router' import Base64 from 'qs/lib/utils' -import { sendErrorMessage } from './message' +import Message from './message' import logger from '@/utils/logger' +const message = new Message() + //这一步的目的是判断出当前是开发环境还是生成环境,方法不止一种,达到目的就行 // if(process.env.NODE_ENV=="development"){ // baseURL='https://api.locyanfrp.cn' @@ -66,7 +68,7 @@ instance.interceptors.response.use( }) break case 500: - sendErrorMessage('服务器响应时发生错误') + message.error('服务器响应时发生错误') // 403 token过期 // 登录过期对用户进行提示 // 清除本地token和清空vuex中token对象 diff --git a/src/utils/title.js b/src/utils/title.js index d1444c2..2071a98 100644 --- a/src/utils/title.js +++ b/src/utils/title.js @@ -7,7 +7,7 @@ const colorBadgeData = 'background-color: #606060; color: #fff;' const colorReset = 'background-color: none; color: none;' const colorCFU = 'wdith: 100%; background-color: #66ccff; color: #fff;' -export async function printTitle() { +export default () => { console.log( `%c _ ____ _____ diff --git a/src/views/DashboardView.vue b/src/views/DashboardView.vue index 94b3d8b..e24a1f1 100644 --- a/src/views/DashboardView.vue +++ b/src/views/DashboardView.vue @@ -38,8 +38,8 @@ style="margin-left: 10px; transform: translateY(-5px)" type="info" v-clipboard="() => frpToken" - v-clipboard:success="() => sendSuccessMessage('复制成功')" - v-clipboard:error="() => sendErrorMessage('复制失败')" + v-clipboard:success="() => message.success('复制成功')" + v-clipboard:error="() => message.error('复制失败')" > 复制 @@ -165,13 +165,16 @@ import { ref, onMounted } from 'vue' // import clipboard from '@/utils/clipboard' import { AngleRight, Key } from '@vicons/fa' import userData from '@/utils/stores/userData/store' -import { useDialog, useMessage } from 'naive-ui' import { startLoadingBar, finishLoadingBar, errorLoadingBar } from '@/utils/loadingbar' -import { sendSuccessMessage, sendErrorMessage } from '@/utils/message' +import Message from '@/utils/message' +import Dialog from '@/utils/dialog' import api from '@/api' import logger from '@/utils/logger' import notice from '@/utils/notice' +const message = new Message() +const dialog = new Dialog() + localStorage.setItem('ViewPage', 'personality') const username = userData.getters.get_username const email = userData.getters.get_email @@ -181,8 +184,6 @@ const outbound = ref(userData.getters.get_user_outbound + 'Mbps 上行') const outboundRef = ref(null) const frpToken = ref(userData.getters.get_frp_token) const notShowFrpToken = ref(true) -const dialog = useDialog() -const message = useMessage() const broadcastHtml = ref('') const broadcastLoading = ref(true) @@ -243,11 +244,7 @@ function helloMessage() { } async function resetTraffic() { - dialog.warning({ - title: '警告', - content: '确定要重置流量吗?这将将剩余流量设置为 10 GiB', - positiveText: '确定', - negativeText: '还是算了~', + dialog.warning('确定要重置流量吗?这将将剩余流量设置为 10 GiB', { onPositiveClick: async () => { startLoadingBar() const data = { @@ -258,7 +255,7 @@ async function resetTraffic() { rs = await api.v2.user.traffic(data.user_id) } catch (e) { logger.error(e) - sendErrorMessage('请求重置流量失败: ' + e) + message.error('请求重置流量失败: ' + e) } if (!rs) { errorLoadingBar() diff --git a/src/views/DonateView.vue b/src/views/DonateView.vue index 229fdce..5e58e83 100644 --- a/src/views/DonateView.vue +++ b/src/views/DonateView.vue @@ -62,13 +62,13 @@ - + { try { rs = await api.v2.donate.info(userData.getters.get_user_id, inputTradeNo) } catch (e) { - sendErrorMessage('请求列表失败: ' + e) + logger.error(e) + message.error('请求列表失败: ' + e) } if (!rs) return if (rs.status === 200) { tradeInfo.value = rs.data } else { - sendErrorMessage(rs.message) + message.error(rs.message) } } }) const submitLoading = ref(false) const donateLoading = ref(false) const formRef = ref(null) -const message = ref([ +const donateMessage = ref([ { message: '' } @@ -196,14 +201,14 @@ async function getDonateList() { try { rs = await api.v2.donate.say.all() } catch (e) { - sendErrorMessage('请求列表失败: ' + e) + message.error('请求列表失败: ' + e) } if (!rs) return if (rs.status === 200) { donateList.value = rs.data.list donateListLoading.value = false } else { - sendErrorMessage(rs.message) + message.error(rs.message) } } @@ -222,8 +227,8 @@ const timestampToTime = (timestamp) => { async function submitMessage() { submitLoading.value = true - if (message.message === '') { - sendWarningDialog('内容不能为空!') + if (donateMessage.message === '') { + message.warning('内容不能为空!') submitLoading.value = false return } @@ -233,18 +238,19 @@ async function submitMessage() { rs = await api.v2.donate.say.root.post( userData.getters.get_user_id, inputTradeNo, - message.value.message + donateMessage.value.message ) } catch (e) { - sendErrorMessage('请求列表失败: ' + e) + logger.error(e) + message.error('请求列表失败: ' + e) } if (!rs) return if (rs.status === 200) { - sendSuccessDialog('提交成功,感谢您的赞助~') + message.success('提交成功,感谢您的赞助~') getDonateList() submitLoading.value = false } else { - sendWarningDialog(rs.message) + message.warning(rs.message) submitLoading.value = false } } @@ -252,7 +258,7 @@ async function submitMessage() { async function doDonate() { donateLoading.value = true if (payType.value === '' || payType.value === null) { - sendWarningDialog('请选择支付方式') + message.error('请选择支付方式') donateLoading.value = false return } @@ -260,14 +266,15 @@ async function doDonate() { try { rs = await api.v2.donate.root.post(userData.getters.get_user_id, amount.value) } catch (e) { - sendErrorMessage('请求列表失败: ' + e) + logger.error(e) + message.error('请求列表失败: ' + e) } if (!rs) return if (rs.status === 200) { window.open(rs.data.url) donateLoading.value = false } else { - sendWarningDialog(rs.message) + message.error(rs.message) donateLoading.value = false } } diff --git a/src/views/IcpCheckView.vue b/src/views/IcpCheckView.vue index 16fc6cb..06b4fc5 100644 --- a/src/views/IcpCheckView.vue +++ b/src/views/IcpCheckView.vue @@ -47,14 +47,16 @@ diff --git a/src/components/sidebar/MainSidebar.vue b/src/components/sidebar/MainSidebar.vue index 69fd9b7..6e72a79 100644 --- a/src/components/sidebar/MainSidebar.vue +++ b/src/components/sidebar/MainSidebar.vue @@ -199,7 +199,7 @@ const menuOptions = [ const active = ref('') // const menuInstRef = ref(null) -router.beforeEach((to, from, next) => { +router.beforeEach((to, _, next) => { computeActiveKey(menuOptions, to.path) next() }) @@ -217,7 +217,7 @@ const computeActiveKey = (menuOptions, path) => { const route = useRoute() computeActiveKey(menuOptions, route.path) -const handleUpdateValue = (key, item) => { +const handleUpdateValue = (_, item) => { router.push({ path: item.path }) } diff --git a/src/views/auth/LoginView.vue b/src/views/auth/LoginView.vue index acfacc9..50cc3a6 100644 --- a/src/views/auth/LoginView.vue +++ b/src/views/auth/LoginView.vue @@ -95,7 +95,7 @@ const qqLoginLoading = ref(false) // const oauthLogin_loading = ref(false) let token = ref('') -const showTurnstile = ref(false) +let showTurnstile = ref(false) const model = ref([ { diff --git a/src/views/auth/RegisterView.vue b/src/views/auth/RegisterView.vue index 2fb3f42..c3e9587 100644 --- a/src/views/auth/RegisterView.vue +++ b/src/views/auth/RegisterView.vue @@ -19,8 +19,8 @@ - - + + @@ -148,7 +148,7 @@ async function register() { // const rs = post('https://api.locyanfrp.cn/User/DoReg', model.value) if (rs.status === 200) { message.success(rs.message) - router.push({ name: 'Login' }) + await router.push({ name: 'Login' }) } else { message.error(rs.message) } diff --git a/src/views/callback/auth/oauth/qq/LoginView.vue b/src/views/callback/auth/oauth/qq/LoginView.vue index a81e886..487f42e 100644 --- a/src/views/callback/auth/oauth/qq/LoginView.vue +++ b/src/views/callback/auth/oauth/qq/LoginView.vue @@ -44,7 +44,7 @@ if (code !== null) { userData.commit('set_token', rs.data.token) // console.log(rs.data) userData.commit('set_user_info', rs.data) - router.push(redirect || '/dashboard') + await router.push('/dashboard') } else { error.value = true errorMessage.value = rs.message From b24d50aee0231e05f76dfe47bbe27b5f0ccdedaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Wed, 4 Dec 2024 21:42:34 +0800 Subject: [PATCH 12/18] =?UTF-8?q?[+]=20=E6=B7=BB=E5=8A=A0=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/sidebar/MainSidebar.vue | 8 ++- src/views/AppView.vue | 85 ++++++++++++++++++++++++++ src/views/DonateView.vue | 4 +- src/views/IcpCheckView.vue | 2 +- src/views/auth/RegisterView.vue | 6 +- src/views/games/MinecraftView.vue | 2 +- src/views/proxies/ProxiesView.vue | 5 +- 7 files changed, 103 insertions(+), 9 deletions(-) diff --git a/src/components/sidebar/MainSidebar.vue b/src/components/sidebar/MainSidebar.vue index 6e72a79..d4324fd 100644 --- a/src/components/sidebar/MainSidebar.vue +++ b/src/components/sidebar/MainSidebar.vue @@ -41,7 +41,7 @@ import { CompassSharp, GameController } from '@vicons/ionicons5' -import { MoreCircle20Filled } from '@vicons/fluent' +import { MoreCircle20Filled, Box24Filled } from '@vicons/fluent' import { AttachMoneyFilled, AccountTreeOutlined } from '@vicons/material' import router from '@router' @@ -155,6 +155,12 @@ const menuOptions = [ } ] }, + { + path: '/app', + label: 'OAuth2.0 应用', + key: 'app', + icon: renderIcon(Box24Filled) + }, { key: 'status', icon: renderIcon(List), diff --git a/src/views/AppView.vue b/src/views/AppView.vue index 7cf6546..d4eda97 100644 --- a/src/views/AppView.vue +++ b/src/views/AppView.vue @@ -1,3 +1,88 @@ + diff --git a/src/views/DonateView.vue b/src/views/DonateView.vue index 5e58e83..c40c612 100644 --- a/src/views/DonateView.vue +++ b/src/views/DonateView.vue @@ -86,7 +86,8 @@ 留言 - + + 已登记的域名 - + - + diff --git a/src/views/games/MinecraftView.vue b/src/views/games/MinecraftView.vue index 0b9d56e..87afd13 100644 --- a/src/views/games/MinecraftView.vue +++ b/src/views/games/MinecraftView.vue @@ -27,7 +27,7 @@ 已创建的联机 - + diff --git a/src/views/proxies/ProxiesView.vue b/src/views/proxies/ProxiesView.vue index 81e79fa..2a6ad07 100644 --- a/src/views/proxies/ProxiesView.vue +++ b/src/views/proxies/ProxiesView.vue @@ -137,10 +137,7 @@ 隧道列表 - + Date: Wed, 4 Dec 2024 21:44:00 +0800 Subject: [PATCH 13/18] =?UTF-8?q?[-]=20=E7=A7=BB=E9=99=A4=20await?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/auth/LoginView.vue | 2 +- src/views/auth/RegisterView.vue | 2 +- src/views/callback/auth/oauth/qq/LoginView.vue | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/views/auth/LoginView.vue b/src/views/auth/LoginView.vue index 50cc3a6..1f01ec8 100644 --- a/src/views/auth/LoginView.vue +++ b/src/views/auth/LoginView.vue @@ -143,7 +143,7 @@ async function login(turnstileToken) { userData.commit('set_token', rs.data.token) // console.log(res.data) userData.commit('set_user_info', rs.data) - await router.push(redirect || '/dashboard') + router.push(redirect || '/dashboard') ldb.finish() } else { message.warning(rs.message) diff --git a/src/views/auth/RegisterView.vue b/src/views/auth/RegisterView.vue index 7e71b01..cdcbb8a 100644 --- a/src/views/auth/RegisterView.vue +++ b/src/views/auth/RegisterView.vue @@ -152,7 +152,7 @@ async function register() { // const rs = post('https://api.locyanfrp.cn/User/DoReg', model.value) if (rs.status === 200) { message.success(rs.message) - await router.push({ name: 'Login' }) + router.push({ name: 'Login' }) } else { message.error(rs.message) } diff --git a/src/views/callback/auth/oauth/qq/LoginView.vue b/src/views/callback/auth/oauth/qq/LoginView.vue index 487f42e..f65228a 100644 --- a/src/views/callback/auth/oauth/qq/LoginView.vue +++ b/src/views/callback/auth/oauth/qq/LoginView.vue @@ -44,7 +44,7 @@ if (code !== null) { userData.commit('set_token', rs.data.token) // console.log(rs.data) userData.commit('set_user_info', rs.data) - await router.push('/dashboard') + router.push('/dashboard') } else { error.value = true errorMessage.value = rs.message From d0c7d55439c8bd88aa868e671753578656c5fe01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Thu, 5 Dec 2024 19:20:57 +0800 Subject: [PATCH 14/18] [+] Add redirect url param --- src/api/v2/auth/oauth/authorize.api.ts | 2 ++ src/views/auth/oauth/AppAuthView.vue | 23 ++++++++++++++++++----- tsconfig.app.json | 5 ++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/api/v2/auth/oauth/authorize.api.ts b/src/api/v2/auth/oauth/authorize.api.ts index abde523..866a396 100644 --- a/src/api/v2/auth/oauth/authorize.api.ts +++ b/src/api/v2/auth/oauth/authorize.api.ts @@ -5,11 +5,13 @@ import base from '@/api/base' const authorize = async ( user_id: number, app_id: number, + redirect_url: string, request_permission_ids: Array ) => { const rs = post(`${base.api_v2_url}/auth/oauth/authorize`, { user_id: user_id, app_id: app_id, + redirect_url: redirect_url, request_permission_ids: request_permission_ids }) return base.buildResponse(await rs) diff --git a/src/views/auth/oauth/AppAuthView.vue b/src/views/auth/oauth/AppAuthView.vue index e81a994..95288aa 100644 --- a/src/views/auth/oauth/AppAuthView.vue +++ b/src/views/auth/oauth/AppAuthView.vue @@ -1,7 +1,7 @@ @@ -71,12 +76,15 @@ import userData from '@/utils/stores/userData/store' import { getUrlKey } from '@/utils/request' import { onMounted, ref } from 'vue' import Message from '@/utils/message' +import Notification from '@/utils/notification' import api from '@/api' import logger from '@/utils/logger' const message = new Message() +const notification = new Notification() const loading = ref(true) +const error = ref(false) const valid = ref(true) const urlKeys = { @@ -120,6 +128,7 @@ async function doAuthorize() { rs = await api.v2.auth.oauth.authorize( userData.getters.get_user_id, urlKeys.appId, + urlKeys.redirectUrl, permissionIds ) } catch (e) { @@ -132,6 +141,8 @@ async function doAuthorize() { if (rs.status === 200) { message.success('授权成功,正在重定向,请不要刷新浏览器') window.location.href = `${urlKeys.redirectUrl}?refresh_token=${rs.data.refresh_token}` + } else if (rs.status === 403) { + notification.error('授权失败', `服务器拒绝授权,原因: ${rs.message}`) } else { message.error('授权失败: ' + rs.message) } @@ -139,7 +150,7 @@ async function doAuthorize() { } function deny() { denyLoading.value = true - window.location.href = urlKeys.redirectUrl + '?error=User.Deny' + window.location.href = urlKeys.redirectUrl + '?error=user.deny' } onMounted(async () => { @@ -154,7 +165,7 @@ onMounted(async () => { message.error(e) return false } - if (rs) return false + if (!rs) return false if (rs.status === 200) { applicationName.value = rs.data.name applicationDescription.value = rs.data.description @@ -204,6 +215,8 @@ onMounted(async () => { let init3 = await initAppPermissions() if (init1 && init2 && init3) { loading.value = false + } else { + error.value = true } }) diff --git a/tsconfig.app.json b/tsconfig.app.json index e14c754..44a400b 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -8,7 +8,10 @@ "baseUrl": ".", "paths": { - "@/*": ["./src/*"] + "@/*": ["./src/*"], + "@views/*": ["./src/views/*"], + "@components/*": ["./src/components/*"], + "@router": ["./src//router/index.js"], } } } From 17f3a1224d03dd498ceb8b001950bceb202855a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Thu, 5 Dec 2024 22:27:30 +0800 Subject: [PATCH 15/18] [+] Add some API implementation --- src/api/v2/app/index.ts | 6 +++++- src/api/v2/app/root.api.ts | 33 +++++++++++++++++++++++++++++++++ src/api/v2/app/update.api.ts | 20 ++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/api/v2/app/root.api.ts create mode 100644 src/api/v2/app/update.api.ts diff --git a/src/api/v2/app/index.ts b/src/api/v2/app/index.ts index ded26e9..69b0546 100644 --- a/src/api/v2/app/index.ts +++ b/src/api/v2/app/index.ts @@ -1,5 +1,9 @@ +import root from './root.api' import info from './info.api' +import update from './update.api' export default { - info: info + root: root, + info: info, + update: update, } diff --git a/src/api/v2/app/root.api.ts b/src/api/v2/app/root.api.ts new file mode 100644 index 0000000..c6ad64b --- /dev/null +++ b/src/api/v2/app/root.api.ts @@ -0,0 +1,33 @@ +import base from '@/api/base' +//@ts-ignore +import { post, deleteReq } from '@/utils/request' + +const postApp = async ( + user_id: number, + app_name: string, + app_description: string | null, + redirect_url: string, +) => { + const rs = post(`${base.api_v2_url}/donate`, { + user_id: user_id, + app_name: app_name, + app_description: app_description, + redirect_url: redirect_url + }) + return base.buildResponse(await rs) +} + +const deleteApp = async (user_id: number, app_id: number) => { + const rs = deleteReq(`${base.api_v2_url}/donate`, { + user_id: user_id, + app_id: app_id + }) + return base.buildResponse(await rs) +} + +const root = { + post: postApp, + delete: deleteApp +} + +export default root diff --git a/src/api/v2/app/update.api.ts b/src/api/v2/app/update.api.ts new file mode 100644 index 0000000..747b89b --- /dev/null +++ b/src/api/v2/app/update.api.ts @@ -0,0 +1,20 @@ +//@ts-ignore +import { post } from '@/utils/request' +import base from '@/api/base' + +const update = async ( + user_id: number, + app_id: number, + app_description: string | null, + redirect_url: string | null, +) => { + const rs = post(`${base.api_v2_url}/app/update`, { + user_id: user_id, + app_id: app_id, + app_description: app_description, + redirect_url: redirect_url, + }) + return base.buildResponse(await rs) +} + +export default update From acefec5544800169d4a90b096fae06a210ebff6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Fri, 6 Dec 2024 18:59:50 +0800 Subject: [PATCH 16/18] [+] Add create, update and delete applications actions --- src/api/v2/app/all.api.ts | 12 ++ src/api/v2/app/index.ts | 2 + src/api/v2/app/root.api.ts | 6 +- src/api/v2/app/update.api.ts | 6 +- src/views/AppView.vue | 208 +++++++++++++++++++++++++++++- src/views/games/MinecraftView.vue | 4 +- src/views/proxies/ProxiesView.vue | 9 +- 7 files changed, 226 insertions(+), 21 deletions(-) create mode 100644 src/api/v2/app/all.api.ts diff --git a/src/api/v2/app/all.api.ts b/src/api/v2/app/all.api.ts new file mode 100644 index 0000000..dd9b463 --- /dev/null +++ b/src/api/v2/app/all.api.ts @@ -0,0 +1,12 @@ +//@ts-ignore +import { get } from '@/utils/request' +import base from '@/api/base' + +const all = async (user_id: number) => { + const rs = get(`${base.api_v2_url}/app/all`, { + user_id: user_id + }) + return base.buildResponse(await rs) +} + +export default all diff --git a/src/api/v2/app/index.ts b/src/api/v2/app/index.ts index 69b0546..c7f7fbc 100644 --- a/src/api/v2/app/index.ts +++ b/src/api/v2/app/index.ts @@ -1,9 +1,11 @@ import root from './root.api' import info from './info.api' import update from './update.api' +import all from './all.api' export default { root: root, info: info, update: update, + all: all } diff --git a/src/api/v2/app/root.api.ts b/src/api/v2/app/root.api.ts index c6ad64b..2d0b2c7 100644 --- a/src/api/v2/app/root.api.ts +++ b/src/api/v2/app/root.api.ts @@ -6,9 +6,9 @@ const postApp = async ( user_id: number, app_name: string, app_description: string | null, - redirect_url: string, + redirect_url: string ) => { - const rs = post(`${base.api_v2_url}/donate`, { + const rs = post(`${base.api_v2_url}/app`, { user_id: user_id, app_name: app_name, app_description: app_description, @@ -18,7 +18,7 @@ const postApp = async ( } const deleteApp = async (user_id: number, app_id: number) => { - const rs = deleteReq(`${base.api_v2_url}/donate`, { + const rs = deleteReq(`${base.api_v2_url}/app`, { user_id: user_id, app_id: app_id }) diff --git a/src/api/v2/app/update.api.ts b/src/api/v2/app/update.api.ts index 747b89b..c344a91 100644 --- a/src/api/v2/app/update.api.ts +++ b/src/api/v2/app/update.api.ts @@ -5,14 +5,16 @@ import base from '@/api/base' const update = async ( user_id: number, app_id: number, + app_name: string, app_description: string | null, - redirect_url: string | null, + redirect_url: string | null ) => { const rs = post(`${base.api_v2_url}/app/update`, { user_id: user_id, app_id: app_id, + app_name: app_name, app_description: app_description, - redirect_url: redirect_url, + redirect_url: redirect_url }) return base.buildResponse(await rs) } diff --git a/src/views/AppView.vue b/src/views/AppView.vue index d4eda97..67236ff 100644 --- a/src/views/AppView.vue +++ b/src/views/AppView.vue @@ -3,21 +3,86 @@ OAuth2.0 应用 - + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- 我的应用 - - 创建 + 我的应用 + 创建 - - - + + + 介绍: {{ app.description === '' ? '无' : (app.description ?? '无') }}
+ 重定向地址: {{ app.redirect_url }} + +
@@ -49,10 +114,12 @@ import { ref, onMounted } from 'vue' import userData from '@/utils/stores/userData/store' import Message from '@/utils/message' +import Dialog from '@/utils/dialog' import api from '@/api' import logger from '@/utils/logger' const message = new Message() +const dialog = new Dialog() const permissionList = ref([]) const permissionListLoading = ref(true) @@ -60,6 +127,129 @@ const permissionListLoading = ref(true) const applicationList = ref([]) const applicationListLoading = ref(true) +const showCreateModal = ref(false) +const showModifyModal = ref(false) +let creatingData = ref({ + name: '', + description: null, + redirectUrl: '' +}) +let modifyingData = ref({ + id: 0, + name: '', + description: null, + redirectUrl: '' +}) +const modalSegmented = { + content: 'soft', + footer: 'soft' +} + +function createModal() { + showCreateModal.value = true +} +async function createApplication() { + let rs + try { + rs = await api.v2.app.root.post( + userData.getters.get_user_id, + creatingData.value.name, + creatingData.value.description, + creatingData.value.redirectUrl + ) + } catch (e) { + logger.error(e) + message.error(e) + } + if (!rs) return + if (rs.status === 200) { + dialog.success('创建成功') + reloadApplications() + showCreateModal.value = false + } else { + message.error(rs.status) + } +} + +function modifyModal(id: number) { + showModifyModal.value = true + modifyingData.value.id = id + const data = applicationList.value.filter((item) => item.id === id)[0] + modifyingData.value.name = data.name + modifyingData.value.description = data.description + modifyingData.value.redirectUrl = data.redirect_url +} +async function modifyApplication() { + let rs + try { + rs = await api.v2.app.update( + userData.getters.get_user_id, + modifyingData.value.id, + modifyingData.value.name, + modifyingData.value.description, + modifyingData.value.redirectUrl + ) + } catch (e) { + logger.error(e) + message.error(e) + } + if (!rs) return + if (rs.status === 200) { + dialog.success('修改成功') + reloadApplications() + showModifyModal.value = false + } else { + message.error(rs.status) + } +} + +async function deleteApplication(id: number) { + dialog.warning('确认要删除这个应用吗?此操作不可逆', { + onPositiveClick: async () => { + let rs + try { + rs = await api.v2.app.root.delete(userData.getters.get_user_id, id) + } catch (e) { + logger.error(e) + message.error(e) + } + if (!rs) return + if (rs.status === 200) { + message.success('删除成功') + applicationList.value = applicationList.value.filter((item) => item.id !== id) + } else { + message.error(rs.message) + } + } + }) +} + +async function reloadApplications() { + applicationListLoading.value = true + const reload = await initApplications() + if (!reload) message.warning('刷新应用列表失败') + applicationListLoading.value = false +} + +async function initApplications(): Promise { + let rs + try { + rs = await api.v2.app.all(userData.getters.get_user_id) + } catch (e) { + logger.error(e) + message.error(e) + return false + } + if (!rs) return false + if (rs.status === 200) { + applicationList.value = rs.data.list + return true + } else { + message.error(rs.message) + } + return false +} + onMounted(async () => { async function initPermissions(): Promise { let rs @@ -81,8 +271,12 @@ onMounted(async () => { return false } let init1 = await initPermissions() + let init2 = await initApplications() if (init1) { permissionListLoading.value = false } + if (init2) { + applicationListLoading.value = false + } }) diff --git a/src/views/games/MinecraftView.vue b/src/views/games/MinecraftView.vue index 87afd13..b3558d7 100644 --- a/src/views/games/MinecraftView.vue +++ b/src/views/games/MinecraftView.vue @@ -157,9 +157,7 @@ async function deleteMinecraftGame(code) { } if (!rs) return if (rs.status === 200) { - created.value = created.value.filter((item) => { - return item.code !== code - }) + created.value = created.value.filter((item) => item.code !== code) message.success('删除成功') } else { message.error(rs.message) diff --git a/src/views/proxies/ProxiesView.vue b/src/views/proxies/ProxiesView.vue index 2a6ad07..70a4c60 100644 --- a/src/views/proxies/ProxiesView.vue +++ b/src/views/proxies/ProxiesView.vue @@ -4,8 +4,8 @@ v-model:show="showEditModal" class="custom-card" preset="card" - :style="bodyStyle" - :title="'编辑隧道 - 隧道ID: ' + String(selectProxyID)" + style="max-width: 600px" + :title="'编辑隧道 - ID: ' + String(selectProxyID)" size="huge" :bordered="false" :segmented="segmented" @@ -89,7 +89,7 @@ v-model:show="showDetailModal" class="custom-card" preset="card" - :style="bodyStyle" + style="max-width: 600px" :title="'详细信息 - 隧道ID: ' + selectProxyID" size="huge" :bordered="false" @@ -274,9 +274,6 @@ const selectProxyID = ref(0) const indexOfProxies = ref(0) const linkAddr = ref('') const editServerList = ref([]) -const bodyStyle = { - width: '600px' -} const segmented = { content: 'soft', footer: 'soft' From e1956a1021c48392e55d5ef9135c7a1c9fd041d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Fri, 6 Dec 2024 19:14:58 +0800 Subject: [PATCH 17/18] [*] Better view --- src/views/AppView.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/AppView.vue b/src/views/AppView.vue index 67236ff..6651a53 100644 --- a/src/views/AppView.vue +++ b/src/views/AppView.vue @@ -61,7 +61,7 @@ - +