From 0f8c188be6622a8c36b76d620ab4c92a9fc2575b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=96=E5=A7=90?= <2981176548@qq.com> Date: Tue, 16 Apr 2024 14:06:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B9=8B=E5=89=8Drequest=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=BC=95=E7=94=A8=EF=BC=8C=E5=9C=A8api=E4=B8=8B=E9=9D=A2?= =?UTF-8?q?=EF=BC=8C=E5=90=8E=E7=BB=AD=E7=94=A8=E5=AE=8C=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E5=88=A0=E4=BA=86=EF=BC=8C=E7=8E=B0=E5=9C=A8=E8=87=AA=E5=B7=B1?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=E6=96=87=E4=BB=B6=E5=86=99=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/message.js | 15 + src/api/request.js | 843 ++++++++++++++++++++++++++++++++++ src/views/error-log/index.vue | 105 +++-- src/views/tab/index.vue | 58 ++- 4 files changed, 961 insertions(+), 60 deletions(-) create mode 100644 src/api/message.js create mode 100644 src/api/request.js diff --git a/src/api/message.js b/src/api/message.js new file mode 100644 index 0000000..b06a0a6 --- /dev/null +++ b/src/api/message.js @@ -0,0 +1,15 @@ + + +function getCurrentTimestamp() { + return new Date().getTime(); +} +export function login(data) { + return request({ + url: '/message/get', + method: 'post', + data, + headers: { + 'Timestamp':getCurrentTimestamp() + } + }); +} \ No newline at end of file diff --git a/src/api/request.js b/src/api/request.js new file mode 100644 index 0000000..d752ab4 --- /dev/null +++ b/src/api/request.js @@ -0,0 +1,843 @@ +import axios from "axios"; +import getCurrentTimestamp from "@/js/methods.js"; + +const api = 'http://nbxt.oa.x-lf.cn' + +/** + * 登录 + * @param data (user,password) + * @returns {*} + */ +const login = (data) => { + return axios({ + url: api+"/auth/login", + method: "post", + data: data, + headers: { + 'content-type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + }, + }) +} + +/** + * 注册 + * @param data (username,password,address,phone,email,sex,age) + * @returns {*} + */ +const register = (data) => { + return axios({ + url: api + "/auth/register", + method: "post", + data: data, + headers: { + 'content-type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 退出登录 + * @param token + * @returns {Promise> | *} + */ +const logout = (token) => { + return axios({ + url: api + "/auth/logout", + method: "get", + headers: { + 'Authorization':'Bearer '+token, + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 修改密码 + * @param data (oldPassword,newPassword,confirmPassword) + * @param token + * @returns {Promise> | *} + */ +const changePassword = (data, token) => { + return axios({ + url: api + "/auth/password", + method: "put", + data: data, + headers: { + 'Authorization':'Bearer '+token, + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 忘记密码 + * @param data (email,check(邮箱验证码),newPassword) + * @returns {*} + */ +const forgetPassword = (data) => { + return axios({ + url: api + "/auth/password/forget", + method: "put", + data: data, + headers: { + 'content-type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 邮箱登录 + * @param params 对象(包含邮箱email:string,验证码code:integer) + * @returns {*} + */ +const authLoginWithEmail = (params) => { + return axios({ + url: api + "/auth/login/email", + method: "get", + params: params, + headers: { + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 发送邮箱验证码 + * @param email 邮箱(string) + * @returns {*} + */ +const authSendEmailCode = (email) => { + return axios({ + url: api + "/auth/email/code", + method: "get", + params: email, + headers: { + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 获取全部用户信息 + * @param data (page,limit,search,role) + * @param token + * @returns {Promise> | *} + */ +const userAllCurrent = (data, token) => { + return axios({ + url: api + "/user/current/all", + method: "post", + data: data, + headers: { + 'Authorization':'Bearer ' + token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 获取一个用户信息(敏感) + * @param params (id,username,email,phone)可以只传一个参数 + * @param token + * @returns {Promise> | *} + */ +const userCurrent = (params, token) => { + return axios({ + url: api + "/user/current", + method: "get", + params: params, + headers: { + 'Authorization':'Bearer '+token, + // 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 新增用户 + * @param data (username,password,address,phone,email,sex,age)必须全部 + * @param token + * @returns {Promise> | *} + */ +const userAdd = (data, token) => { + return axios({ + url: api + "/user/add", + method: "post", + data: data, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 编辑用户 + * @param data (id,address,phone,email,age,signature,sex,avatar,nickname,description + * @param token + * @returns {Promise> | *} + */ +const userEdit = (data, token) => { + return axios({ + url: api + "/user/edit", + method: "put", + data: data, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 删除用户 + * @param id + * @param token + * @returns {Promise> | *} + */ +const userDelete = (id, token) => { + return axios({ + url: api + "/user/delete", + method: "delete", + params: { + id: id + }, + headers: { + 'Authorization':'Bearer '+token, + 'content-type':'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 锁定用户 + * @param data (id,isLock(1解锁)) + * @param token + * @returns {Promise> | *} + */ +const userLock = (data, token) => { + return axios({ + url: api + "/user/lock", + method: "put", + data: data, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 获取用户信息(非敏感) + * @param token + * @returns {Promise> | *} + */ +const userGetProfile = (token) => { + return axios({ + url: api + "/user/profile/get", + method: "get", + headers: { + 'Authorization':'Bearer '+token, + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 修改用户信息(普通用户) + * @param data (id,username,address,phone,email,sex,age,signature,avatar,nickname,description) + * @param token + * @returns {Promise> | *} + */ +const userEditProfile = (data, token) => { + return axios({ + url: api + "/user/profile/edit", + method: "put", + data: data, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 查询角色 + * @param id 可选,不填则是查询所有? + * @param token + * @returns {Promise> | *} + */ +const roleGet = (id, token) => { + return axios({ + url: api + "/role/get", + method: "get", + params: id, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 新增角色 + * @param data (name,displayName)示例(name:teacher, displayName:老师)必须 + * @param token + * @returns {Promise> | *} + */ +const roleAdd = (data, token) => { + return axios({ + url: api + "/role/add", + method: "post", + data: data, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 编辑角色 + * @param data (id,name,displayName(中文))必须 + * @param token + * @returns {Promise> | *} + */ +const roleEdit = (data, token) => { + return axios({ + url: api + "/role/edit", + method: "put", + data: data, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 删除角色 + * @param id + * @param token + * @returns {Promise> | *} + */ +const roleDelete = (id, token) => { + return axios({ + url: api + "/role/delete", + method: "delete", + params: id, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 给角色添加用户 + * @param data (rid,uid) + * @param token + * @returns {Promise> | *} + */ +const roleAddUser = (data, token) => { + return axios({ + url: api + "/role/user/add", + method: "post", + data: data, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 修改用户的角色 + * @param data (uid,rid) + * @param token + * @returns {Promise> | *} + */ +const roleChangeUser = (data, token) => { + return axios({ + url: api + "/role/user/change", + method: "put", + data: data, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 移除用户的角色 + * @param uid + * @param token + * @returns {Promise> | *} + */ +const roleRemoveUser = (uid, token) => { + return axios({ + url: api + "/role/user/remove", + method: "delete", + data: uid, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 查询轮播图(管理员) + * @param id 可选 + * @param token + * @returns {Promise> | *} + */ +const infoGetHeaderImage = (id, token) => { + return axios({ + url: api + "/info/header-image/get", + method: "get", + params: id, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 编辑轮播图信息 + * @param data (id,displayOrder(排序顺序),image(图片地址),title,description,isActive(是否启用)) + * @param token + * @returns {Promise> | *} + */ +const infoEditHeaderImage = ( data, token) => { + return axios({ + url: api + "/info/header-image/edit", + method: "put", + data: data, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 新增轮播图 + * @param data (displayOrder,image,title,description,isActive) + * @param token + * @returns {Promise> | *} + */ +const infoAddHeaderImage = (data, token) => { + return axios({ + url: api + "/info/header-image/add", + method: "post", + data: data, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 删除轮播图 + * @param id + * @param token + * @returns {Promise> | *} + */ +const infoDeleteHeaderImage = (id, token) => { + return axios({ + url: api + "/info/header-image/del", + method: "delete", + params: id, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 展示轮播图,顺序或倒序 + * @param showType 0倒序,1顺序 + * @param token + * @returns {Promise> | *} + */ +const infoEditSettingHeaderImage = (showType, token) => { + return axios({ + url: api + "/info/header-image/edit-setting", + method: "put", + data: showType, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 展示我负责的项目 + * @param data + * @param token + */ +const projectGet =(data, token) => { + const tags = data.tags + const isFinish = data.isFinish + // const principalUser = data.principalId + const encodedTags = tags.map(tag => encodeURIComponent(tag)); + const encodedIsFinish = isFinish.map(is => encodeURIComponent(is)) + const queryTags = `tags=${encodedTags.join('&tags=')}`; + const queryIsFinish = `isFinish=${encodedIsFinish.join('&isFinish=')}`; + return axios({ + url:api+ `/project/get?${queryTags}&${queryIsFinish}`, + method: "get", + headers:{ + 'Authorization':'Bearer '+token, + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 新增项目 + * @param token + * @param data + */ +const projectAdd =(token,data) => { + return axios({ + url:api+ "/project/add", + method: "post", + data:data, + headers:{ + 'Authorization':'Bearer '+token, + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 展示游客查看的项目 + */ +const projectGetCustom = (data) =>{ + const tags = data.tags + const isFinish = data.isFinish + // const principalUser = data.principalId + const encodedTags = tags.map(tag => encodeURIComponent(tag)); + const encodedIsFinish = isFinish.map(is => encodeURIComponent(is)) + const queryTags = `tags=${encodedTags.join('&tags=')}`; + const queryIsFinish = `isFinish=${encodedIsFinish.join('&isFinish=')}`; + return axios({ + url:`${api}/project/get/custom?id=${data.id}&${queryTags}&${queryIsFinish}`, + method: "get", + headers:{ + 'Timestamp': getCurrentTimestamp() + } + }) +} +// projectGetCustom().interceptors.request.use(config => { +// let url = config.url +// if (config.params) { +// url += '?' +// const keys = Object.keys(config.params) +// for (const key of keys) { +// url += `${key}=${encodeURIComponent(config.params[key])}&` +// } +// url = url.substring(0, url.length-1) +// config.params = {} +// } +// config.url = url +// return config +// }) + + + +/** + * 展示全部消息 + * + */ +const messageGet = (token) => { + return axios({ + url:api + "/message/get", + method:"get", + headers:{ + 'Authorization':'Bearer '+token, + 'content-type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 得到tag列表 + * @param token + */ +const getTagsProjectList = () =>{ + return axios({ + url:api+ "/tags/project/list", + method: "get", + headers:{ + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 得到tag列表 + * @param data + * @param token + * 获取项目的所有子系统 + */ +// const projectWorkGet = (data,token) => { +// return axios({ +// url:api + "/project/work/get", +// method:"get", +// data:data, +// headers:{ +// 'Authorization':'Bearer '+token, +// 'content-type': 'application/json;charset=utf-8', +// 'Timestamp': getCurrentTimestamp() +// } +// }) +// } + +const projectWorkGet = (data,token) =>{ + const tags = data.tags + const isFinish = data.isFinish + const encodedTags = tags.map(tag => encodeURIComponent(tag)); + const encodedIsFinish = isFinish.map(is => encodeURIComponent(is)) + const queryTags = `tags=${encodedTags.join('&tags=')}`; + const queryIsFinish = `isFinish=${encodedIsFinish.join('&isFinish=')}`; + return axios({ + url:`${api}/project/work/get?${queryTags}&${queryIsFinish}`, + method: "get", + headers:{ + 'content-type': 'application/json;charset=utf-8', + 'Authorization':'Bearer '+token, + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 根据项目id获取项目信息 + * @param id 项目id + * @param token 访问令牌 + * @returns {Promise> | *} + */ +const projectGetById = (id, token) => { + return axios({ + url: api + "/project/get/id?id=" + id, + method: "get", + headers: { + 'Authorization': 'Bearer ' + token, + 'Timestamp': getCurrentTimestamp() + } + }) +} + + +const projectWorkAdd = (data, token) => { + return axios({ + url: api + "/project/work/add" , + method: "post", + data:data, + headers: { + 'Authorization': 'Bearer ' + token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +// data(id) +const projectDelete = (id, token) => { + return axios({ + url: api + "/project/delete" , + method: "delete", + params: { + id: id + }, + headers: { + 'Authorization': 'Bearer ' + token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +/** + * 根据项目id获取子系统的所有信息 + * @param projectId + * @param token + */ +const moduleGetByProjectId = (projectId, token) => { + return axios({ + url: api + "/module/get?projectId=" + projectId, + method: "get", + // params: { + // projectId: projectId + // }, + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + + +/** + * 根据子系统id获取子模块信息 + * @param sysId + * @param token + */ +const moduleGetBySysId = (sysId, token) => { + return axios({ + url: api + "/module/get/min?sysId=" + sysId, + methods:"get", + headers: { + 'Authorization':'Bearer '+token, + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + + + +/*const moduleGetByProjectId = (projectId, token) => { + return axios ({ + url:api + "/module/get", + methods:"get", + params:projectId, + headers:{ + 'Authorization':'Bearer '+token, + 'content-type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +}*/ + + +const moduleDelete = (id, token) =>{ + return axios({ + url: api + "/module/delete/" + id, + method: "delete", + headers: { + 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp(), + 'Authorization':'Bearer '+ token + } + }) +} + +/** + * 获取模块/子系统信息 + * @param id + * @param token + * @returns {Promise> | *} + */ +const getModuleInfo = (id, token) => { + return axios({ + url: api + "/project/getwork/id", + method: 'get', + params: { + id: id + }, + headers: { + 'Authorization':'Bearer '+token, + // 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +const getPrincipalUser = (token) => { + return axios({ + url: api + "/project/pri", + method: 'get', + headers: { + 'Authorization':'Bearer '+token, + // 'Content-Type': 'application/json;charset=utf-8', + 'Timestamp': getCurrentTimestamp() + } + }) +} + +export default { + + login, + register, + logout, + changePassword, + forgetPassword, + authLoginWithEmail, + authSendEmailCode, + + userAllCurrent, + userCurrent, + userAdd, + userEdit, + userDelete, + userLock, + userGetProfile, + userEditProfile, + + roleGet, + roleEdit, + roleAdd, + roleDelete, + roleAddUser, + roleChangeUser, + roleRemoveUser, + + infoGetHeaderImage, + infoEditHeaderImage, + infoAddHeaderImage, + infoDeleteHeaderImage, + infoEditSettingHeaderImage, + + + projectGet, + projectGetCustom, + projectAdd, + projectGetById, + projectWorkAdd, + getTagsProjectList, + projectWorkGet, + projectDelete, + + + moduleGetByProjectId, + moduleGetBySysId, + moduleDelete, + getModuleInfo, + + messageGet, + getPrincipalUser + +} \ No newline at end of file diff --git a/src/views/error-log/index.vue b/src/views/error-log/index.vue index 9715850..26e7ae0 100644 --- a/src/views/error-log/index.vue +++ b/src/views/error-log/index.vue @@ -5,7 +5,7 @@ -
+
时间
-
- 状态 - - - + + + + + + + + + + + + + + + -
+
查询 @@ -58,14 +58,13 @@
{{row.name}} - {{ row.date }} + {{ row.text }}
-
-
address: {{ row.address }}
+
+
{{ row.createdAt }}
- Delete Delete @@ -158,42 +157,43 @@ const options = [ ]; // 表格 -interface User { - date: string +interface Message { + id: number + createdAt: string name: string - address: string + text: string } -const handleDelete = (index: number, row: User) => { +const handleDelete = (index: number, row: Message) => { console.log(index, row); }; -const tableData: User[] = [ +const tableData: Message[] = [ { - date: '2016-05-03', + id:1 , + createdAt: '2016-05-03', name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' + text: 'No. 189, Grove St, Los Angeles' }, - { - date: '2016-05-02', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, - { - date: '2016-05-04', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, - { - date: '2016-05-01', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - }, - { - date: '2016-05-01', - name: 'Tom', - address: 'No. 189, Grove St, Los Angeles' - } + { + id:1 , + createdAt: '2016-05-03', + name: 'Tom', + text: 'No. 189, Grove St, Los Angeles' + }, + { + id:1 , + createdAt: '2016-05-03', + name: 'Tom', + text: 'No. 189, Grove St, Los Angeles' + }, + { + id:1 , + createdAt: '2016-05-03', + name: 'Tom', + text: 'No. 189, Grove St, Los Angeles' + }, + ];