Skip to content

Commit

Permalink
Merge pull request #29 from LoCyan-Team/request-refactor
Browse files Browse the repository at this point in the history
重构 API 请求部分
  • Loading branch information
Daiyangcheng authored Sep 6, 2024
2 parents b199365 + 5efb849 commit b418987
Show file tree
Hide file tree
Showing 108 changed files with 2,540 additions and 1,256 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package.json
_deprecated/
15 changes: 7 additions & 8 deletions src/views/LanLobby.vue → _deprecated/LanLobby.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,9 @@
</template>
<script setup>
import { ref } from 'vue'
import { get, post, Delete } from '../utils/request'
import store from '../utils/stores/store.js'
import { sendErrorMessage, sendSuccessMessage } from '../utils/message'
import { SendErrorDialog, SendSuccessDialog, SendWarningDialog } from '../utils/dialog.js'
import { get, post, deleteReq } from '@/utils/request'
import store from '@/utils/stores/store'
import { sendSuccessDialog } from '@/utils/dialog'
const bodyStyle = {
width: '600px'
Expand Down Expand Up @@ -367,21 +366,21 @@ function createLobby() {
const rs = post('https://api-v2.locyanfrp.cn/api/v2/lan/private/create', lobbyValue.value)
rs.then((res) => {
if (res.status === 200) {
SendSuccessDialog('添加成功!')
sendSuccessDialog('添加成功!')
}
})
}
function deleteLobby(id) {
const rs = Delete(
'https://api-v2.locyanfrp.cn/api/v2/lan/private/delete?username=' +
const rs = deleteReq(
'https://api-v2.locyanfrp.cn/api/v2/lan/private/deleteReq?username=' +
store.getters.get_username +
'&id=' +
String(id)
)
rs.then((res) => {
if (res.status === 200) {
SendSuccessDialog('删除成功')
sendSuccessDialog('删除成功')
getPrivateLobby()
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/views/Status.vue → _deprecated/Status.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</template>
<script setup>
import { ref } from 'vue'
import { get } from '../utils/request.js'
import { get } from '@/utils/request'
const StatusList = ref([
{
Expand Down
34 changes: 17 additions & 17 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<!DOCTYPE html>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8"/>
<link rel="icon" type="image/svg+xml" href="/favicon.ico"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>LoCyanFrp 2.0 Dashboard</title>
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LoCyanFrp 2 Dashboard</title>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-KWN2LXQ8RV"></script>
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer = window.dataLayer || []

function gtag() {
dataLayer.push(arguments);
}
function gtag() {
dataLayer.push(arguments)
}

gtag('js', new Date());
gtag('js', new Date())

gtag('config', 'G-KWN2LXQ8RV');
gtag('config', 'G-KWN2LXQ8RV')
</script>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
39 changes: 21 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "locyanfrp",
"private": true,
"version": "2.0.3",
"version": "2.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -13,36 +13,39 @@
"@vicons/ionicons4": "^0.12.0",
"@vicons/ionicons5": "^0.12.0",
"@vicons/material": "^0.12.0",
"axios": "^1.6.5",
"axios": "^1.7.7",
"clipboard": "^2.0.11",
"highlight.js": "^11.9.0",
"highlight.js": "^11.10.0",
"js-cookie": "^3.0.5",
"json": "^11.0.0",
"marked": "^11.1.1",
"marked": "^11.2.0",
"nodejs-websocket": "^1.7.2",
"postcss": "^8.4.33",
"qs": "^6.11.2",
"tailwindcss": "^3.4.1",
"unplugin-auto-import": "^0.17.3",
"postcss": "^8.4.45",
"qs": "^6.13.0",
"tailwindcss": "^3.4.10",
"unplugin-auto-import": "^0.17.8",
"unplugin-vue-components": "^0.26.0",
"vue": "^3.4.27",
"vue": "^3.5.2",
"vue-axios": "^3.5.2",
"vue-cookies": "^1.8.3",
"vue-cookies": "^1.8.4",
"vue-native-websocket": "^2.0.15",
"vue-route": "^1.5.1",
"vue-router": "^4.2.5",
"vue-router": "^4.4.3",
"vuex": "^4.1.0"
},
"devDependencies": {
"@types/qs": "^6.9.11",
"@tsconfig/node20": "^20.1.4",
"@types/qs": "^6.9.15",
"@vicons/fa": "^0.12.0",
"@vitejs/plugin-vue": "^3.2.0",
"autoprefixer": "^10.4.17",
"cssnano": "^5.1.15",
"@vitejs/plugin-vue": "^5.1.3",
"@vue/tsconfig": "^0.5.1",
"autoprefixer": "^10.4.20",
"cssnano": "^7.0.6",
"git-revision-vite-plugin": "^0.0.11",
"naive-ui": "2.38.2",
"prettier": "^2.8.8",
"vfonts": "^0.0.3",
"vite": "^3.2.8"
"prettier": "^3.3.3",
"vfonts": "^0.1.0",
"vite": "^5.4.3",
"vite-plugin-vue-devtools": "^7.4.4"
}
}
4 changes: 2 additions & 2 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
autoprefixer: {}
}
}
63 changes: 33 additions & 30 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ import MainNav from './components/MainNav.vue'
import GuestNav from './components/GuestNav.vue'
import Notification from './components/Notification.vue'
import { computed } from 'vue'
import store from './utils/stores/store.js'
import store from '@/utils/stores/store'
import hljs from 'highlight.js/lib/core'
import ini from 'highlight.js/lib/languages/ini'
import nginx from 'highlight.js/lib/languages/nginx'
import { get } from './utils/request.js'
import { sendWarningMessage } from './utils/message.js'
import { logout } from './utils/profile.js'
// import { init_ws, SetOnMessageFunction } from "./utils/websocket.js";
import { sendInfoNotification } from './utils/notification.js'
import api from '@/api'
import { sendWarningMessage, sendErrorMessage } from '@/utils/message'
import { logout } from '@/utils/profile'
// import { init_ws, SetOnMessageFunction } from "@/utils/websocket.js";
import { sendInfoNotification } from '@/utils/notification'
const osThemeRef = useOsTheme()
const theme = computed(() => (osThemeRef.value === 'dark' ? darkTheme : null))
Expand All @@ -64,31 +64,34 @@ if (inited === false) {
inited = true
}
setInterval(() => {
setInterval(async () => {
if (store.getters.get_token) {
const rs = get(
'https://api.locyanfrp.cn/Account/info?username=' +
store.getters.get_username +
'&token=' +
store.getters.get_token,
[]
)
rs.then((res) => {
if (res.status === 0) {
store.commit('set_user_info', res)
// localStorage.setItem('proxies', res.proxies_num)
// localStorage.setItem('traffic', res.traffic)
// localStorage.setItem('set_limit', res)
// store.set_limit({
// inbound: res.inbound,
// outbound: res.outbound,
// })
}
if (res.status === -3) {
sendWarningMessage('登录过期或未登录,请重新登录后台!')
logout()
}
})
let rs
try {
rs = await api.v2.users.info(store.getters.get_username)
} catch (e) {
sendWarningMessage('查询用户信息失败: ' + e + ',请重新登录后台!')
logout()
}
if (!rs) return
if (rs.status === 200) {
// console.log(rs)
store.commit('set_user_email', rs.data.email)
store.commit('set_user_inbound', rs.data.inbound)
store.commit('set_user_outbound', rs.data.inbound)
store.commit('set_user_traffic', rs.data.traffic)
// localStorage.setItem('proxies', res.proxies_num)
// localStorage.setItem('traffic', res.traffic)
// localStorage.setItem('set_limit', res)
// store.set_limit({
// inbound: res.inbound,
// outbound: res.outbound,
// })
}
if (rs.status === 401) {
sendWarningMessage('登录过期或未登录,请重新登录后台!')
logout()
}
}
}, 10000)
</script>
12 changes: 12 additions & 0 deletions src/api/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const base = {
api_v1_url: 'https://api.locyanfrp.cn',
api_v2_url: 'https://api-v2.locyanfrp.cn/api/v2',
buildResponse: (res: any, useDataPath: boolean = true) => {
return {
status: res.status as number,
data: useDataPath ? res.data.data : res.data
}
}
}

export default base
9 changes: 9 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import v1 from './v1'
import v2 from './v2'

const api = {
v1: v1,
v2: v2
}

export default api
15 changes: 15 additions & 0 deletions src/api/v1/Account/EditEmail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import base from '@/api/base'
//@ts-ignore
import { get } from '@/utils/request'

const EditEmail = async (username: string, token: string, email: string, code: string) => {
const rs = await get(`${base.api_v1_url}/Account/EditEmail`, {
username: username,
token: token,
email: email,
code: code
})
return base.buildResponse(rs, false)
}

export default EditEmail
14 changes: 14 additions & 0 deletions src/api/v1/Account/SendEditMail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import base from '@/api/base'
//@ts-ignore
import { get } from '@/utils/request'

const SendEditMail = async (username: string, token: string, email: string) => {
const rs = await get(`${base.api_v1_url}/Account/SendEditMail`, {
username: username,
token: token,
email: email
})
return base.buildResponse(rs, false)
}

export default SendEditMail
7 changes: 7 additions & 0 deletions src/api/v1/Account/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import EditEmail from './EditEmail'
import SendEditMail from './SendEditMail'

export default {
EditEmail: EditEmail,
SendEditMail: SendEditMail
}
19 changes: 19 additions & 0 deletions src/api/v1/App/GetBroadCast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import base from '@/api/base'
//@ts-ignore
import { get } from '@/utils/request'

/**
* 获取公告
* @returns {
* status: int,
* data: {
* broadcast: string
* }
* }
*/
const GetBroadCast = async () => {
const rs = await get(`${base.api_v1_url}/App/GetBroadCast`, {})
return base.buildResponse(rs, false)
}

export default GetBroadCast
20 changes: 20 additions & 0 deletions src/api/v1/App/GetCSApp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import base from '@/api/base'
//@ts-ignore
import { get } from '@/utils/request'

/**
* 获取公告
* @returns {
* status: int,
* data: {
* url: string,
* name: string,
* }
* }
*/
const GetCSApp = async () => {
const rs = await get(`${base.api_v1_url}/App/GetCSApp`, {})
return base.buildResponse(rs, false)
}

export default GetCSApp
20 changes: 20 additions & 0 deletions src/api/v1/App/_root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import base from '@/api/base'
//@ts-ignore
import { get } from '@/utils/request'

/**
* 获取通知
* @returns {
* status: int,
* data: {
* ads: string,
* content: string
* }
* }
*/
const root = async () => {
const rs = await get(`${base.api_v1_url}/App`, {})
return base.buildResponse(rs, false)
}

export default root
9 changes: 9 additions & 0 deletions src/api/v1/App/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import root from './_root'
import GetBroadCast from './GetBroadCast'
import GetCSApp from './GetCSApp'

export default {
root: root,
GetBroadCast: GetBroadCast,
GetCSApp: GetCSApp
}
Loading

0 comments on commit b418987

Please sign in to comment.