Browse Source

处理request 请求状态的问题

master
453530270@qq.com 2 years ago
parent
commit
19539f49aa
  1. 1
      README.md
  2. 12
      api/page.js
  3. 2
      pages/index/components/banner.vue
  4. 69
      pages/index/index.vue
  5. 8
      utils/request/index.js

1
README.md

@ -1,4 +1,5 @@
# 文化云 [uni-app端] # 文化云 [uni-app端]
1、[uni-app代理配置 manifest.json](https://blog.csdn.net/qq_36557846/article/details/123686878)
#### 如何使用uni-app端 #### 如何使用uni-app端

12
api/page.js

@ -1,8 +1,12 @@
import request from '@/utils/request' import request from '@/utils/request'
// 生产环境 与测试环境
const prefix ="AgencyAddress/"
// api地址 // api地址
const apiUri = { const apiUri = {
detail: 'page/detail' detail: 'page/detail',
pageinfo: prefix+'/logo/logoImag'
} }
// 页面数据 // 页面数据
@ -11,3 +15,9 @@ export function detail(pageId) {
pageId pageId
}) })
} }
// 查询全局设置----logo、栏目、底部、轮播图
export function pageinfo() {
// return request.jsonp(apiUri.pageinfo)
return request.get(apiUri.pageinfo)
}

2
pages/index/components/banner.vue

@ -33,7 +33,7 @@
watch:{ watch:{
dataList:function(e){ dataList:function(e){
// console.log("datalist",e) console.log("datalist",e)
} }
}, },

69
pages/index/index.vue

@ -82,49 +82,62 @@
}, },
mounted() { mounted() {
this.getBannerList(); this.getBannerList();
//
this.getHomeList(); // this.getHomeList();
}, },
methods: { methods: {
// //
getBannerList(){ getBannerList(){
// for demo Api.pageinfo().then((res)=>{
for(let i=0;i<3;i++){ // console.log("fda",eval(res))
const obj = { let ldata = res.data
"imgUrl": "http://192.168.66.16:8089/assets/store/img/diy/banner/01.png", //
"link": null this.imglist = ldata.rotations
} }).catch(err=>{
this.imglist.push(obj) console.log(err)
} });
// this.imglist.push(simg)
// Api.pageinfo().then(res=>{
//let aa = eval('(' + res + ')');
// let aa = JSON.stringify(res)
// console.log(aa.length)
// console.log(aa)
// if(res.resultCode =="00000000"){
// let ldata = res.data
// }
// console.log(res)
// });
}, },
// //
getHomeList(){ getHomeList(){
let rqdata={pay_type: 1,record_type: 2,goods_status: 1,page: 1,limit: 6} //
let rqdata = {"pay_type":2,"goods_status":1,"page":1,"limit":6}
//let rqdata={pay_type: 1,record_type: 2,goods_status: 1,page: 1,limit: 6}
Gapi.soglist(rqdata).then(res=>{ Gapi.soglist(rqdata).then(res=>{
if(res.resulteCode=='000000'){ if(res.resulteCode=='00000000'){
this.gdlist = res.data this.gdlist = res.data.data
} }
console.log("sgres:",res) console.log("sgres:",res)
}).catch(err=>{ }).catch(err=>{
console.log(err) console.log(err)
}); });
// //
for(let i=0;i<5;i++){ // for(let i=0;i<5;i++){
const obj = { // const obj = {
"goods_id": 10002, // "goods_id": 10002,
"goods_name": "00A02", // "goods_name": "00A02",
"selling_point": "", // "selling_point": "",
"goods_image": "http://192.168.66.16:8089/uploads/10001/20231021/be65b065b633bf469cb7bcfc15385936.jpg", // "goods_image": "http://192.168.66.16:8089/uploads/10001/20231021/be65b065b633bf469cb7bcfc15385936.jpg",
"goods_price_min": "100.00", // "goods_price_min": "100.00",
"goods_price_max": "100.00", // "goods_price_max": "100.00",
"line_price_min": "120.00", // "line_price_min": "120.00",
"line_price_max": "120.00", // "line_price_max": "120.00",
"goods_sales": 0 // "goods_sales": 0
} // }
this.gdlist.push(obj) // this.gdlist.push(obj)
} // }
} }
}, },

8
utils/request/index.js

@ -109,6 +109,7 @@ $http.dataFactory = async res => {
}) })
} }
console.log(res.response)
let httpData = res.response.data let httpData = res.response.data
if (typeof httpData == "string") { if (typeof httpData == "string") {
try { try {
@ -124,7 +125,7 @@ $http.dataFactory = async res => {
errMsg: "请检查api地址能否访问正常" errMsg: "请检查api地址能否访问正常"
}) })
} }
/*********以下只是模板(及共参考),需要开发者根据各自的接口返回类型修改*********/ /*********以下只是模板(及共参考),需要开发者根据各自的接口返回类型修改*********/
// 判断数据是否请求成功 // 判断数据是否请求成功
@ -133,6 +134,11 @@ $http.dataFactory = async res => {
// 返回正确的结果(then接受数据) // 返回正确的结果(then接受数据)
return Promise.resolve(httpData) return Promise.resolve(httpData)
} }
// why 系统专有
if(httpData.resultCode == '00000000'){
return Promise.resolve(httpData)
}
// 判断是否需要登录 // 判断是否需要登录
if (httpData.status == 401) { if (httpData.status == 401) {

Loading…
Cancel
Save