Commit 82baad4c by 李伟康

增加mock

1 parent 334d8570
......@@ -75,7 +75,8 @@
],
"usingComponents": {
"calendar": "/components/Calendar/Calendar",
"NavigationBar": "/components/NavigationBar/NavigationBar"
"navigation-bar": "/components/NavigationBar/NavigationBar",
"glsx-image": "/components/image/index"
},
"style": "v2",
"resolveAlias": {
......
// components/tabView/tabView.js
Component({
options: {
multipleSlots: true // 在组件定义时的选项中启用多slot支持
},
/**
* 组件的属性列表
*/
properties: {
tabList: {
type: Array,
value: []
},
height: null,
tagIndex: {
type: Number,
value: 0
},
refresherEnabled: Boolean,
triggered: Boolean
},
/**
* 组件的初始数据
*/
data: {
scrollTop: 0,
},
/**
* 组件的方法列表
*/
methods: {
click(e) {
let {
index,
item
} = e.currentTarget.dataset
item.index = index
this.setData({
scrollTop: 0,
tagIndex: index
})
this.triggerEvent('click', item)
},
tabScrollTolower(e) {
this.triggerEvent('tabScrollTolower')
},
viewScrollTolower(e) {
this.triggerEvent('viewScrollTolower')
},
bindrefresherrefresh(e) {
this.triggerEvent('refresherrefresh')
}
}
})
\ No newline at end of file
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
<view class="tab-box" id="tabView" style="height:calc(100vh - {{height}}px)">
<scroll-view style="height:100%;" scroll-y class="tab" bindscrolltolower="tabScrollTolower">
<view>
<block wx:for="{{tabList}}" wx:key="index">
<view class="tab-item {{tagIndex==index?'active':''}}" bindtap="click" data-item="{{item}}" data-index="{{index}}">
{{item.zoneName}}</view>
</block>
</view>
</scroll-view>
<view class="view">
<view style="height:100%;">
<scroll-view style="height:100%" scroll-y scroll-top="{{scrollTop}}" bindscrolltolower="viewScrollTolower"
refresher-enabled="{{refresherEnabled}}" refresher-triggered="{{triggered}}"
bindrefresherrefresh="bindrefresherrefresh">
<view class="content">
<slot name="content"></slot>
</view>
</scroll-view>
</view>
</view>
</view>
\ No newline at end of file
/* components/tabView/tabView.wxss */
.tab-box{
display: flex;
}
.tab {
width: 21.33%;
box-sizing: border-box;
text-align: center;
background: #F7F8FA ;
}
.view {
width: 78.67%;
height: 100%;
position: relative;
background: #fff;
}
.tab-item {
width: 100%;
height: 120rpx;
line-height: 120rpx;
font-size: 26rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: #707071;
box-sizing: border-box;
padding: 0 10rpx;
transition: all .5s;
background-color: #EFF0F2;
}
.active {
font-weight: 500;
background: #fff;
position: sticky;
top: 0;
color: #2D2D2E;
}
.active::after{
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 8rpx;
background-color: var(--btnColor);
content: '';
animation: show-border .5s forwards;
}@keyframes show-border{
0%{
height: 0;
}
100%{
height: 60rpx;
}
}
.refresherEnabled {
position: relative;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
opacity: 0;
}
.content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
\ No newline at end of file
// components/image/index.js
import {
IMG_URL,
IMG_VERSION
} from '~/utils/constants'
Component({
externalClasses: ['custom-class', 'class'],
/**
* 组件的属性列表
*/
properties: {
src: {
type: String,
value: '',
observer: async function (url, o) {
if (url) {
let isWebp = url.includes('webp')
let checkList = ['https://', 'http://']
let isFullAdd = checkList.map(item => url.includes(item)).some(item => item)
this.setData({
isWebp,
imagePath: `${isFullAdd ? '' : IMG_URL}${url}?v=` + await IMG_VERSION()
})
}
}
},
mode: {
type: String,
value: 'scaleToFill'
},
webp: {
type: Boolean,
value: true
},
alt: {
type: String,
value: ''
},
showMenuByLongpress: Boolean
},
/**
* 组件的初始数据
*/
data: {
imagePath: '',
isWebp: false
},
// 组件生命周期
lifetimes: {
// 在组件实例进入页面节点树时执行
// attached: function () {
// let src = this.data.src
// let prefix = IMG_URL
// this.setData({
// imagePath: `${prefix}${src}?v=` + IMG_VERSION()
// })
// },
// 在组件实例被从页面节点树移除时执行
detached: function () {}
},
/**
* 组件的方法列表
*/
methods: {}
})
\ No newline at end of file
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
<!-- components/image/index.wxml -->
<image src="{{imagePath}}" mode="{{mode}}" webp="{{webp||isWebp}}" alt="{{alt}}" lazy-load class="custom-class class" show-menu-by-longpress="{{showMenuByLongpress}}" />
\ No newline at end of file
/* components/image/index.wxss */
\ No newline at end of file
......@@ -7,6 +7,7 @@ Page({
*/
data: {
navStyle,
showPage:true
},
/**
......
/* pages/tab/index/pages/index/index.wxss */
page {
background-color: #F8F9FC;
}
.home-top {
height: 88rpx;
display: flex;
align-items: center;
padding-left: 30rpx;
}
.flex {
display: flex;
align-items: center;
}
.scroll-bg {
position: absolute;
top: 0;
}
.logo {
z-index: 10;
}
.logo image {
width: 176rpx;
height: 34rpx;
}
.widget-box {
font-size: 20rpx;
margin-left: 26rpx;
color: #fff;
display: flex;
flex-flow: column;
align-items: center;
z-index: 10;
}
.widget-box image {
height: 30rpx;
width: 34rpx;
}
.layout {
padding-bottom: 200rpx;
position: relative;
padding-top: 16rpx;
background: transparent;
}
.bg-box {
width: 100%;
height: 446rpx;
overflow: hidden;
position: absolute;
left: 0;
}
.bg {
width: 100%;
height: 100%;
position: absolute;
z-index: -1;
top: 0;
left: 0;
}
.menu-box {
margin-top: 14rpx;
}
.sticky {
background: #F8F9FC;
padding: 10rpx 0;
}
.back-to-top {
background: #fff;
border-radius: 50%;
position: fixed;
right: 24rpx;
bottom: 245rpx;
width: 60rpx;
height: 60rpx;
z-index: 100;
}
.hidden-top {
animation: hideToTop .5s forwards;
}
.show-top {
animation: showToTop .5s forwards;
}
@keyframes hideToTop {
0% {
transform: translateX(0);
}
100% {
transform: translateX(80rpx);
}
}
@keyframes showToTop {
0% {
transform: translateX(40rpx);
}
100% {
transform: translateX(0);
}
}
.nothing {
flex-direction: column;
font-size: 28rpx;
color: #858A94;
}
.nothing .icon {
width: 320rpx;
height: 320rpx;
margin-bottom: 8rpx;
}
.widget .icon {
width: 100%;
height: 200%;
position: relative;
}
.online-text {
font-size: 16rpx;
color: #2A69FF;
}
.widget-box .flex-box {
position: relative;
display: flex;
border-radius: var(--borderRadius);
padding: 10rpx 20rpx 10rpx 100rpx;
/* background: linear-gradient(201deg, #7BA6FF 0%, #1C72FB 100%); */
box-sizing: border-box;
animation: showFlex .5s forwards;
font-size: 20rpx;
justify-content: space-between;
width: 320rpx;
}
.widget-box .flex-box .view {
opacity: 0;
animation: showView .1s forwards .5s;
}
@keyframes showFlex {
0% {
right: -1000%;
}
100% {
right: 0;
}
}
@keyframes showView {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.split-line {
padding-bottom: 20rpx;
text-align: center;
}
.split-line .split-title {
display: flex;
width: 100%;
justify-content: center;
align-items: center;
font-family: PingFangSC-Medium;
font-weight: 500;
font-size: 16px;
color: #0A0D14;
}
.split-line .split-title .line {
width: 60rpx;
height: 4rpx;
border-radius: 2px;
}
.split-line .split-title .left-line {
background-image: linear-gradient(90deg, rgba(252, 237, 205, 0.00) 0%, #2A69FF 100%);
margin-right: 71rpx;
}
.split-line .split-title .right-line {
background-image: linear-gradient(90deg, #2A69FF 0%, rgba(252, 237, 205, 0.00) 100%);
margin-left: 71rpx;
}
.split-line .split-text {
margin-top: 10rpx;
width: 100%;
font-family: PingFangSC-Regular;
font-size: 12px;
color: #858A94;
}
\ No newline at end of file
<view style="padding-top:200px">
<button bindtap="jump">点击跳转携带参数</button>
<view>{{a}}</view>
<view>{{b}}</view>
</view>
\ No newline at end of file
<block wx:if="{{showPage}}">
<navigation-bar page-title="首页" custom="{{true}}" bindnavbarReady="navbarReady">
<block wx:if="{{IMGURL}}">
<view class="home-top flex">
<view class="logo">
<image webp src="{{IMGURL}}index/home_logo.png" webp></image>
</view>
<view class="widget-box" wx:if="{{showKF}}" bindtap="openKF">
<image webp src="{{IMGURL}}index/icon-kf.png"></image>
<view class="online-text">客服</view>
</view>
</view>
<image class="scroll-bg" webp src="{{IMGURL}}index/navigationBar_bg.png"></image>
</block>
</navigation-bar>
<block wx:if="{{navHeight}}">
<view class="layout" style="top:{{navHeight}}px">
<view class="bg-box" style="height:{{270 + navHeight * 2}}rpx;top:-{{navHeight}}px">
<view class="bg">
<image webp src="{{IMGURL}}index/home-bg.png"></image>
</view>
</view>
<!-- 门店信息 -->
<block>
<view class="store-box">
<store-equity id="com-0"></store-equity>
</view>
</block>
<!-- 菜单 -->
<view class="menu-box">
<menu-list data="{{utilList}}" isLogin="{{userInfo.isLogin}}"></menu-list>
</view>
<!-- 公告 -->
<block wx:if="{{noticeContent}}">
<view class="notice-bar">
<notice-bar data="{{noticeContent}}" speed="7500" id="com-1"></notice-bar>
</view>
</block>
<!-- banner -->
<view class="banner-box" wx:if="{{bannerList.length > 0}}">
<banner bannerList="{{bannerList}}"></banner>
</view>
<view class="split-line" wx:if="{{goodsFlag}}">
<view class="split-title">
<view class="line left-line"></view>
<view class="title">精品推荐</view>
<view class="line right-line"></view>
</view>
<view class="split-text">品质精选,超值低价</view>
</view>
<!-- 商品 -->
<block wx:if="{{goodsFlag}}">
<view wx:if="{{classifyList.length}}">
<view class="goods-box">
<view class="sticky" style="top:{{navHeight}}px;">
<good-tab tab="{{tab}}" align="left" openScroll bindclick="changeTab" index="{{goodsIndex}}"></good-tab>
</view>
<view wx:if="{{tab[goodsIndex]!='特惠精选'}}" class="goods-content">
<block wx:if="{{classifyList.length}}">
<block wx:for="{{classifyList}}" wx:key="index">
<block wx:if="{{index == goodsIndex}}">
<block wx:if="{{item.goodsData}}">
<goods list="{{item.goodsData}}"></goods>
</block>
<block wx:elif="{{item.activityData}}">
<activity nothing="{{nothing}}" list="{{item.activityData}}"></activity>
</block>
</block>
</block>
</block>
</view>
<!-- 平台商品 -->
<view wx:if="{{tab[goodsIndex]=='特惠精选'}}" class="goods-content">
<block wx:if="{{platformGoods.length}}">
<platform-goods list="{{platformGoods}}"></platform-goods>
</block>
</view>
<block wx:if="{{classifyList[goodsIndex].classifyName == '秒杀'}}">
<view class="btn text-center" bindtap="jump" data-url="activity.index">
查看更多
<view class="icon">
<image webp src="{{IMGURL}}index/more.png"></image>
</view>
</view>
</block>
</view>
</view>
<block wx:else>
<view class="nothing flex">
<view class="icon">
<image webp src="{{IMGURL}}index/index-activity-nothing.png"></image>
</view>
暂无优惠活动,敬请期待
</view>
</block>
</block>
<view class="back-to-top {{scrollToTop ? 'show-top': 'hidden-top'}}" bindtap="backTop">
<image webp src="{{IMGURL}}index/back-to-top.png"></image>
</view>
</view>
</block>
<!-- 客服 -->
<customer show="{{widgetStatus}}" customerlist="{{customerlist}}" bindclose="closeCustomer"></customer>
<login show="{{showLogin}}"></login>
</block>
<block wx:else>
<page-loading color="#2A69FF" isFullScreen></page-loading>
</block>
\ No newline at end of file
......@@ -4,29 +4,15 @@ export const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram-tes
// 缓存get方法为空的默认指定值
export const DEFAULT_GET_STORAGEKEY = ['sessionId', 'merchantId', 'userInfo']
// 缓存get方法key的对应才映射值
// export const GET_STORAGE_OBJECTkEY = {
// super: ['sessionId', 'merchantId', 'userInfo']
// }
// 缓存get方法key的对应才映射值
export const STORAGE_OBJECTkEY = {
DEFAULT_GET_STORAGEKEY,
sessionId: 'sessionId',
userInfo: 'userInfo',
system_info: 'systemInfo',
app_title: 'appTitle',
auto_login_object: 'auto_login_object',
wx_user_info: 'wx_user_info',
userPhone: 'userPhone',
firstLogin: 'firstLogin',
authphone: 'authphone',
posterTimer: 'posterTimer',
disLikeRecordFlag: 'disLikeRecordFlag'
system_info: 'system_info',
mock_data: 'mock_data'
}
// 图片版本号
export const IMG_VERSION = () => {
const accountInfo = wx.getAccountInfoSync()
return accountInfo.miniProgram.version || '1.0.0'
export const IMG_VERSION = async () => {
const accountInfo = await util.getMockData()
return accountInfo?.version || Date.now()
}
......@@ -110,5 +110,22 @@ class Request {
const projectName = method.split('.')[2]
return projectName
}
getMock() {
let url = 'https://oss-config.dev.glsx.com.cn/mock/6264ff4760f415276f6dfe62/config'
if (index == 3) url = 'https://oss-config.test.glsx.com.cn/mock/6274e3050da5034a58680aa6/config'
return new Promise(resolve => {
wx.request({
url,
data: {},
method: 'GET',
header: {},
dataType: 'json',
responseType: 'text',
success(response) {
resolve(response.data)
}
})
})
}
}
export default new Request()
// import { commonApi, equityApi } from '../api/api'
// import {
// sopApi,
// commonApi,
// bigdatautilApi,
// equityApi
// } from '../api/api'
import api from '~/utils/request/request'
/**
* 日期格式化
* let time = new Date().format('yyyy-MM-dd hh:mm:ss') //log 2020-07-31 10:00:00
......@@ -135,18 +127,51 @@ const parseString = str => {
return obj
}
/**获取图片版本号 */
const getImgVersion = () => {
return '1.0.0'
/**获取mock数据 */
let mockRequestCount = null,
mockTimer = {},
mockCache = null
const getMockData = async () => {
const MOCKDATA = wx.p.storage.get('mock_data')
try {
if (MOCKDATA && Date.now() - MOCKDATA.createTime < 5 * 60e3) {
return Promise.resolve(MOCKDATA)
} else {
if (!mockRequestCount) {
mockCache = null
mockRequestCount = Date.now()
const data = await api.getMock()
data.createTime = Date.now()
mockCache = data
wx.p.storage.set('mock_data', data)
return Promise.resolve(data)
} else {
const key = Date.now()
return new Promise((resolve) => {
mockTimer[key] = setInterval(() => {
if (mockCache) {
clearInterval(mockTimer[key])
mockRequestCount = null
resolve(mockCache)
}
}, 1e3)
})
}
}
} catch (error) {
if (mockTimer[key]) clearInterval(mockTimer[key])
mockRequestCount = null
return Promise.reject(error)
}
}
const Util = {
getImgVersion,
onReachBottom,
isFullSucreen,
clearObjNull,
throttle,
isEmptyObj,
parseString
parseString,
getMockData
}
export default Util
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!