From 6435bf1e44740820cd651a0992c5f43a67f9a44b Mon Sep 17 00:00:00 2001
From: lnn19986213 <1667908750@qq.com>
Date: Sun, 24 Apr 2022 17:20:11 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/index.html | 20 +++
src/main.js | 3 +
src/pages/ArtWorks/ArtWorks.vue | 28 +++--
src/pages/MyOrder/MyOrder.vue | 15 +++
src/request/index.js | 52 ++++++++
src/request/interface.js | 211 ++++++++++++++++++++++++++++++++
6 files changed, 319 insertions(+), 10 deletions(-)
create mode 100644 src/index.html
create mode 100644 src/request/index.js
create mode 100644 src/request/interface.js
diff --git a/src/index.html b/src/index.html
new file mode 100644
index 0000000..c3ff205
--- /dev/null
+++ b/src/index.html
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main.js b/src/main.js
index ef01fba..5ea1d0d 100644
--- a/src/main.js
+++ b/src/main.js
@@ -22,3 +22,6 @@ const app = new Vue({
...App
})
app.$mount()
+
+import http from "@/request/index.js"
+Vue.prototype.http=http
diff --git a/src/pages/ArtWorks/ArtWorks.vue b/src/pages/ArtWorks/ArtWorks.vue
index 7a910d2..66bf661 100644
--- a/src/pages/ArtWorks/ArtWorks.vue
+++ b/src/pages/ArtWorks/ArtWorks.vue
@@ -12,17 +12,19 @@
}" itemStyle=" height: 50px; ">
-
+
-
+
-
+
+ 513
+
-
+
摄影作品自由生活向美而生作品
@@ -121,12 +123,12 @@
.like {
position: absolute;
top: calc(100% - 40px);
- left: calc(100% - 40px);
- width: 32px;
+ left: calc(100% - 70px);
+ width: 59px;
height: 32px;
- background-color: white;
+ background: rgba(38, 18, 18, 0.27);
z-index: 10;
- border-radius: 50%;
+ border-radius: 16px;
display: flex;
align-items: center;
justify-content: center;
@@ -135,14 +137,20 @@
width: 16px;
height: 16px;
background: url(../../static/spaceHeart.png) center/100% no-repeat;
-
-
+ float: left;
}
.img_selected {
width: 16px;
height: 16px;
background: url(../../static/redHerart.png) center/100% no-repeat;
+ float: left;
+ }
+
+ .select_num{
+ float: left;
+ margin-left: 10rpx;
+ color: #fff;
}
}
}
diff --git a/src/pages/MyOrder/MyOrder.vue b/src/pages/MyOrder/MyOrder.vue
index 0964167..50d96c5 100644
--- a/src/pages/MyOrder/MyOrder.vue
+++ b/src/pages/MyOrder/MyOrder.vue
@@ -115,7 +115,22 @@
this.topHeight = this.statusHeight + this.titleHeight
// #endif
},
+ // onShow() {
+ // this.getMyInfo()
+ // },
methods: {
+ // getMyInfo() {
+ // this.http.request('/userInfo/userInfo', {}, "POST").then(res => {
+ // if (res.code == 200) {
+ // console.log(res)
+ // }
+ // }).catch(e => {
+ // uni.showToast({
+ // title:e.data.message,
+ // icon:"none",
+ // });
+ // })
+ // },
toBuy() {
this.cho = 0
},
diff --git a/src/request/index.js b/src/request/index.js
new file mode 100644
index 0000000..f7cbcc4
--- /dev/null
+++ b/src/request/index.js
@@ -0,0 +1,52 @@
+import http from './interface'
+
+/**
+ * 将业务所有接口统一起来便于维护
+ * 如果项目很大可以将 url 独立成文件,接口分成不同的模块
+ *
+ */
+
+export const request = (url,data,method,isback = false, isJson = false) => {
+ //设置请求前拦截器
+ http.interceptor.request = (config) => {
+ if(isJson){
+ config.header = {
+ 'Content-Type':'application/x-www-form-urlencoded'
+ }
+ }else{
+ config.header = {
+ 'Content-Type':'application/json;charset=UTF-8'
+ }
+ }
+ try {
+ const token = uni.getStorageSync('token');
+ // const Authorization = uni.getStorageSync('Authorization');
+ if(token){
+ config.header.Authorization = "Bearer "+ token
+ // config.header['x-token']= token
+ }else{
+ config.header.Authorization = ""
+ // config.header.token = ""
+ }
+ } catch (e) {
+ // error
+ }
+ }
+ //设置请求结束后拦截器
+ http.interceptor.response = (response) => {
+ //判断返回状态 执行相应操作
+ return response;
+ }
+ return http.request({
+ url,
+ method,
+ data,
+ isback
+ })
+}
+
+
+// 默认全部导出 import api from '@/common/vmeitime-http/'
+export default {
+ request
+}
\ No newline at end of file
diff --git a/src/request/interface.js b/src/request/interface.js
new file mode 100644
index 0000000..2f66b9a
--- /dev/null
+++ b/src/request/interface.js
@@ -0,0 +1,211 @@
+/**
+ * 通用uni-app网络请求
+ * 基于 Promise 对象实现更简单的 request 使用方式,支持请求和响应拦截
+ */
+
+export default {
+ config: {
+ // baseUrl: "http://192.168.0.57:8090/api", //王锡
+ // baseUrl: "http://192.168.124.110:8088/api", //周源
+ baseUrl: "http://192.168.0.7:8090/api", //俞燕红
+ // baseUrl: "https://wlsq.ydool.com.cn/api", //线上
+ header: {
+ 'Content-Type': 'application/json;charset=UTF-8',
+ // 'Content-Type':'application/x-www-form-urlencoded'
+ },
+ data: {},
+ method: "POST",
+ dataType: "json",
+ /* 如设为json,会对返回的数据做一次 JSON.parse */
+ responseType: "text",
+ success() {},
+ fail() {},
+ complete() {}
+ },
+ interceptor: {
+ request: null,
+ response: null
+ },
+ request(options) {
+ if (!options) {
+ options = {}
+ }
+ options.baseUrl = options.baseUrl || this.config.baseUrl
+ options.dataType = options.dataType || this.config.dataType
+ options.url = options.baseUrl + options.url
+ options.data = options.data || {}
+ options.method = options.method || this.config.method
+ options.sslVerify = false
+ options.timeout = 60000
+ //TODO 加密数据
+
+ //TODO 数据签名
+ /*
+ _token = {'token': getStorage(STOREKEY_LOGIN).token || 'undefined'},
+ _sign = {'sign': sign(JSON.stringify(options.data))}
+ options.header = Object.assign({}, options.header, _token,_sign)
+ */
+
+ return new Promise((resolve, reject) => {
+ let _config = null
+
+ options.complete = (response) => {
+ // console.log(response, 'response----')
+ let statusCode = response.statusCode
+ response.config = _config
+ if (process.env.NODE_ENV === 'development') {
+ if (statusCode === 200) {
+ // console.log("【" + _config.requestId + "】 结果:" + JSON.stringify(response.data))
+ }
+ }
+ if (this.interceptor.response) {
+ let newResponse = this.interceptor.response(response)
+ if (newResponse) {
+ response = newResponse
+ }
+ }
+ // 统一的响应日志记录
+ _reslog(response)
+ if (statusCode === 200) { //成功
+ if (options.isback) {
+ resolve(response.data);
+ } else {
+ if (response.data.code == 200) {
+ resolve(response.data);
+ } else if (response.data.code == 401) { //登录过期
+ reject(response)
+ } else {
+ uni.showToast({
+ title: response.data.msg,
+ icon: 'none',
+ mask: true
+ });
+ uni.hideLoading()
+ reject(response)
+ }
+ }
+ } else if (statusCode == 401) { //登录过期
+ uni.showToast({
+ title: '登录过期',
+ icon: 'none',
+ });
+ setTimeout(()=>{
+ uni.navigateTo({
+ url: '../login/login'
+ })
+ },1200)
+
+ } else {
+ uni.getNetworkType({
+ success: (res) => {
+ // console.log(res, "网络状态")
+ if (res.networkType == 'none') {} else {
+ uni.showToast({
+ title: "请求错误",
+ icon: 'none',
+ mask: true
+ });
+
+ }
+ }
+ });
+ reject(response)
+ }
+ }
+
+ _config = Object.assign({}, this.config, options)
+ _config.requestId = new Date().getTime()
+
+ if (this.interceptor.request) {
+ this.interceptor.request(_config)
+ }
+
+ // 统一的请求日志记录
+ _reqlog(_config)
+
+ if (process.env.NODE_ENV === 'development') {
+ // console.log("【" + _config.requestId + "】 地址:" + _config.url)
+ if (_config.data) {
+ // console.log("【" + _config.requestId + "】 参数:" + JSON.stringify(_config.data))
+ }
+ }
+
+ uni.request(_config);
+ });
+ },
+ get(url, data, options) {
+ if (!options) {
+ options = {}
+ }
+ options.url = url
+ options.data = data
+ options.method = 'GET'
+ return this.request(options)
+ },
+ post(url, data, options) {
+ if (!options) {
+ options = {}
+ }
+ options.url = url
+ options.data = data
+ options.method = 'POST'
+ return this.request(options)
+ },
+ put(url, data, options) {
+ if (!options) {
+ options = {}
+ }
+ options.url = url
+ options.data = data
+ options.method = 'PUT'
+ return this.request(options)
+ },
+ delete(url, data, options) {
+ if (!options) {
+ options = {}
+ }
+ options.url = url
+ options.data = data
+ options.method = 'DELETE'
+ return this.request(options)
+ }
+}
+
+
+/**
+ * 请求接口日志记录
+ */
+function _reqlog(req) {
+ if (process.env.NODE_ENV === 'development') {
+ // console.log("【" + req.requestId + "】 地址:" + req.url)
+ if (req.data) {
+ // console.log("【" + req.requestId + "】 请求参数:" + JSON.stringify(req.data))
+ }
+ }
+ //TODO 调接口异步写入日志数据库
+}
+
+/**
+ * 响应接口日志记录
+ */
+function _reslog(res) {
+ let _statusCode = res.statusCode;
+ if (process.env.NODE_ENV === 'development') {
+ // console.log("【" + res.config.requestId + "】 地址:" + res.config.url)
+ if (res.config.data) {
+ // console.log("【" + res.config.requestId + "】 请求参数:" + JSON.stringify(res.config.data))
+ }
+ // console.log("【" + res.config.requestId + "】 响应结果:" + JSON.stringify(res))
+ }
+ //TODO 除了接口服务错误外,其他日志调接口异步写入日志数据库
+ switch (_statusCode) {
+ case 200:
+ break;
+ case 401:
+ break;
+ case 404:
+ break;
+ default:
+ break;
+ }
+}