完成前后端框架搭建,完成聊天页面布局

This commit is contained in:
RockYang
2023-03-17 14:17:27 +08:00
commit c25cc97450
35 changed files with 21044 additions and 0 deletions

77
web/src/utils/http.js Normal file
View File

@@ -0,0 +1,77 @@
import axios from 'axios'
import JSONBigInt from 'json-bigint'
import qs from 'qs'
import { ElMessageBox } from 'element-plus'
axios.defaults.timeout = 5000
axios.defaults.baseURL = process.env.VUE_APP_API_SECURE === true ? 'https://' + process.env.VUE_APP_API_HOST : 'http://' + process.env.VUE_APP_API_HOST
axios.defaults.withCredentials = true
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
axios.defaults.transformResponse = [(data, headers) => {
if (headers['content-type'].indexOf('application/json') !== -1) {
try {
data = JSONBigInt.parse(data)
} catch (e) { /* Ignore */ }
}
return data
}]
// HTTP拦截器
axios.interceptors.request.use(
config => {
// set session-name
config.headers['Session-Name'] = "xwebssh-sess-token"
return config
}, error => {
return Promise.reject(error)
})
axios.interceptors.response.use(
response => {
if (response.data.code == 0) {
return response
} else {
return Promise.reject(response.data)
}
}, error => {
if (error.response.status === 401) {
ElMessageBox.alert('您未登录或者登录已退出,请先登录再操作。', '登录提醒', {
confirmButtonText: '确定',
callback: () => {
// TODO: goto login page
},
})
}
if (error.response.status === 400) {
return Promise.reject(error.response.data)
}
return Promise.reject(error)
})
// send a http get request
export function httpGet (url, params = {}) {
return new Promise((resolve, reject) => {
axios.get(url, {
params: params
}).then(response => {
resolve(response.data)
}).catch(err => {
reject(err)
})
})
}
// send a http post request
export function httpPost (url, data = {}, options = {}) {
return new Promise((resolve, reject) => {
axios.post(url, qs.stringify(data), options).then(response => {
resolve(response.data)
}).catch(err => {
reject(err)
})
})
}

15
web/src/utils/libs.js Normal file
View File

@@ -0,0 +1,15 @@
/**
* Util lib functions
*/
// generate a random string
export function randString(length) {
const str = "0123456789abcdefghijklmnopqrstuvwxyz"
const size = str.length
let buf = []
for (let i = 0; i < length; i++) {
const rand = Math.random() * size
buf.push(str.charAt(rand))
}
return buf.join("")
}

8
web/src/utils/prototype.js vendored Normal file
View File

@@ -0,0 +1,8 @@
// add prototype method for array to insert item
Array.prototype.insert = function (index, item) {
this.splice(index, 0, item)
}
Array.prototype.remove = function (index) {
this.splice(index, 1)
}

7
web/src/utils/storage.js Normal file
View File

@@ -0,0 +1,7 @@
/* eslint-disable no-constant-condition */
/**
* storage handler
*/
// import Storage from 'good-storage'