This commit is contained in:
lnn19986213 2022-04-24 17:20:11 +08:00
parent f7642e3a0a
commit 6435bf1e44
6 changed files with 319 additions and 10 deletions

20
src/index.html Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script>
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
CSS.supports('top: constant(a)'))
document.write(
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
</script>
<title></title>
<!--preload-links-->
<!--app-context-->
</head>
<body>
<div id="app"><!--app-html--></div>
<script type="module" src="/main.js"></script>
</body>
</html>

View File

@ -22,3 +22,6 @@ const app = new Vue({
...App ...App
}) })
app.$mount() app.$mount()
import http from "@/request/index.js"
Vue.prototype.http=http

View File

@ -12,17 +12,19 @@
}" itemStyle=" height: 50px; "> }" itemStyle=" height: 50px; ">
</u-tabs> </u-tabs>
<view class="artworks"> <view class="artworks">
<view class="art_item" v-for="(v,i) in isLoveList" :key="i" @click="toDetail(i)"> <view class="art_item" v-for="(v,i) in isLoveList" :key="i">
<view class="art_item_top"> <view class="art_item_top">
<image src="../../static/artWork.png" mode=""></image> <image src="../../static/artWork.png" mode="" @click="toDetail(i)"></image>
<view class="like" @click="like(i)"> <view class="like" @click="like(i)">
<view :class=" isLoveList[i] ? 'img_selected' : 'img'"> <view :class=" isLoveList[i] ? 'img_selected' : 'img'">
<!-- 红心 --> <!-- 红心 -->
</view> </view>
<view class="select_num">
513
</view> </view>
</view> </view>
<view class=" art_item_bott"> </view>
<view class=" art_item_bott" @click="toDetail(i)">
<view class="title"> <view class="title">
摄影作品自由生活向美而生作品 摄影作品自由生活向美而生作品
</view> </view>
@ -121,12 +123,12 @@
.like { .like {
position: absolute; position: absolute;
top: calc(100% - 40px); top: calc(100% - 40px);
left: calc(100% - 40px); left: calc(100% - 70px);
width: 32px; width: 59px;
height: 32px; height: 32px;
background-color: white; background: rgba(38, 18, 18, 0.27);
z-index: 10; z-index: 10;
border-radius: 50%; border-radius: 16px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
@ -135,14 +137,20 @@
width: 16px; width: 16px;
height: 16px; height: 16px;
background: url(../../static/spaceHeart.png) center/100% no-repeat; background: url(../../static/spaceHeart.png) center/100% no-repeat;
float: left;
} }
.img_selected { .img_selected {
width: 16px; width: 16px;
height: 16px; height: 16px;
background: url(../../static/redHerart.png) center/100% no-repeat; background: url(../../static/redHerart.png) center/100% no-repeat;
float: left;
}
.select_num{
float: left;
margin-left: 10rpx;
color: #fff;
} }
} }
} }

View File

@ -115,7 +115,22 @@
this.topHeight = this.statusHeight + this.titleHeight this.topHeight = this.statusHeight + this.titleHeight
// #endif // #endif
}, },
// onShow() {
// this.getMyInfo()
// },
methods: { 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() { toBuy() {
this.cho = 0 this.cho = 0
}, },

52
src/request/index.js Normal file
View File

@ -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
}

211
src/request/interface.js Normal file
View File

@ -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;
}
}