From 645112d4fe310c27bc4ebd9ff93cb2f7ad858dcd Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Fri, 8 Dec 2023 16:55:42 +0800 Subject: [PATCH] api --- .env.development | 3 ++ .env.production | 3 ++ src/components/rank.vue | 22 +++++--- src/main.js | 5 ++ src/pages/article/detail.vue | 62 +++++++++++++++++++--- src/pages/auth/login.vue | 21 ++++++-- src/pages/feedback/add.vue | 13 +++++ src/pages/index/index.vue | 69 +++++++++++++++++++------ src/pages/score/user-rank.vue | 97 ++++++++++++++++++++++++++++++++--- src/static/css/base.css | 3 ++ src/utils/index.js | 3 ++ src/utils/request.js | 58 +++++++++++++++++++++ 12 files changed, 317 insertions(+), 42 deletions(-) create mode 100644 .env.development create mode 100644 .env.production create mode 100644 src/utils/index.js create mode 100644 src/utils/request.js diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..09bf489 --- /dev/null +++ b/.env.development @@ -0,0 +1,3 @@ +ENV = 'development' + +VUE_APP_BASE_API = 'http://local.party-rank.host' \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..8b0b51b --- /dev/null +++ b/.env.production @@ -0,0 +1,3 @@ +ENV = 'production' + +VUE_APP_BASE_API = 'http://www.xbzt.cc' \ No newline at end of file diff --git a/src/components/rank.vue b/src/components/rank.vue index a763967..61365be 100644 --- a/src/components/rank.vue +++ b/src/components/rank.vue @@ -6,16 +6,19 @@ - - {{ index + 1 }} - - - + + + {{ item.rank }} + + + + + {{ item.name }} - {{ item.name }} + {{ item.score }} - {{ item.score }} - + + @@ -52,6 +55,9 @@ justify-content: space-between; padding: 15rpx 0; } + .table-body .table-tr { + border-bottom: 1px solid #e5e5e5; + } .avatar ::v-deep uni-image { border-radius: 30rpx; width: 64rpx; diff --git a/src/main.js b/src/main.js index 7feb7a6..9ceae00 100644 --- a/src/main.js +++ b/src/main.js @@ -11,4 +11,9 @@ App.mpType = 'app' const app = new Vue({ ...App }) + +require('@/utils/request.js')() + +Vue.prototype.$ajax = uni.$u.http + app.$mount() diff --git a/src/pages/article/detail.vue b/src/pages/article/detail.vue index c0c485e..973cabe 100644 --- a/src/pages/article/detail.vue +++ b/src/pages/article/detail.vue @@ -1,9 +1,14 @@ @@ -11,20 +16,56 @@ export default { data() { return { - content: '

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

' + noData: false, + title: '', + content: '' + } + }, + onLoad(e) { + // 共性指标 + if (e.type == 'common') { + uni.setNavigationBarTitle({ + title: '共性指标' + }) + this.$ajax.get('/api/article/common', { custom: { loading: true } }).then(res => { + if (res.status == 0 && res.data) { + this.title = res.data.title + this.content = res.data.content + } else { + this.noData = true + } + }) + } + // 进阶指标 + else if (e.type == 'cate') { + uni.setNavigationBarTitle({ + title: '进阶指标' + }) + this.$ajax.get('/api/article/cate', { custom: { loading: true } }).then(res => { + if (res.status == 0 && res.data) { + this.title = res.data.title + this.content = res.data.content + if (res.data.party_cate) { + uni.setNavigationBarTitle({ + title: res.data.party_cate.name + }) + } + } else { + this.noData = true + } + }) } } } \ No newline at end of file diff --git a/src/pages/auth/login.vue b/src/pages/auth/login.vue index aa68760..8569a89 100644 --- a/src/pages/auth/login.vue +++ b/src/pages/auth/login.vue @@ -26,10 +26,15 @@ data() { return { username: '', - password: '' + password: '', + redirect: '' + } + }, + onLoad(e) { + if (e.redirect) { + this.redirect = e.redirect } }, - onLoad() {}, methods: { submit() { if (!this.username) { @@ -38,12 +43,22 @@ title: '账号必填' }) } - if (!this.username) { + if (!this.password) { return uni.showToast({ icon: 'error', title: '密码必填' }) } + + this.$ajax.post('/api/login', { username: this.username, password: this.password }).then(res => { + if (res.status == 0) { + const token = res.data.token + uni.setStorageSync('party_rank_auth_token', token) + uni.reLaunch({ + url: '/pages/index/index' + }) + } + }) } } } diff --git a/src/pages/feedback/add.vue b/src/pages/feedback/add.vue index df18e0e..83989bb 100644 --- a/src/pages/feedback/add.vue +++ b/src/pages/feedback/add.vue @@ -24,13 +24,26 @@ icon: 'error' }) } + this.$ajax.post('/api/feedback', { content: this.content }, { custom: { loading: true } }).then(res => { + if (res.status == 0) { + this.content = '' + uni.showToast({ + title: '提交成功', + icon: 'succsss' + }) + } + }) } } } \ No newline at end of file diff --git a/src/static/css/base.css b/src/static/css/base.css index a593542..b8d433c 100644 --- a/src/static/css/base.css +++ b/src/static/css/base.css @@ -1,3 +1,6 @@ +::v-deep uni-page-wrapper { + background-color: #efefef; +} .page { background-color: #efefef; /* position: absolute; diff --git a/src/utils/index.js b/src/utils/index.js new file mode 100644 index 0000000..8241ff2 --- /dev/null +++ b/src/utils/index.js @@ -0,0 +1,3 @@ +export function isLogin() { + return !!uni.getStorageSync('party_rank_auth_token') +} \ No newline at end of file diff --git a/src/utils/request.js b/src/utils/request.js new file mode 100644 index 0000000..3c916e1 --- /dev/null +++ b/src/utils/request.js @@ -0,0 +1,58 @@ +// http 网络请求 + +module.exports = () => { + // 全局配置 + uni.$u.http.setConfig((config) => { + config.baseURL = process.env.VUE_APP_BASE_API + config.custom = { + toast: true, + loading: false + } + return config + }) + + // 请求拦截 + uni.$u.http.interceptors.request.use( + (config) => { + const token = uni.getStorageSync('party_rank_auth_token') + if (token) { + config.header['Authorization'] = `Bearer ${token}` + } + config.header['Accept'] = 'application/json' + if (config.custom.loading) { + uni.showLoading() + } + return config + }, + config => { + return Promise.reject(config) + } + ) + + // 响应拦截 + uni.$u.http.interceptors.response.use( + (response) => { + uni.hideLoading() + + const res = response.data + if (response.config.custom.toast && res.status != 0 && res.doNotDisplayToast != 1) { + uni.showModal({ + title: res.msg, + showCancel: false + }) + } + if (res.code == 401) { + uni.reLaunch({ + url: '/pages/auth/login' + }) + } + + return res + }, + (response) => { + uni.hideLoading() + return Promise.reject(response) + } + ) +} +