Compare commits
2 Commits
master
...
feature/请求
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c1d6bcefd | ||
|
|
1172dc260c |
17
.eslintrc.js
17
.eslintrc.js
@@ -29,15 +29,16 @@ module.exports = {
|
||||
}
|
||||
],
|
||||
'vue/max-attributes-per-line': [
|
||||
2,
|
||||
{
|
||||
singleline: 10,
|
||||
multiline: {
|
||||
max: 1,
|
||||
allowFirstLine: true
|
||||
'error',
|
||||
{
|
||||
'singleline': {
|
||||
'max': 1
|
||||
},
|
||||
'multiline': {
|
||||
'max': 1
|
||||
}
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
'vue/singleline-html-element-content-newline': 'off',
|
||||
'vue/multiline-html-element-content-newline': 'off',
|
||||
'vue/require-v-for-key': 'off',
|
||||
|
||||
7
main.js
7
main.js
@@ -1,6 +1,5 @@
|
||||
import App from './App'
|
||||
|
||||
//引入uView-ui组件库(注意这两行要放在 import Vue 之后)
|
||||
// 引入uView-ui组件库(注意这两行要放在 import Vue 之后)
|
||||
import uView from 'uview-ui'
|
||||
Vue.use(uView)
|
||||
|
||||
@@ -9,7 +8,7 @@ import Vue from 'vue'
|
||||
Vue.config.productionTip = false
|
||||
App.mpType = 'app'
|
||||
const app = new Vue({
|
||||
...App
|
||||
...App
|
||||
})
|
||||
app.$mount()
|
||||
// #endif
|
||||
@@ -22,4 +21,4 @@ export function createApp() {
|
||||
app
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
// #endif
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {apiService} from '../../service/request.js'
|
||||
export default {
|
||||
computed: {},
|
||||
data() {
|
||||
return {
|
||||
list: [{
|
||||
@@ -24,7 +26,11 @@
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
|
||||
console.log('--------------')
|
||||
apiService.getCategories().then(res => {
|
||||
const {message} = res.data
|
||||
console.log(message)
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
|
||||
|
||||
221
service/request.js
Normal file
221
service/request.js
Normal file
@@ -0,0 +1,221 @@
|
||||
|
||||
const serverHost = 'https://api-ugo-web.itheima.net'
|
||||
function isOutTime(res) {
|
||||
if (res.data.message === '请先登录') {
|
||||
uni.showToast('登录信息已过期,请重新登录')
|
||||
setTimeout(() => {
|
||||
uni.redirectTo({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
}, 1000)
|
||||
uni.removeStorageSync('userInfo')
|
||||
uni.removeStorageSync('token')
|
||||
} else {
|
||||
// uni.showToast(res.data.message);
|
||||
}
|
||||
}
|
||||
|
||||
const service = {
|
||||
get(url) {
|
||||
const header = {}
|
||||
header['Authorization'] = 'Bearer ' + uni.getStorageSync('token')
|
||||
header['content-type'] = 'application/json'
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
method: 'get',
|
||||
url: serverHost + url,
|
||||
header: header,
|
||||
success: res => {
|
||||
// // 调用接口成功
|
||||
// if (!res.data.data) {
|
||||
// isOutTime(res)
|
||||
// reject(res)
|
||||
// }
|
||||
resolve(res)
|
||||
},
|
||||
fail: err => {
|
||||
// 调用接口失败
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
post(url, data, isLogin) {
|
||||
const header = {}
|
||||
if (isLogin) {
|
||||
// header['content-type'] = 'application/x-www-form-urlencoded';
|
||||
console.log(isLogin)
|
||||
header['Authorization'] = ''
|
||||
} else {
|
||||
header['Authorization'] = 'Bearer ' + uni.getStorageSync('token')
|
||||
header['content-type'] = 'application/json'
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
method: 'post',
|
||||
url: serverHost + url,
|
||||
data: data,
|
||||
header: header,
|
||||
timeout: 30000,
|
||||
success: res => {
|
||||
console.log(1111, res)
|
||||
uni.hideLoading()
|
||||
// if (res.data.exception === 'UnAuthorizedException') {
|
||||
// let pages = getCurrentPages()
|
||||
// let page = (pages[pages.length - 1]).route
|
||||
// if (!page.includes('login')) {
|
||||
// uni.navigateTo({
|
||||
// url: `/pages/login/login`
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
// if (res.data.message) {
|
||||
// isOutTime(res);
|
||||
// toast.error(res.data.message)
|
||||
// reject(res);
|
||||
// }
|
||||
|
||||
// if (isLogin && !res.data.access_token) {
|
||||
// reject(res);
|
||||
// } else {
|
||||
// resolve(res);
|
||||
// }
|
||||
resolve(res)
|
||||
},
|
||||
fail: err => {
|
||||
console.log('err', err)
|
||||
uni.hideLoading()
|
||||
// 调用接口失败
|
||||
try {
|
||||
toast.error(err.data.message)
|
||||
} catch (errr) {
|
||||
toast.error('服务器出错')
|
||||
}
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
put(url, data, isLogin) {
|
||||
const header = {}
|
||||
|
||||
if (isLogin) {
|
||||
header['content-type'] = 'application/x-www-form-urlencoded'
|
||||
} else {
|
||||
header['Authorization'] = 'Bearer ' + uni.getStorageSync('token')
|
||||
header['content-type'] = 'application/json'
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
method: 'put',
|
||||
url: serverHost + url,
|
||||
header: header,
|
||||
success: res => {
|
||||
if (!res.data.flag) {
|
||||
isOutTime(res)
|
||||
reject(res)
|
||||
}
|
||||
|
||||
resolve(res)
|
||||
},
|
||||
data: data,
|
||||
fail: err => {
|
||||
// 调用接口失败
|
||||
// toast.error(res.data.message)
|
||||
uni.hideLoading()
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
const toastDuration = 1500
|
||||
const toast = {
|
||||
// duration: 1500,
|
||||
success: (text, dur) => {
|
||||
// $wuxToptips().success({
|
||||
// hidden: false,
|
||||
// text: text || '成功',
|
||||
// duration: dur || toastDuration
|
||||
// });
|
||||
uni.showToast({
|
||||
title: text || '成功',
|
||||
duration: dur || toastDuration
|
||||
})
|
||||
},
|
||||
warn: text => {
|
||||
// $wuxToptips().warn({
|
||||
// hidden: false,
|
||||
// text: text || '未知警告',
|
||||
// duration: toastDuration
|
||||
// });
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: text || '未知警告',
|
||||
duration: toastDuration
|
||||
})
|
||||
},
|
||||
error: text => {
|
||||
// $wuxToptips().error({
|
||||
// hidden: false,
|
||||
// text: text || '未知错误',
|
||||
// duration: toastDuration
|
||||
// });
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: text || '未知错误',
|
||||
duration: toastDuration
|
||||
})
|
||||
}
|
||||
}
|
||||
const apiService = {
|
||||
uploadImgUrl: serverHost,
|
||||
imgUrl: serverHost,
|
||||
login: data => {
|
||||
data = Object.assign(data || {}, {})
|
||||
const url = `/api`
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(service.post(url, data, true))
|
||||
})
|
||||
},
|
||||
// 获取
|
||||
getCategories(data) {
|
||||
const url = `/api/public/v1/categories`
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(service.get(url, data))
|
||||
})
|
||||
},
|
||||
// 新增
|
||||
addOutboundOrder(data) {
|
||||
const url = `/api`
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(service.post(url, data))
|
||||
})
|
||||
},
|
||||
// 提交
|
||||
deliveryOrderConfirm(data) {
|
||||
const url = `/api`
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(service.post(url, data))
|
||||
})
|
||||
},
|
||||
// 解密
|
||||
decrypt(data) {
|
||||
const url = `/api`
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(service.post(url, { data }))
|
||||
})
|
||||
},
|
||||
// 国密sm4加密
|
||||
sm4Encrypt(data) {
|
||||
const url = `/api`
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(service.sm(url, data))
|
||||
})
|
||||
}
|
||||
}
|
||||
export { apiService, toast }
|
||||
Reference in New Issue
Block a user