Browse Source

修改样式兼容微信小程序

master
Gao xiaosong 4 years ago
parent
commit
84e8f3e5d2
  1. 11
      .hbuilderx/launch.json
  2. 31
      components/OrderGoods.vue
  3. 566
      components/tui-button/tui-button.vue
  4. 816
      components/tui-icon/tui-icon.vue
  5. 161
      main.js
  6. 1
      package.json
  7. 11
      pages.json
  8. 92
      pages/activity/GroupDetails/index.vue
  9. 72
      pages/activity/SeckillDetails/index.vue
  10. 302
      store/index.js
  11. 142
      utils/dialog.js
  12. 112
      utils/request.js

11
.hbuilderx/launch.json

@ -0,0 +1,11 @@
{ // launch.json configurations app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/
// launchtypelocalremote, localremote
"version": "0.0",
"configurations": [{
"type": "uniCloud",
"default": {
"launchtype": "remote"
}
}
]
}

31
components/OrderGoods.vue

@ -11,13 +11,9 @@
<view class="name line1">{{ cart.productInfo.storeName }}</view> <view class="name line1">{{ cart.productInfo.storeName }}</view>
<view class="num">x {{ cart.cartNum }}</view> <view class="num">x {{ cart.cartNum }}</view>
</view> </view>
<view <view class="attr line1" v-if="cart.productInfo.attrInfo">{{ cart.productInfo.attrInfo.sku }}</view>
class="attr line1" <view class="money font-color-red">{{ cart.truePrice }}</view>
v-if="cart.productInfo.attrInfo" <view class="evaluate" v-if="evaluate == 3 && cart.isReply == 0" @click="routerGo(cart)">评价</view>
>{{ cart.productInfo.attrInfo.sku }}</view>
<view class="money font-color-red" v-if="!isIntegral">{{ cart.truePrice }}</view>
<view class="money font-color-red" v-if="isIntegral">{{ cart.productInfo.attrInfo.integral }}积分</view>
<view class="evaluate" v-if="evaluate == 3 && cart.isReply==0" @click="routerGo(cart)">评价</view>
</view> </view>
</view> </view>
</view> </view>
@ -25,26 +21,25 @@
</template> </template>
<script> <script>
export default { export default {
name: "OrderGoods", name: 'OrderGoods',
props: { props: {
isIntegral:Boolean,
evaluate: Number, evaluate: Number,
cartInfo: { cartInfo: {
type: Array, type: Array,
default: () => [] default: () => [],
} },
}, },
data: function() { data: function() {
return {}; return {}
}, },
mounted: function() {}, mounted: function() {},
methods: { methods: {
routerGo(cart) { routerGo(cart) {
this.$yrouter.push({ this.$yrouter.push({
path: "/pages/shop/GoodsEvaluate/index", path: '/pages/shop/GoodsEvaluate/index',
query: { id: cart.unique } query: { id: cart.unique },
}); })
} },
} },
}; }
</script> </script>

566
components/tui-button/tui-button.vue

@ -1,517 +1,495 @@
<template> <template>
<button <button class="tui-btn" :class="[plain ? 'tui-' + type + '-outline' : 'tui-btn-' + (type || 'primary'), getDisabledClass(disabled, type, plain), getShapeClass(shape, plain), getShadowClass(type, shadow, plain), bold ? 'tui-text-bold' : '', link ? 'tui-btn__link' : '']" :hover-class="getHoverClass(disabled, type, plain)" :style="{ width: width, height: height, lineHeight: height, fontSize: size + 'rpx', margin: margin }" :loading="loading" :form-type="formType" :open-type="openType" @getuserinfo="bindgetuserinfo" @getphonenumber="bindgetphonenumber" @contact="bindcontact" @error="binderror" :disabled="disabled" @tap="handleClick">
class="tui-btn" <slot></slot>
:class="[ </button>
plain ? 'tui-' + type + '-outline' : 'tui-btn-' + (type || 'primary'),
getDisabledClass(disabled, type, plain),
getShapeClass(shape, plain),
getShadowClass(type, shadow, plain),
bold ? 'tui-text-bold' : '',
link ? 'tui-btn__link' : ''
]"
:hover-class="getHoverClass(disabled, type, plain)"
:style="{ width: width, height: height, lineHeight: height, fontSize: size + 'rpx', margin: margin }"
:loading="loading"
:form-type="formType"
:open-type="openType"
@getuserinfo="bindgetuserinfo"
@getphonenumber="bindgetphonenumber"
@contact="bindcontact"
@error="binderror"
:disabled="disabled"
@tap="handleClick"
>
<slot></slot>
</button>
</template> </template>
<script> <script>
export default { export default {
name: 'tui-button', name: 'tui-button',
behaviors: ['wx://form-field-button'], props: {
props: { // primary, white, danger, warning, green,blue, grayblack,brown,gray-primary,gray-danger,gray-warning,gray-green
// primary, white, danger, warning, green,blue, grayblack,brown,gray-primary,gray-danger,gray-warning,gray-green type: {
type: { type: String,
type: String, default: 'primary',
default: 'primary' },
}, //
// shadow: {
shadow: { type: Boolean,
type: Boolean, default: false,
default: false },
}, // rpx %
// rpx % width: {
width: { type: String,
type: String, default: '100%',
default: '100%' },
}, // rpx
// rpx height: {
height: { type: String,
type: String, default: '96rpx',
default: '96rpx' },
}, // rpx
// rpx size: {
size: { type: Number,
type: Number, default: 32,
default: 32 },
}, bold: {
bold: { type: Boolean,
type: Boolean, default: false,
default: false },
}, margin: {
margin: { type: String,
type: String, default: '0',
default: '0' },
}, // circle(), square()rightAngle()
// circle(), square()rightAngle() shape: {
shape: { type: String,
type: String, default: 'square',
default: 'square' },
}, plain: {
plain: { type: Boolean,
type: Boolean, default: false,
default: false },
}, //linkplain使
//linkplain使 link: {
link: { type: Boolean,
type: Boolean, default: false,
default: false },
}, disabled: {
disabled: { type: Boolean,
type: Boolean, default: false,
default: false },
}, // button
// button disabledGray: {
disabledGray: { type: Boolean,
type: Boolean, default: false,
default: false },
}, loading: {
loading: { type: Boolean,
type: Boolean, default: false,
default: false },
}, formType: {
formType: { type: String,
type: String, default: '',
default: '' },
}, openType: {
openType: { type: String,
type: String, default: '',
default: '' },
}, index: {
index: { type: [Number, String],
type: [Number, String], default: 0,
default: 0 },
}, //200ms
//200ms preventClick: {
preventClick: { type: Boolean,
type: Boolean, default: false,
default: false },
} },
}, data() {
data() { return {
return { time: 0,
time: 0 }
}; },
}, methods: {
methods: { handleClick() {
handleClick() { if (this.disabled) return
if (this.disabled) return; if (this.preventClick) {
if (this.preventClick) { if (new Date().getTime() - this.time <= 200) return
if(new Date().getTime() - this.time <= 200) return; this.time = new Date().getTime()
this.time = new Date().getTime(); setTimeout(() => {
setTimeout(() => { this.time = 0
this.time = 0; }, 200)
}, 200); }
} this.$emit('click', {
this.$emit('click', { index: Number(this.index),
index: Number(this.index) })
}); },
}, bindgetuserinfo({ detail = {} } = {}) {
bindgetuserinfo({ detail = {} } = {}) { this.$emit('getuserinfo', detail)
this.$emit('getuserinfo', detail); },
}, bindcontact({ detail = {} } = {}) {
bindcontact({ detail = {} } = {}) { this.$emit('contact', detail)
this.$emit('contact', detail); },
}, bindgetphonenumber({ detail = {} } = {}) {
bindgetphonenumber({ detail = {} } = {}) { this.$emit('getphonenumber', detail)
this.$emit('getphonenumber', detail); },
}, binderror({ detail = {} } = {}) {
binderror({ detail = {} } = {}) { this.$emit('error', detail)
this.$emit('error', detail); },
}, getShadowClass: function(type, shadow, plain) {
getShadowClass: function(type, shadow, plain) { let className = ''
let className = ''; if (shadow && type != 'white' && !plain) {
if (shadow && type != 'white' && !plain) { className = 'tui-shadow-' + type
className = 'tui-shadow-' + type; }
} return className
return className; },
}, getDisabledClass: function(disabled, type, plain) {
getDisabledClass: function(disabled, type, plain) { let className = ''
let className = ''; if (disabled && type != 'white' && type.indexOf('-') == -1) {
if (disabled && type != 'white' && type.indexOf('-') == -1) { let classVal = this.disabledGray ? 'tui-gray-disabled' : 'tui-dark-disabled'
let classVal = this.disabledGray ? 'tui-gray-disabled' : 'tui-dark-disabled'; className = plain ? 'tui-dark-disabled-outline' : classVal
className = plain ? 'tui-dark-disabled-outline' : classVal; }
} return className
return className; },
}, getShapeClass: function(shape, plain) {
getShapeClass: function(shape, plain) { let className = ''
let className = ''; if (shape == 'circle') {
if (shape == 'circle') { className = plain ? 'tui-outline-fillet' : 'tui-fillet'
className = plain ? 'tui-outline-fillet' : 'tui-fillet'; } else if (shape == 'rightAngle') {
} else if (shape == 'rightAngle') { className = plain ? 'tui-outline-rightAngle' : 'tui-rightAngle'
className = plain ? 'tui-outline-rightAngle' : 'tui-rightAngle'; }
} return className
return className; },
}, getHoverClass: function(disabled, type, plain) {
getHoverClass: function(disabled, type, plain) { let className = ''
let className = ''; if (!disabled) {
if (!disabled) { className = plain ? 'tui-outline-hover' : 'tui-' + (type || 'primary') + '-hover'
className = plain ? 'tui-outline-hover' : 'tui-' + (type || 'primary') + '-hover'; }
} return className
return className; },
} },
} }
};
</script> </script>
<style scoped> <style scoped>
.tui-btn-primary { .tui-btn-primary {
background: #5677fc !important; background: #5677fc !important;
color: #fff; color: #fff;
} }
.tui-shadow-primary { .tui-shadow-primary {
box-shadow: 0 10rpx 14rpx 0 rgba(86, 119, 252, 0.2); box-shadow: 0 10rpx 14rpx 0 rgba(86, 119, 252, 0.2);
} }
.tui-btn-danger { .tui-btn-danger {
background: #eb0909 !important; background: #eb0909 !important;
color: #fff; color: #fff;
} }
.tui-shadow-danger { .tui-shadow-danger {
box-shadow: 0 10rpx 14rpx 0 rgba(235, 9, 9, 0.2); box-shadow: 0 10rpx 14rpx 0 rgba(235, 9, 9, 0.2);
} }
.tui-btn-warning { .tui-btn-warning {
background: #fc872d !important; background: #fc872d !important;
color: #fff; color: #fff;
} }
.tui-shadow-warning { .tui-shadow-warning {
box-shadow: 0 10rpx 14rpx 0 rgba(252, 135, 45, 0.2); box-shadow: 0 10rpx 14rpx 0 rgba(252, 135, 45, 0.2);
} }
.tui-btn-green { .tui-btn-green {
background: #07c160 !important; background: #07c160 !important;
color: #fff; color: #fff;
} }
.tui-shadow-green { .tui-shadow-green {
box-shadow: 0 10rpx 14rpx 0 rgba(7, 193, 96, 0.2); box-shadow: 0 10rpx 14rpx 0 rgba(7, 193, 96, 0.2);
} }
.tui-btn-blue { .tui-btn-blue {
background: #007aff !important; background: #007aff !important;
color: #fff; color: #fff;
} }
.tui-shadow-blue { .tui-shadow-blue {
box-shadow: 0 10rpx 14rpx 0 rgba(0, 122, 255, 0.2); box-shadow: 0 10rpx 14rpx 0 rgba(0, 122, 255, 0.2);
} }
.tui-btn-white { .tui-btn-white {
background: #fff !important; background: #fff !important;
color: #333 !important; color: #333 !important;
} }
.tui-btn-gray { .tui-btn-gray {
background: #bfbfbf !important; background: #bfbfbf !important;
color: #fff !important; color: #fff !important;
} }
.tui-btn-black { .tui-btn-black {
background: #333 !important; background: #333 !important;
color: #fff !important; color: #fff !important;
} }
.tui-btn-brown{ .tui-btn-brown {
background: #ac9157 !important; background: #ac9157 !important;
color: #fff !important; color: #fff !important;
} }
.tui-btn-gray-black { .tui-btn-gray-black {
background: #f2f2f2 !important; background: #f2f2f2 !important;
color: #333; color: #333;
} }
.tui-btn-gray-primary { .tui-btn-gray-primary {
background: #f2f2f2 !important; background: #f2f2f2 !important;
color: #5677fc !important; color: #5677fc !important;
} }
.tui-gray-primary-hover { .tui-gray-primary-hover {
background: #d9d9d9 !important; background: #d9d9d9 !important;
} }
.tui-btn-gray-green { .tui-btn-gray-green {
background: #f2f2f2 !important; background: #f2f2f2 !important;
color: #07c160 !important; color: #07c160 !important;
} }
.tui-gray-green-hover { .tui-gray-green-hover {
background: #d9d9d9 !important; background: #d9d9d9 !important;
} }
.tui-btn-gray-danger { .tui-btn-gray-danger {
background: #f2f2f2 !important; background: #f2f2f2 !important;
color: #eb0909 !important; color: #eb0909 !important;
} }
.tui-gray-danger-hover { .tui-gray-danger-hover {
background: #d9d9d9 !important; background: #d9d9d9 !important;
} }
.tui-btn-gray-warning { .tui-btn-gray-warning {
background: #f2f2f2 !important; background: #f2f2f2 !important;
color: #fc872d !important; color: #fc872d !important;
} }
.tui-gray-warning-hover { .tui-gray-warning-hover {
background: #d9d9d9 !important; background: #d9d9d9 !important;
} }
.tui-shadow-gray { .tui-shadow-gray {
box-shadow: 0 10rpx 14rpx 0 rgba(191, 191, 191, 0.2); box-shadow: 0 10rpx 14rpx 0 rgba(191, 191, 191, 0.2);
} }
.tui-hover-gray { .tui-hover-gray {
background: #f7f7f9 !important; background: #f7f7f9 !important;
} }
.tui-black-hover { .tui-black-hover {
background: #555 !important; background: #555 !important;
color: #e5e5e5 !important; color: #e5e5e5 !important;
} }
.tui-brown-hover{ .tui-brown-hover {
background: #A37F49 !important; background: #a37f49 !important;
color: #e5e5e5 !important; color: #e5e5e5 !important;
} }
/* button start*/ /* button start*/
.tui-btn { .tui-btn {
width: 100%; width: 100%;
position: relative; position: relative;
border: 0 !important; border: 0 !important;
border-radius: 6rpx; border-radius: 6rpx;
padding-left: 0; padding-left: 0;
padding-right: 0; padding-right: 0;
overflow: visible; overflow: visible;
} }
.tui-btn::after { .tui-btn::after {
content: ''; content: '';
position: absolute; position: absolute;
width: 200%; width: 200%;
height: 200%; height: 200%;
transform-origin: 0 0; transform-origin: 0 0;
transform: scale(0.5, 0.5) translateZ(0); transform: scale(0.5, 0.5) translateZ(0);
box-sizing: border-box; box-sizing: border-box;
left: 0; left: 0;
top: 0; top: 0;
border-radius: 12rpx; border-radius: 12rpx;
border: 0; border: 0;
} }
.tui-text-bold { .tui-text-bold {
font-weight: bold; font-weight: bold;
} }
.tui-btn-white::after { .tui-btn-white::after {
border: 1px solid #bfbfbf; border: 1px solid #bfbfbf;
} }
.tui-white-hover { .tui-white-hover {
background: #e5e5e5 !important; background: #e5e5e5 !important;
color: #2e2e2e !important; color: #2e2e2e !important;
} }
.tui-dark-disabled { .tui-dark-disabled {
opacity: 0.6 !important; opacity: 0.6 !important;
color: #fafbfc !important; color: #fafbfc !important;
} }
.tui-dark-disabled-outline { .tui-dark-disabled-outline {
opacity: 0.5 !important; opacity: 0.5 !important;
} }
.tui-gray-disabled { .tui-gray-disabled {
background: #f3f3f3 !important; background: #f3f3f3 !important;
color: #919191 !important; color: #919191 !important;
box-shadow: none; box-shadow: none;
} }
.tui-outline-hover { .tui-outline-hover {
opacity: 0.5; opacity: 0.5;
} }
.tui-primary-hover { .tui-primary-hover {
background: #4a67d6 !important; background: #4a67d6 !important;
color: #e5e5e5 !important; color: #e5e5e5 !important;
} }
.tui-primary-outline::after { .tui-primary-outline::after {
border: 1px solid #5677fc !important; border: 1px solid #5677fc !important;
} }
.tui-primary-outline { .tui-primary-outline {
color: #5677fc !important; color: #5677fc !important;
background: transparent; background: transparent;
} }
.tui-danger-hover { .tui-danger-hover {
background: #c80808 !important; background: #c80808 !important;
color: #e5e5e5 !important; color: #e5e5e5 !important;
} }
.tui-danger-outline { .tui-danger-outline {
color: #eb0909 !important; color: #eb0909 !important;
background: transparent; background: transparent;
} }
.tui-danger-outline::after { .tui-danger-outline::after {
border: 1px solid #eb0909 !important; border: 1px solid #eb0909 !important;
} }
.tui-warning-hover { .tui-warning-hover {
background: #d67326 !important; background: #d67326 !important;
color: #e5e5e5 !important; color: #e5e5e5 !important;
} }
.tui-warning-outline { .tui-warning-outline {
color: #fc872d !important; color: #fc872d !important;
background: transparent; background: transparent;
} }
.tui-warning-outline::after { .tui-warning-outline::after {
border: 1px solid #fc872d !important; border: 1px solid #fc872d !important;
} }
.tui-green-hover { .tui-green-hover {
background: #06ad56 !important; background: #06ad56 !important;
color: #e5e5e5 !important; color: #e5e5e5 !important;
} }
.tui-green-outline { .tui-green-outline {
color: #07c160 !important; color: #07c160 !important;
background: transparent; background: transparent;
} }
.tui-green-outline::after { .tui-green-outline::after {
border: 1px solid #07c160 !important; border: 1px solid #07c160 !important;
} }
.tui-blue-hover { .tui-blue-hover {
background: #0062cc !important; background: #0062cc !important;
color: #e5e5e5 !important; color: #e5e5e5 !important;
} }
.tui-blue-outline { .tui-blue-outline {
color: #007aff !important; color: #007aff !important;
background: transparent; background: transparent;
} }
.tui-blue-outline::after { .tui-blue-outline::after {
border: 1px solid #007aff !important; border: 1px solid #007aff !important;
} }
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
.tui-btn-gradual { .tui-btn-gradual {
background: linear-gradient(90deg, rgb(255, 89, 38), rgb(240, 14, 44)) !important; background: linear-gradient(90deg, rgb(255, 89, 38), rgb(240, 14, 44)) !important;
color: #fff !important; color: #fff !important;
} }
.tui-shadow-gradual { .tui-shadow-gradual {
box-shadow: 0 10rpx 14rpx 0 rgba(235, 9, 9, 0.15); box-shadow: 0 10rpx 14rpx 0 rgba(235, 9, 9, 0.15);
} }
/* #endif */ /* #endif */
.tui-gray-hover { .tui-gray-hover {
background: #a3a3a3 !important; background: #a3a3a3 !important;
color: #898989; color: #898989;
} }
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
.tui-gradual-hover { .tui-gradual-hover {
background: linear-gradient(90deg, #d74620, #cd1225) !important; background: linear-gradient(90deg, #d74620, #cd1225) !important;
color: #fff !important; color: #fff !important;
} }
/* #endif */ /* #endif */
.tui-gray-outline { .tui-gray-outline {
color: #999 !important; color: #999 !important;
background: transparent !important; background: transparent !important;
} }
.tui-white-outline { .tui-white-outline {
color: #fff !important; color: #fff !important;
background: transparent !important; background: transparent !important;
} }
.tui-black-outline { .tui-black-outline {
background: transparent !important; background: transparent !important;
color: #333 !important; color: #333 !important;
} }
.tui-gray-outline::after { .tui-gray-outline::after {
border: 1px solid #ccc !important; border: 1px solid #ccc !important;
} }
.tui-white-outline::after { .tui-white-outline::after {
border: 1px solid #fff !important; border: 1px solid #fff !important;
} }
.tui-black-outline::after { .tui-black-outline::after {
border: 1px solid #333 !important; border: 1px solid #333 !important;
} }
.tui-brown-outline { .tui-brown-outline {
color: #ac9157 !important; color: #ac9157 !important;
background: transparent; background: transparent;
} }
.tui-brown-outline::after { .tui-brown-outline::after {
border: 1px solid #ac9157 !important; border: 1px solid #ac9157 !important;
} }
/*圆角 */ /*圆角 */
.tui-fillet { .tui-fillet {
border-radius: 50rpx; border-radius: 50rpx;
} }
.tui-btn-white.tui-fillet::after { .tui-btn-white.tui-fillet::after {
border-radius: 98rpx; border-radius: 98rpx;
} }
.tui-outline-fillet::after { .tui-outline-fillet::after {
border-radius: 98rpx; border-radius: 98rpx;
} }
/*平角*/ /*平角*/
.tui-rightAngle { .tui-rightAngle {
border-radius: 0; border-radius: 0;
} }
.tui-btn-white.tui-rightAngle::after { .tui-btn-white.tui-rightAngle::after {
border-radius: 0; border-radius: 0;
} }
.tui-outline-rightAngle::after { .tui-outline-rightAngle::after {
border-radius: 0; border-radius: 0;
} }
.tui-btn__link::after { .tui-btn__link::after {
border: 0 !important; border: 0 !important;
} }
</style> </style>

816
components/tui-icon/tui-icon.vue

File diff suppressed because one or more lines are too long

161
main.js

@ -2,41 +2,21 @@ import Vue from 'vue'
import App from './App' import App from './App'
// import router from "./router"; // import router from "./router";
import store from "./store"; import store from './store'
import schema from "async-validator"; import schema from 'async-validator'
import dialog from "./utils/dialog"; import dialog from './utils/dialog'
import cookie from "@/utils/store/cookie"; import cookie from '@/utils/store/cookie'
import cuCustom from '@/components/colorui/components/cu-custom.vue' import cuCustom from '@/components/colorui/components/cu-custom.vue'
// // import "@/assets/iconfont/iconfont";
// import "@/assets/iconfont/iconfont.css"; import { parseRoute, _router, parseQuery } from '@/utils'
// // import "@/assets/js/media_750"; import { VUE_APP_RESOURCES_URL, VUE_APP_API_URL } from '@/config'
// // import "vue-ydui/dist/ydui.base.css"; Vue.component('cu-custom', cuCustom)
// import "@/assets/css/base.less"; Vue.config.productionTip = false
// import "@/assets/css/reset.less"; Vue.config.devtools = process.env.NODE_ENV !== 'production'
// import "@/assets/css/style.less";
Vue.prototype.$validator = function(rule) {
// // 引入微信jssdk return new schema(rule)
// var jweixin = require('jweixin-module') }
// jweixin.ready(function(){
// // TODO
// });
import {
parseRoute,
_router,
parseQuery
} from "@/utils";
import {
VUE_APP_RESOURCES_URL,
VUE_APP_API_URL
} from "@/config";
Vue.component('cu-custom', cuCustom);
Vue.config.productionTip = false;
Vue.config.devtools = process.env.NODE_ENV !== "production";
Vue.prototype.$validator = function (rule) {
return new schema(rule);
};
Vue.config.productionTip = false Vue.config.productionTip = false
App.mpType = 'app' App.mpType = 'app'
@ -45,36 +25,33 @@ Vue.prototype.$store = store
const app = new Vue(App) const app = new Vue(App)
Vue.mixin({ Vue.mixin({
onLoad() { onLoad() {
const { const { $mp } = this.$root
$mp this._route = parseRoute($mp)
} = this.$root // this.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL;
this._route = parseRoute($mp) this._data.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL
// this.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL; },
this._data.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL; onShow() {
}, _router.app = this
onShow() { _router.currentRoute = this._route
_router.app = this },
_router.currentRoute = this._route
}
}) })
Object.defineProperty(Vue.prototype, '$yrouter', { Object.defineProperty(Vue.prototype, '$yrouter', {
get() { get() {
return _router return _router
} },
}) })
Object.defineProperty(Vue.prototype, '$yroute', { Object.defineProperty(Vue.prototype, '$yroute', {
get() { get() {
return this._route return this._route
} },
}) })
Vue.prototype.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL Vue.prototype.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL
Vue.prototype.$VUE_APP_API_URL = VUE_APP_API_URL Vue.prototype.$VUE_APP_API_URL = VUE_APP_API_URL
Vue.component('cu-custom', cuCustom); Vue.component('cu-custom', cuCustom)
// #ifdef APP-PLUS // #ifdef APP-PLUS
// App平台编译的代码 // App平台编译的代码
@ -96,69 +73,49 @@ store.commit('updateDevicetype', 'routine')
// ...mapState(['$deviceType']) // ...mapState(['$deviceType'])
// }, // },
// #ifdef H5 // #ifdef H5
// H5编译的代码 // H5编译的代码
import { import { wechat, clearAuthStatus, oAuth, auth, toAuth, pay, openAddress, openShareAll, openShareAppMessage, openShareTimeline, wechatEvevt, ready, wxShowLocation } from '@/libs/wechat'
wechat,
clearAuthStatus,
oAuth,
auth,
toAuth,
pay,
openAddress,
openShareAll,
openShareAppMessage,
openShareTimeline,
wechatEvevt,
ready,
wxShowLocation,
} from '@/libs/wechat'
import { isWeixin } from '@/utils' import { isWeixin } from '@/utils'
const CACHE_KEY = "clear_0.0.1"; const CACHE_KEY = 'clear_0.0.1'
if (!cookie.has(CACHE_KEY)) { if (!cookie.has(CACHE_KEY)) {
cookie.clearAll() cookie.clearAll()
cookie.set(CACHE_KEY, 1); cookie.set(CACHE_KEY, 1)
} }
var urlSpread = parseQuery()["spread"]; var urlSpread = parseQuery()['spread']
if (urlSpread) { if (urlSpread) {
cookie.set("spread", urlSpread); cookie.set('spread', urlSpread)
} }
// #endif // #endif
async function init() { async function init() {
// #ifdef H5
// #ifdef H5 // H5编译的代码
// H5编译的代码 // 判断是否是微信浏览器
// 判断是否是微信浏览器 if (isWeixin()) {
if (isWeixin()) { Vue.prototype.$deviceType = 'weixin'
Vue.prototype.$deviceType = 'weixin' store.commit('updateDevicetype', 'weixin')
store.commit('updateDevicetype', 'weixin') let wechatInit = await wechat()
let wechatInit = await wechat() console.log(wechatInit)
console.log(wechatInit) if (wechatInit) {
if (wechatInit) { await oAuth()
await oAuth() app.$mount()
app.$mount() }
} } else {
} else { Vue.prototype.$deviceType = 'weixinh5'
Vue.prototype.$deviceType = 'weixinh5' store.commit('updateDevicetype', 'weixinh5')
store.commit('updateDevicetype', 'weixinh5') app.$mount()
app.$mount() }
// #endif
}
// #endif // #ifndef H5
app.$mount()
// #ifndef H5 // #endif
app.$mount()
// #endif
} }
init() init()

1
package.json

@ -15,7 +15,6 @@
"dayjs": "^1.8.22", "dayjs": "^1.8.22",
"jweixin-module": "^1.6.0", "jweixin-module": "^1.6.0",
"miniapp-color-thief": "^1.0.5", "miniapp-color-thief": "^1.0.5",
"vue-ydui": "^1.2.6",
"vconsole": "^3.3.4", "vconsole": "^3.3.4",
"wechat-jssdk": "^5.0.4" "wechat-jssdk": "^5.0.4"
}, },

11
pages.json

@ -41,7 +41,6 @@
"style": { "style": {
"navigationBarTitleText": "yshop商城", "navigationBarTitleText": "yshop商城",
"navigationBarTextStyle": "white", "navigationBarTextStyle": "white",
// "enablePullDownRefresh": true,
"navigationStyle": "custom" "navigationStyle": "custom"
} }
}, },
@ -425,11 +424,11 @@
} }
], ],
"easycom": { "easycom": {
"autoscan": true, "autoscan": true,
"custom": { "custom": {
"tui-(.*)": "@/components/tui-$1/tui-$1.vue" "tui-(.*)": "@/components/tui-$1/tui-$1.vue"
} }
}, },
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",
"navigationBarTitleText": "Yshop", "navigationBarTitleText": "Yshop",

92
pages/activity/GroupDetails/index.vue

@ -10,17 +10,17 @@
<view class="tui-pro-price"> <view class="tui-pro-price">
<view> <view>
<text></text> <text></text>
<text class="tui-price">{{ storeInfo.price.split('.')[0] }}</text> <text class="tui-price">{{ formatPrice(storeInfo.price, 0) }}</text>
<text>.{{ storeInfo.price.split('.')[1] }}</text> <text>.{{ formatPrice(storeInfo.price, 1) }}</text>
</view> </view>
<!-- <view class="tui-original-price tui-white__gray">199.00</view> --> <!-- <view class="tui-original-price tui-white__gray">199.00</view> -->
</view> </view>
<view class="tui-sold tui-white__gray"> <view class="tui-sold tui-white__gray">
<view class="tui-price-tag">{{ storeInfo.people }}人团</view> <view class="tui-price-tag">{{ storeInfo.people }}人团</view>
<text>已拼{{ storeInfo.sales }}{{ storeInfo.unitNam }}</text> <text>已拼{{ storeInfo.sales }}{{ storeInfo.unitName }}</text>
</view> </view>
</view> </view>
<view class="tui-right__box">库存{{ storeInfo.stock }}{{ storeInfo.unitNam }}</view> <view class="tui-right__box">库存{{ storeInfo.stock }}{{ storeInfo.unitName }}</view>
</view> </view>
<view class="tui-pro-titbox"> <view class="tui-pro-titbox">
<view class="tui-pro-title">{{ storeInfo.title }}</view> <view class="tui-pro-title">{{ storeInfo.title }}</view>
@ -130,7 +130,7 @@
<view class="tui-operation-left tui-col-5"> <view class="tui-operation-left tui-col-5">
<!-- #ifdef MP-WEIXIN --> <!-- #ifdef MP-WEIXIN -->
<button class="tui-operation-item" hover-class="tui-opcity" :hover-stay-time="150"> <button class="tui-operation-item" hover-class="tui-opcity" :hover-stay-time="150">
<tui-icon name="kefu" :size="22" color="#333"></tui-icon> <view class="iconfont icon-kefu"></view>
<view class="tui-operation-text tui-scale-small">客服</view> <view class="tui-operation-text tui-scale-small">客服</view>
</button> </button>
<!-- #endif --> <!-- #endif -->
@ -152,8 +152,8 @@
<view>单独购买</view> <view>单独购买</view>
<view class="tui-flex-end"> <view class="tui-flex-end">
<view class="tui-size-26"></view> <view class="tui-size-26"></view>
<view class="tui-size-36">{{ storeInfo.productPrice.split('.')[0] }}</view> <view class="tui-size-36">{{ formatPrice(storeInfo.productPrice, 0) }}</view>
<view class="tui-size-26">.{{ storeInfo.productPrice.split('.')[1] }}</view> <view class="tui-size-26">.{{ formatPrice(storeInfo.productPrice, 1) }}</view>
</view> </view>
</view> </view>
</tui-button> </tui-button>
@ -164,8 +164,8 @@
<view>发起拼团</view> <view>发起拼团</view>
<view class="tui-flex-end"> <view class="tui-flex-end">
<view class="tui-size-28"></view> <view class="tui-size-28"></view>
<view class="tui-price-large tui-size-36">{{ storeInfo.price.split('.')[0] }}</view> <view class="tui-price-large tui-size-36">{{ formatPrice(storeInfo.price, 0) }}</view>
<view class="tui-size-28">.{{ storeInfo.price.split('.')[1] }}</view> <view class="tui-size-28">.{{ formatPrice(storeInfo.price, 1) }}</view>
</view> </view>
</view> </view>
</tui-button> </tui-button>
@ -205,7 +205,7 @@ export default {
StorePoster, StorePoster,
}, },
props: {}, props: {},
data: function () { data: function() {
return { return {
domStatus: false, domStatus: false,
posterData: { posterData: {
@ -246,19 +246,27 @@ export default {
userCollect: false, userCollect: false,
} }
}, },
computed: {},
watch: { watch: {
$yroute: function (n) { $yroute: function(n) {
var that = this var that = this
if (n.name === NAME) { if (n.name === NAME) {
that.mountedStart() that.mountedStart()
} }
}, },
}, },
onShow: function () { onShow: function() {
this.mountedStart() this.mountedStart()
}, },
methods: { methods: {
onShareAppMessage: function () { formatPrice(price, index) {
console.log(price)
if (price) {
return price.split('.')[index]
}
return ''
},
onShareAppMessage: function() {
return { return {
title: this.storeInfo.title, title: this.storeInfo.title,
imageUrl: this.storeInfo.image, imageUrl: this.storeInfo.image,
@ -276,7 +284,7 @@ export default {
}, },
} }
}, },
openAlone: function () { openAlone: function() {
this.$yrouter.push({ this.$yrouter.push({
path: '/pages/shop/GoodsCon/index', path: '/pages/shop/GoodsCon/index',
query: { query: {
@ -286,21 +294,21 @@ export default {
// this.$yrouter.replace({ path: "/detail/" + this.storeInfo.productId }); // this.$yrouter.replace({ path: "/detail/" + this.storeInfo.productId });
}, },
// //
setCollect: function () { setCollect: function() {
let that = this, let that = this,
id = that.storeInfo.id, id = that.storeInfo.id,
category = 'product' category = 'product'
if (that.userCollect) { if (that.userCollect) {
getCollectDel(id, category).then(function () { getCollectDel(id, category).then(function() {
that.userCollect = !that.userCollect that.userCollect = !that.userCollect
}) })
} else { } else {
getCollectAdd(id, category).then(function () { getCollectAdd(id, category).then(function() {
that.userCollect = !that.userCollect that.userCollect = !that.userCollect
}) })
} }
}, },
mountedStart: function () { mountedStart: function() {
var that = this var that = this
let id = that.$yroute.query.id let id = that.$yroute.query.id
getCombinationDetail(id).then(res => { getCombinationDetail(id).then(res => {
@ -328,7 +336,7 @@ export default {
that.DefaultSelect() that.DefaultSelect()
}) })
}, },
DefaultSelect: function () { DefaultSelect: function() {
let productAttr = this.attr.productAttr let productAttr = this.attr.productAttr
let value = [] let value = []
for (let i = 0; i < productAttr.length; i++) { for (let i = 0; i < productAttr.length; i++) {
@ -367,19 +375,19 @@ export default {
this.$set(this, 'attrTxt', '请选择') this.$set(this, 'attrTxt', '请选择')
} }
}, },
getImageBase64: function () { getImageBase64: function() {
let that = this let that = this
imageBase64(this.posterData.image, that.posterData.code).then(res => { imageBase64(this.posterData.image, that.posterData.code).then(res => {
that.posterData.image = res.data.image that.posterData.image = res.data.image
that.posterData.code = res.data.code that.posterData.code = res.data.code
}) })
}, },
setPosterImageStatus: function () { setPosterImageStatus: function() {
// var sTop = document.body || document.documentElement; // var sTop = document.body || document.documentElement;
// sTop.scrollTop = 0; // sTop.scrollTop = 0;
this.posterImageStatus = !this.posterImageStatus this.posterImageStatus = !this.posterImageStatus
}, },
groupRule: function (id) { groupRule: function(id) {
var that = this var that = this
that.$yrouter.push({ that.$yrouter.push({
path: '/pages/activity/GroupRule/index', path: '/pages/activity/GroupRule/index',
@ -388,7 +396,7 @@ export default {
}, },
}) })
}, },
goReply: function () { goReply: function() {
var that = this var that = this
that.$yrouter.push({ that.$yrouter.push({
path: '/pages/shop/EvaluateList/index', path: '/pages/shop/EvaluateList/index',
@ -397,21 +405,21 @@ export default {
}, },
}) })
}, },
setGroupListCount: function () { setGroupListCount: function() {
this.groupListCount = this.groupListCount + 2 this.groupListCount = this.groupListCount + 2
}, },
// //
changeFun: function (opt) { changeFun: function(opt) {
if (typeof opt !== 'object') opt = {} if (typeof opt !== 'object') opt = {}
let action = opt.action || '' let action = opt.action || ''
let value = opt.value === undefined ? '' : opt.value let value = opt.value === undefined ? '' : opt.value
this[action] && this[action](value) this[action] && this[action](value)
}, },
changeattr: function (res) { changeattr: function(res) {
var that = this var that = this
that.attr.cartAttr = res that.attr.cartAttr = res
}, },
ChangeCartNum: function (res) { ChangeCartNum: function(res) {
var that = this var that = this
that.attr.productSelect.cart_num = 1 that.attr.productSelect.cart_num = 1
that.cartNum = 1 that.cartNum = 1
@ -422,7 +430,7 @@ export default {
}) })
}, },
// //
ChangeAttr: function (res) { ChangeAttr: function(res) {
// //
let productSelect = this.productValue[res.value] let productSelect = this.productValue[res.value]
if (productSelect) { if (productSelect) {
@ -445,7 +453,7 @@ export default {
} }
}, },
openTeam: function () { openTeam: function() {
var that = this var that = this
if (that.attr.cartAttr == false) { if (that.attr.cartAttr == false) {
that.attr.cartAttr = !this.attr.cartAttr that.attr.cartAttr = !this.attr.cartAttr
@ -475,7 +483,7 @@ export default {
} }
}, },
// //
selecAttrTap: function () { selecAttrTap: function() {
this.attr.cartAttr = true this.attr.cartAttr = true
this.isOpen = true this.isOpen = true
}, },
@ -994,6 +1002,18 @@ export default {
justify-content: center; justify-content: center;
flex-direction: column; flex-direction: column;
position: relative; position: relative;
background: none;
padding: 0;
border: 0;
line-height: 1em;
&:after {
display: none;
}
.tui-operation-text {
margin-top: 9rpx;
line-height: 1em;
}
} }
.tui-operation-text { .tui-operation-text {
@ -1052,18 +1072,6 @@ export default {
bottom: 0; bottom: 0;
} }
/* .tui-popup-btn .tui-btn-class {
width: 90% !important;
display: block !important;
font-size: 28rpx !important;
} */
/* .tui-icon-close {
position: absolute;
top: 30rpx;
right: 30rpx;
} */
.tui-product-box { .tui-product-box {
display: flex; display: flex;
align-items: flex-end; align-items: flex-end;

72
pages/activity/SeckillDetails/index.vue

@ -9,8 +9,8 @@
<view class="tui-pro-price"> <view class="tui-pro-price">
<view> <view>
<text></text> <text></text>
<text class="tui-price">{{ storeInfo.price.split('.')[0] }}</text> <text class="tui-price">{{ formatPrice(storeInfo.price, 0) }}</text>
<text>.{{ storeInfo.price.split('.')[1] }}</text> <text>.{{ formatPrice(storeInfo.price, 1) }}</text>
</view> </view>
<view class="tui-original-price tui-white__gray" v-text="'¥' + storeInfo.price"></view> <view class="tui-original-price tui-white__gray" v-text="'¥' + storeInfo.price"></view>
</view> </view>
@ -28,17 +28,8 @@
</view> </view>
<view class="tui-pro-titbox"> <view class="tui-pro-titbox">
<view class="tui-pro-title">{{ storeInfo.title }}</view> <view class="tui-pro-title">{{ storeInfo.title }}</view>
<!-- <button open-type="share" class="tui-share-btn tui-share-position" @tap="onShare">
<tui-tag type="gray" shape="circleLeft" padding="12rpx 16rpx">
<view class="tui-share-box">
<tui-icon name="partake" color="#999" :size="15"></tui-icon>
<text class="tui-share-text tui-gray tui-size">分享</text>
</view>
</tui-tag>
</button> -->
</view> </view>
<view class="tui-padding"> <view class="tui-padding">
<!-- <view class="tui-sub-title tui-size tui-gray">此商品将于2019-06-28,10点结束闪购特卖时尚美饰联合专场</view> -->
<view class="tui-sale-info tui-size tui-gray"> <view class="tui-sale-info tui-size tui-gray">
<view>库存{{ storeInfo.stock }}</view> <view>库存{{ storeInfo.stock }}</view>
<view>月销{{ storeInfo.sales }}</view> <view>月销{{ storeInfo.sales }}</view>
@ -62,14 +53,13 @@
<!-- 操作栏 --> <!-- 操作栏 -->
<view style="height: 100rpx"></view> <view style="height: 100rpx"></view>
<!--底部操作栏--> <!--底部操作栏-->
<view class="tui-operation"> <view class="tui-operation">
<view class="tui-operation-left tui-col-5"> <view class="tui-operation-left tui-col-5">
<!-- #ifdef MP-WEIXIN --> <!-- #ifdef MP-WEIXIN -->
<button class="tui-operation-item" hover-class="tui-opcity" :hover-stay-time="150"> <button class="tui-operation-item" hover-class="tui-opcity" :hover-stay-time="150">
<tui-icon name="kefu" :size="22" color="#333"></tui-icon> <view class="iconfont icon-kefu"></view>
<view class="tui-operation-text tui-scale-small">客服</view> <view class="tui-operation-text tui-scale-small">客服</view>
</button> </button>
<!-- #endif --> <!-- #endif -->
@ -83,7 +73,7 @@
<view class="tui-operation-text tui-scale-small">收藏</view> <view class="tui-operation-text tui-scale-small">收藏</view>
</view> </view>
</view> </view>
<view class="tui-operation-right tui-right-flex tui-col-7 tui-btnbox-4" v-if="seckillStatus == 1 && storeInfo.num > 0 && storeInfo.stock > 0"> <view class="tui-operation-right tui-right-flex tui-col-7 tui-btnbox-4" v-if="seckillStatus == 1 && storeInfo.num > 0 && storeInfo.stock > 0">
<view class="tui-flex-1"> <view class="tui-flex-1">
<tui-button height="68rpx" :size="26" type="warning" shape="circle" @click="openAlone">单独购买</tui-button> <tui-button height="68rpx" :size="26" type="warning" shape="circle" @click="openAlone">单独购买</tui-button>
@ -117,7 +107,7 @@
</view> </view>
</view> </view>
</view> </view>
<ProductWindow v-on:changeFun="changeFun" :attr="attr" :cartNum="cartNum"></ProductWindow> <ProductWindow v-on:changeFun="changeFun" :attr="attr" :cartNum="cartNum"></ProductWindow>
<StorePoster v-on:setPosterImageStatus="setPosterImageStatus" :posterImageStatus="posterImageStatus" :posterData="posterData"></StorePoster> <StorePoster v-on:setPosterImageStatus="setPosterImageStatus" :posterImageStatus="posterImageStatus" :posterData="posterData"></StorePoster>
</view> </view>
@ -148,7 +138,7 @@ export default {
StorePoster, StorePoster,
}, },
props: {}, props: {},
data: function () { data: function() {
return { return {
seckillStatus: '', seckillStatus: '',
domStatus: false, domStatus: false,
@ -177,11 +167,18 @@ export default {
userCollect: false, userCollect: false,
} }
}, },
onShow: function () { onShow: function() {
this.mountedStart() this.mountedStart()
}, },
methods: { methods: {
onShareAppMessage: function () { formatPrice(price, index) {
console.log(price)
if (price) {
return price.split('.')[index]
}
return ''
},
onShareAppMessage: function() {
return { return {
title: this.storeInfo.title, title: this.storeInfo.title,
imageUrl: this.storeInfo.image, imageUrl: this.storeInfo.image,
@ -199,7 +196,7 @@ export default {
}, },
} }
}, },
openAlone: function () { openAlone: function() {
this.$yrouter.push({ this.$yrouter.push({
path: '/pages/shop/GoodsCon/index', path: '/pages/shop/GoodsCon/index',
query: { query: {
@ -214,21 +211,21 @@ export default {
}) })
}, },
// //
setCollect: function () { setCollect: function() {
let that = this, let that = this,
id = that.storeInfo.id, id = that.storeInfo.id,
category = 'product' category = 'product'
if (that.userCollect) { if (that.userCollect) {
getCollectDel(id, category).then(function () { getCollectDel(id, category).then(function() {
that.userCollect = !that.userCollect that.userCollect = !that.userCollect
}) })
} else { } else {
getCollectAdd(id, category).then(function () { getCollectAdd(id, category).then(function() {
that.userCollect = !that.userCollect that.userCollect = !that.userCollect
}) })
} }
}, },
mountedStart: function () { mountedStart: function() {
var that = this var that = this
console.log(this) console.log(this)
let id = that.$yroute.query.id let id = that.$yroute.query.id
@ -260,12 +257,12 @@ export default {
updateTitle() { updateTitle() {
// document.title = this.storeInfo.title || this.$yroute.meta.title; // document.title = this.storeInfo.title || this.$yroute.meta.title;
}, },
setPosterImageStatus: function () { setPosterImageStatus: function() {
// var sTop = document.body || document.documentElement; // var sTop = document.body || document.documentElement;
// sTop.scrollTop = 0; // sTop.scrollTop = 0;
this.posterImageStatus = !this.posterImageStatus this.posterImageStatus = !this.posterImageStatus
}, },
DefaultSelect: function () { DefaultSelect: function() {
let productAttr = this.attr.productAttr let productAttr = this.attr.productAttr
let value = [] let value = []
for (let i = 0; i < productAttr.length; i++) { for (let i = 0; i < productAttr.length; i++) {
@ -305,13 +302,13 @@ export default {
} }
}, },
// //
changeFun: function (opt) { changeFun: function(opt) {
if (typeof opt !== 'object') opt = {} if (typeof opt !== 'object') opt = {}
let action = opt.action || '' let action = opt.action || ''
let value = opt.value === undefined ? '' : opt.value let value = opt.value === undefined ? '' : opt.value
this[action] && this[action](value) this[action] && this[action](value)
}, },
changeattr: function (res) { changeattr: function(res) {
var that = this var that = this
that.attr.cartAttr = res that.attr.cartAttr = res
}, },
@ -330,7 +327,7 @@ export default {
// } // }
// } // }
// }, // },
ChangeCartNum: function (changeValue) { ChangeCartNum: function(changeValue) {
//changeValue: | //changeValue: |
// //
let productSelect = this.productValue[this.attrValue] let productSelect = this.productValue[this.attrValue]
@ -363,7 +360,7 @@ export default {
} }
}, },
// //
ChangeAttr: function (res) { ChangeAttr: function(res) {
// //
let productSelect = this.productValue[res.value] let productSelect = this.productValue[res.value]
if (productSelect) { if (productSelect) {
@ -385,11 +382,11 @@ export default {
this.$set(this, 'attrTxt', '请选择') this.$set(this, 'attrTxt', '请选择')
} }
}, },
selecAttrTap: function () { selecAttrTap: function() {
this.attr.cartAttr = true this.attr.cartAttr = true
this.isOpen = true this.isOpen = true
}, },
tapBuy: function () { tapBuy: function() {
var that = this var that = this
if (that.attr.cartAttr == false) { if (that.attr.cartAttr == false) {
that.attr.cartAttr = !this.attr.attrcartAttr that.attr.cartAttr = !this.attr.attrcartAttr
@ -761,6 +758,19 @@ export default {
justify-content: center; justify-content: center;
flex-direction: column; flex-direction: column;
position: relative; position: relative;
background: none;
padding: 0;
border: 0;
line-height: 1em;
&:after {
display: none;
}
.tui-operation-text {
margin-top: 9rpx;
line-height: 1em;
}
} }
.tui-operation-text { .tui-operation-text {

302
store/index.js

@ -1,166 +1,150 @@
import Vue from "vue"; import Vue from 'vue'
import Vuex from "vuex"; import Vuex from 'vuex'
Vue.use(Vuex); Vue.use(Vuex)
const debug = process.env.NODE_ENV !== "production"; const debug = process.env.NODE_ENV !== 'production'
import cookie from "@/utils/store/cookie"; import cookie from '@/utils/store/cookie'
import { import { getUserInfo, getUser } from '@/api/user'
getUserInfo, import dialog from '@/utils/dialog'
getUser
} from "@/api/user";
import dialog from "@/utils/dialog";
const loginKey = "login_status"; const loginKey = 'login_status'
const vuexStore = new Vuex.Store({ const vuexStore = new Vuex.Store({
state: { state: {
// 是否已经在授权页面 // 是否已经在授权页面
isAuthorizationPage: false, isAuthorizationPage: false,
// 是否授权 // 是否授权
isAuthorization: false, isAuthorization: false,
// 不建议从这里取 token,但是删除掉会影响其他的页面 // 不建议从这里取 token,但是删除掉会影响其他的页面
token: cookie.get(loginKey) || null, token: cookie.get(loginKey) || null,
userInfo: cookie.get('userInfo'), userInfo: cookie.get('userInfo'),
$deviceType: null, $deviceType: null,
location: { location: {
latitude: '', latitude: '',
longitude: '' longitude: '',
}, },
storeItems: cookie.get("storeItems") || null, storeItems: cookie.get('storeItems') || null,
goName: cookie.get("goName") || "" goName: cookie.get('goName') || '',
}, },
mutations: { mutations: {
login(state, token, expires_time) { login(state, token, expires_time) {
state.token = token; state.token = token
cookie.set(loginKey, token, expires_time); cookie.set(loginKey, token, expires_time)
}, },
logout(state) { logout(state) {
console.log('清除数据') console.log('清除数据')
state.token = null; state.token = null
state.userInfo = null state.userInfo = null
cookie.clearAll() cookie.clearAll()
}, },
backgroundColor(state, color) { backgroundColor(state, color) {
state.color = color; state.color = color
// document.body.style.backgroundColor = color; // document.body.style.backgroundColor = color;
}, },
updateUserInfo(state, userInfo) { updateUserInfo(state, userInfo) {
state.userInfo = userInfo; state.userInfo = userInfo
if (userInfo) { if (userInfo) {
cookie.set('userInfo', userInfo) cookie.set('userInfo', userInfo)
} else { } else {
cookie.set('userInfo', null) cookie.set('userInfo', null)
} }
}, },
updateAuthorizationPage(state, isAuthorizationPage) { updateAuthorizationPage(state, isAuthorizationPage) {
state.isAuthorizationPage = isAuthorizationPage; state.isAuthorizationPage = isAuthorizationPage
}, },
updateAuthorization(state, isAuthorization) { updateAuthorization(state, isAuthorization) {
state.isAuthorization = isAuthorization; state.isAuthorization = isAuthorization
}, },
updateDevicetype(state, $deviceType) { updateDevicetype(state, $deviceType) {
state.$deviceType = $deviceType; state.$deviceType = $deviceType
}, },
setLocation(state, location) { setLocation(state, location) {
state.location = location state.location = location
}, },
get_store(state, storeItems) { get_store(state, storeItems) {
state.storeItems = storeItems; state.storeItems = storeItems
cookie.set("storeItems", storeItems); cookie.set('storeItems', storeItems)
}, },
get_to(state, goName) { get_to(state, goName) {
state.goName = goName; state.goName = goName
cookie.set("goName", goName); cookie.set('goName', goName)
} },
}, },
actions: { actions: {
getLocation({ state, commit }, force) { getLocation({ state, commit }, force) {
uni.getLocation({ uni.getLocation({
type: 'gcj02', type: 'gcj02',
success: function (res) { success: function(res) {
console.log(res) console.log(res)
commit("setLocation", { commit('setLocation', {
longitude: res.longitude, longitude: res.longitude,
latitude: res.latitude, latitude: res.latitude,
}); })
} },
}); })
}, },
userInfo({ state, commit }, force) { userInfo({ state, commit }, force) {
if (state.userInfo !== null && !force) { if (state.userInfo !== null && !force) {
return Promise.resolve(state.userInfo); return Promise.resolve(state.userInfo)
} }
return new Promise(reslove => { return new Promise(reslove => {
getUserInfo().then(res => { getUserInfo().then(res => {
commit("updateUserInfo", res.data); commit('updateUserInfo', res.data)
reslove(res.data); reslove(res.data)
}); })
}).catch(() => { }).catch(() => {
uni.showToast({ uni.showToast({
title: "获取信息失败!", title: '获取信息失败!',
icon: "none", icon: 'none',
duration: 2000, duration: 2000,
}); })
}); })
}, },
getUser({ state, commit }) { getUser({ state, commit }) {
if (!state.token) { if (!state.token) {
return Promise.reject('未获取到token'); return Promise.reject('未获取到token')
} }
return new Promise(reslove => { return new Promise(reslove => {
getUserInfo().then(res => { getUserInfo().then(res => {
console.log(res) console.log(res)
commit("updateUserInfo", res.data); commit('updateUserInfo', res.data)
reslove(res.data); reslove(res.data)
}); })
}).catch((error) => { }).catch(error => {
console.log(error) console.log(error)
uni.showToast({ uni.showToast({
title: "获取信息失败!", title: '获取信息失败!',
icon: "none", icon: 'none',
duration: 2000, duration: 2000,
}); })
}); })
}, },
changeLogin({ changeLogin({ state, commit }, data, date) {
state, commit('login', data, date)
commit },
}, data, date) { setUserInfo({ state, commit }, user) {
commit("login", data, date); commit('updateUserInfo', user)
}, },
setUserInfo({ changeAuthorizationPage({ state, commit }, index) {
state, commit('updateAuthorizationPage', index)
commit },
}, user) { changeAuthorization({ state, commit }, index) {
commit('updateAuthorization', index)
commit("updateUserInfo", user); },
}, },
changeAuthorizationPage({ getters: {
state, isAuthorizationPage: state => state.isAuthorizationPage,
commit isAuthorization: state => state.isAuthorization,
}, index) { token: state => state.token,
commit("updateAuthorizationPage", index); isLogin: state => !!state.token,
}, userInfo: state => state.userInfo || {},
changeAuthorization({ location: state => state.location,
state, storeItems: state => state.storeItems,
commit goName: state => state.goName,
}, index) { $deviceType: state => state.$deviceType,
commit("updateAuthorization", index); },
}, strict: debug,
}, })
getters: {
isAuthorizationPage: state => state.isAuthorizationPage,
isAuthorization: state => state.isAuthorization,
token: state => state.token,
isLogin: state => !!state.token,
userInfo: state => state.userInfo || {},
location: state => state.location,
storeItems: state => state.storeItems,
goName: state => state.goName,
$deviceType: state => state.$deviceType,
},
strict: debug
});
export default vuexStore export default vuexStore

142
utils/dialog.js

@ -1,41 +1,31 @@
// import {
// Confirm as confirm,
// Alert as alert,
// Toast as toast,
// Notify as notify,
// Loading as loading
// } from "vue-ydui/dist/lib.rem/dialog";
// import Dialog from "../../static/vant-weapp/dialog/dialog";
// import notify from "../../static/vant-weapp/notify/notify";
const dialog = { const dialog = {
confirm: (options) => { confirm: options => {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: options.mes, content: options.mes,
success(res) { success(res) {
if (res.confirm) { if (res.confirm) {
opts() opts()
} else if (res.cancel) {} } else if (res.cancel) {
} }
}) },
}, })
alert: null, },
// alert: Dialog.alert, alert: null,
notify: null, // alert: Dialog.alert,
// notify, notify: null,
loading: { // notify,
open: () => { loading: {
// uni.showLoading({ open: () => {
// title: '加载中' // uni.showLoading({
// }) // title: '加载中'
}, // })
close: () => { },
uni.hideLoading() close: () => {
} uni.hideLoading()
} },
}; },
}
// const icons = { error: "操作失败", success: "操作成功" }; // const icons = { error: "操作失败", success: "操作成功" };
// Object.keys(icons).reduce((dialog, key) => { // Object.keys(icons).reduce((dialog, key) => {
@ -55,49 +45,49 @@ const dialog = {
// return dialog; // return dialog;
// }, dialog); // }, dialog);
dialog.message = (mes = "操作失败", obj = {}) => { dialog.message = (mes = '操作失败', obj = {}) => {
return new Promise(function(resolve) { return new Promise(function(resolve) {
uni.showToast({ uni.showToast({
title: mes, title: mes,
icon: "none", icon: 'none',
duration: 2000, duration: 2000,
complete: () => { complete: () => {
resolve(); resolve()
} },
}); })
}); })
}; }
dialog.toast = (options) => { dialog.toast = options => {
uni.showToast({ uni.showToast({
title: options.mes, title: options.mes,
icon: "none", icon: 'none',
duration: 2000, duration: 2000,
complete: () => { complete: () => {
options.callback ? options.callback() : null options.callback ? options.callback() : null
} },
}); })
}; }
dialog.error = (mes) => { dialog.error = mes => {
uni.showToast({ uni.showToast({
title: mes, title: mes,
icon: "none", icon: 'none',
duration: 2000 duration: 2000,
}); })
}; }
dialog.validateError = (...args) => { dialog.validateError = (...args) => {
validatorDefaultCatch(...args); validatorDefaultCatch(...args)
}; }
export function validatorDefaultCatch(err, type = "message") { export function validatorDefaultCatch(err, type = 'message') {
uni.showToast({ uni.showToast({
title: err.errors[0].message, title: err.errors[0].message,
icon: 'none', icon: 'none',
duration: 2000 duration: 2000,
}) })
return false return false
} }
export default dialog; export default dialog

112
utils/request.js

@ -1,22 +1,21 @@
// #ifdef H5 // #ifdef H5
// h5端 // h5端
import Fly from "flyio/dist/npm/fly"; import Fly from 'flyio/dist/npm/fly'
// #endif // #endif
// #ifdef APP-PLUS // #ifdef APP-PLUS
// app端 // app端
import Fly from "flyio/dist/npm/wx"; import Fly from 'flyio/dist/npm/wx'
// #endif // #endif
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
import Fly from "flyio/dist/npm/wx"; import Fly from 'flyio/dist/npm/wx'
// #endif // #endif
import store from "../store"; import store from '../store'
import { handleLoginFailure } from "@/utils"; import { handleLoginFailure } from '@/utils'
import { VUE_APP_API_URL } from "@/config"; import { VUE_APP_API_URL } from '@/config'
import cookie from "@/utils/store/cookie"; import cookie from '@/utils/store/cookie'
const fly = new Fly() const fly = new Fly()
fly.config.baseURL = VUE_APP_API_URL fly.config.baseURL = VUE_APP_API_URL
@ -25,82 +24,87 @@ fly.interceptors.response.use(
response => { response => {
// console.log(response) // console.log(response)
// 定时刷新access-token // 定时刷新access-token
return response; return response
}, },
error => { error => {
if (error.toString() == 'Error: Network Error') { if (error.toString() == 'Error: Network Error') {
console.log('————————') console.log('————————')
console.log('发送请求失败', error) console.log('发送请求失败', error)
console.log('————————') console.log('————————')
handleLoginFailure(); handleLoginFailure()
return Promise.reject({ msg: "未登录", toLogin: true }); return Promise.reject({ msg: '未登录', toLogin: true })
} }
if (error.status == 401) { if (error.status == 401) {
console.log('————————') console.log('————————')
console.log('登录失效 401', error) console.log('登录失效 401', error)
console.log('————————') console.log('————————')
handleLoginFailure(); handleLoginFailure()
return Promise.reject({ msg: "未登录", toLogin: true }); return Promise.reject({ msg: '未登录', toLogin: true })
} }
if (error.response.data.status == 5109) { if (error.response.data.status == 5109) {
uni.showToast({ uni.showToast({
title: error.response.data.msg, title: error.response.data.msg,
icon: "none", icon: 'none',
duration: 2000 duration: 2000,
}); })
} }
return Promise.reject(error); return Promise.reject(error)
} }
); )
const defaultOpt = { login: true }; const defaultOpt = { login: true }
function baseRequest(options) { function baseRequest(options) {
// 从缓存中获取 token 防止 token 失效后还会继续请求的情况 // 从缓存中获取 token 防止 token 失效后还会继续请求的情况
const token = cookie.get('login_status'); const token = cookie.get('login_status')
// 合并传参过来的 headers // 合并传参过来的 headers
// 如果接口需要登录,携带 token 去请求 // 如果接口需要登录,携带 token 去请求
options.headers = { options.headers = {
...options.headers ...options.headers,
} }
if (options.login === true) { if (options.login === true) {
options.headers = { options.headers = {
...options.headers, ...options.headers,
Authorization: "Bearer " + token Authorization: 'Bearer ' + token,
} }
} }
// 如果需要登录才可访问的接口没有拿到 token 视为登录失效 // 如果需要登录才可访问的接口没有拿到 token 视为登录失效
if (options.login === true && !token) { if (options.login === true && !token) {
// 跳转到登录或授权页面 // 跳转到登录或授权页面
handleLoginFailure(); handleLoginFailure()
// 提示错误信息 // 提示错误信息
return Promise.reject({ msg: "未登录", toLogin: true }); return Promise.reject({ msg: '未登录', toLogin: true })
} }
// 结构请求需要的参数 // 结构请求需要的参数
const { url, params, data, login, ...option } = options const { url, params, data, login, ...option } = options
// 发起请求 // 发起请求
return fly.request(url, params || data, { return fly
...option .request(url, params || data, {
}).then(res => { ...option,
const data = res.data || {}; })
if (res.status !== 200) { .then(res => {
return Promise.reject({ msg: "请求失败", res, data }); const data = res.data || {}
}
if ([401, 403].indexOf(data.status) !== -1) { if (res.status !== 200) {
handleLoginFailure(); return Promise.reject({ msg: '请求失败', res, data })
return Promise.reject({ msg: res.data.msg, res, data, toLogin: true }); }
} else if (data.status === 200) { console.log(data)
return Promise.resolve(data, res); if ([401, 403].indexOf(data.status) !== -1) {
} else { handleLoginFailure()
return Promise.reject({ msg: res.data.msg, res, data }); return Promise.reject({ msg: res.data.msg, res, data, toLogin: true })
} } else if (data.status === 200) {
}); return Promise.resolve(data, res)
} else if (data.status == 5101) {
return Promise.resolve(data, res)
} else {
return Promise.reject({ msg: res.data.msg, res, data })
}
})
} }
/** /**
@ -108,7 +112,7 @@ function baseRequest(options) {
* 参考文档 https://www.kancloud.cn/yunye/axios/234845 * 参考文档 https://www.kancloud.cn/yunye/axios/234845
* *
*/ */
const request = ["post", "put", "patch"].reduce((request, method) => { const request = ['post', 'put', 'patch'].reduce((request, method) => {
/** /**
* *
* @param url string 接口地址 * @param url string 接口地址
@ -117,14 +121,12 @@ const request = ["post", "put", "patch"].reduce((request, method) => {
* @returns {AxiosPromise} * @returns {AxiosPromise}
*/ */
request[method] = (url, data = {}, options = {}) => { request[method] = (url, data = {}, options = {}) => {
return baseRequest( return baseRequest(Object.assign({ url, data, method }, defaultOpt, options))
Object.assign({ url, data, method }, defaultOpt, options) }
); return request
}; }, {})
return request;
}, {}); ;['get', 'delete', 'head'].forEach(method => {
["get", "delete", "head"].forEach(method => {
/** /**
* *
* @param url string 接口地址 * @param url string 接口地址
@ -133,10 +135,8 @@ const request = ["post", "put", "patch"].reduce((request, method) => {
* @returns {AxiosPromise} * @returns {AxiosPromise}
*/ */
request[method] = (url, params = {}, options = {}) => { request[method] = (url, params = {}, options = {}) => {
return baseRequest( return baseRequest(Object.assign({ url, params, method }, defaultOpt, options))
Object.assign({ url, params, method }, defaultOpt, options) }
); })
};
});
export default request; export default request

Loading…
Cancel
Save