diff --git a/.hbuilderx/launch.json b/.hbuilderx/launch.json
new file mode 100644
index 0000000..501e01c
--- /dev/null
+++ b/.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/
+ // launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数
+ "version": "0.0",
+ "configurations": [{
+ "type": "uniCloud",
+ "default": {
+ "launchtype": "remote"
+ }
+ }
+ ]
+}
diff --git a/components/OrderGoods.vue b/components/OrderGoods.vue
index 5669af9..50fac18 100644
--- a/components/OrderGoods.vue
+++ b/components/OrderGoods.vue
@@ -11,13 +11,9 @@
{{ cart.productInfo.storeName }}
x {{ cart.cartNum }}
- {{ cart.productInfo.attrInfo.sku }}
- ¥{{ cart.truePrice }}
- {{ cart.productInfo.attrInfo.integral }}积分
- 评价
+ {{ cart.productInfo.attrInfo.sku }}
+ ¥{{ cart.truePrice }}
+ 评价
@@ -25,26 +21,25 @@
diff --git a/components/tui-button/tui-button.vue b/components/tui-button/tui-button.vue
index 39fc4c7..1293aa5 100644
--- a/components/tui-button/tui-button.vue
+++ b/components/tui-button/tui-button.vue
@@ -1,517 +1,495 @@
-
+
diff --git a/components/tui-icon/tui-icon.vue b/components/tui-icon/tui-icon.vue
deleted file mode 100644
index b04a19d..0000000
--- a/components/tui-icon/tui-icon.vue
+++ /dev/null
@@ -1,816 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/main.js b/main.js
index d837dad..e32dccb 100644
--- a/main.js
+++ b/main.js
@@ -2,41 +2,21 @@ import Vue from 'vue'
import App from './App'
// import router from "./router";
-import store from "./store";
-import schema from "async-validator";
-import dialog from "./utils/dialog";
-import cookie from "@/utils/store/cookie";
+import store from './store'
+import schema from 'async-validator'
+import dialog from './utils/dialog'
+import cookie from '@/utils/store/cookie'
import cuCustom from '@/components/colorui/components/cu-custom.vue'
-// // import "@/assets/iconfont/iconfont";
-// import "@/assets/iconfont/iconfont.css";
-// // import "@/assets/js/media_750";
-// // import "vue-ydui/dist/ydui.base.css";
-// import "@/assets/css/base.less";
-// import "@/assets/css/reset.less";
-// import "@/assets/css/style.less";
-
-// // 引入微信jssdk
-// 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);
-};
+
+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
App.mpType = 'app'
@@ -45,36 +25,33 @@ Vue.prototype.$store = store
const app = new Vue(App)
Vue.mixin({
- onLoad() {
- const {
- $mp
- } = this.$root
- this._route = parseRoute($mp)
- // this.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL;
- this._data.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL;
- },
- onShow() {
- _router.app = this
- _router.currentRoute = this._route
- }
+ onLoad() {
+ const { $mp } = this.$root
+ this._route = parseRoute($mp)
+ // this.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL;
+ this._data.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL
+ },
+ onShow() {
+ _router.app = this
+ _router.currentRoute = this._route
+ },
})
Object.defineProperty(Vue.prototype, '$yrouter', {
- get() {
- return _router
- }
+ get() {
+ return _router
+ },
})
Object.defineProperty(Vue.prototype, '$yroute', {
- get() {
- return this._route
- }
+ get() {
+ return this._route
+ },
})
Vue.prototype.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL
Vue.prototype.$VUE_APP_API_URL = VUE_APP_API_URL
-Vue.component('cu-custom', cuCustom);
-
+Vue.component('cu-custom', cuCustom)
// #ifdef APP-PLUS
// App平台编译的代码
@@ -96,69 +73,49 @@ store.commit('updateDevicetype', 'routine')
// ...mapState(['$deviceType'])
// },
-
// #ifdef H5
// H5编译的代码
-import {
- wechat,
- clearAuthStatus,
- oAuth,
- auth,
- toAuth,
- pay,
- openAddress,
- openShareAll,
- openShareAppMessage,
- openShareTimeline,
- wechatEvevt,
- ready,
- wxShowLocation,
-} from '@/libs/wechat'
+import { wechat, clearAuthStatus, oAuth, auth, toAuth, pay, openAddress, openShareAll, openShareAppMessage, openShareTimeline, wechatEvevt, ready, wxShowLocation } from '@/libs/wechat'
import { isWeixin } from '@/utils'
-const CACHE_KEY = "clear_0.0.1";
+const CACHE_KEY = 'clear_0.0.1'
if (!cookie.has(CACHE_KEY)) {
- cookie.clearAll()
- cookie.set(CACHE_KEY, 1);
+ cookie.clearAll()
+ cookie.set(CACHE_KEY, 1)
}
-var urlSpread = parseQuery()["spread"];
+var urlSpread = parseQuery()['spread']
if (urlSpread) {
- cookie.set("spread", urlSpread);
+ cookie.set('spread', urlSpread)
}
// #endif
-
-
async function init() {
-
- // #ifdef H5
- // H5编译的代码
- // 判断是否是微信浏览器
- if (isWeixin()) {
- Vue.prototype.$deviceType = 'weixin'
- store.commit('updateDevicetype', 'weixin')
- let wechatInit = await wechat()
- console.log(wechatInit)
- if (wechatInit) {
- await oAuth()
- app.$mount()
- }
- } else {
- Vue.prototype.$deviceType = 'weixinh5'
- store.commit('updateDevicetype', 'weixinh5')
- app.$mount()
-
- }
- // #endif
-
- // #ifndef H5
- app.$mount()
- // #endif
-
+ // #ifdef H5
+ // H5编译的代码
+ // 判断是否是微信浏览器
+ if (isWeixin()) {
+ Vue.prototype.$deviceType = 'weixin'
+ store.commit('updateDevicetype', 'weixin')
+ let wechatInit = await wechat()
+ console.log(wechatInit)
+ if (wechatInit) {
+ await oAuth()
+ app.$mount()
+ }
+ } else {
+ Vue.prototype.$deviceType = 'weixinh5'
+ store.commit('updateDevicetype', 'weixinh5')
+ app.$mount()
+ }
+ // #endif
+
+ // #ifndef H5
+ app.$mount()
+ // #endif
}
init()
diff --git a/package.json b/package.json
index 297db34..44f987a 100644
--- a/package.json
+++ b/package.json
@@ -15,7 +15,6 @@
"dayjs": "^1.8.22",
"jweixin-module": "^1.6.0",
"miniapp-color-thief": "^1.0.5",
- "vue-ydui": "^1.2.6",
"vconsole": "^3.3.4",
"wechat-jssdk": "^5.0.4"
},
diff --git a/pages.json b/pages.json
index bdec2e4..e310355 100644
--- a/pages.json
+++ b/pages.json
@@ -41,7 +41,6 @@
"style": {
"navigationBarTitleText": "yshop商城",
"navigationBarTextStyle": "white",
- // "enablePullDownRefresh": true,
"navigationStyle": "custom"
}
},
@@ -425,11 +424,11 @@
}
],
"easycom": {
- "autoscan": true,
- "custom": {
- "tui-(.*)": "@/components/tui-$1/tui-$1.vue"
- }
- },
+ "autoscan": true,
+ "custom": {
+ "tui-(.*)": "@/components/tui-$1/tui-$1.vue"
+ }
+ },
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "Yshop",
diff --git a/pages/activity/GroupDetails/index.vue b/pages/activity/GroupDetails/index.vue
index 45b8758..504b3f2 100644
--- a/pages/activity/GroupDetails/index.vue
+++ b/pages/activity/GroupDetails/index.vue
@@ -10,17 +10,17 @@
¥
- {{ storeInfo.price.split('.')[0] }}
- .{{ storeInfo.price.split('.')[1] }}
+ {{ formatPrice(storeInfo.price, 0) }}
+ .{{ formatPrice(storeInfo.price, 1) }}
{{ storeInfo.people }}人团
- 已拼{{ storeInfo.sales }}{{ storeInfo.unitNam }}
+ 已拼{{ storeInfo.sales }}{{ storeInfo.unitName }}
- 库存{{ storeInfo.stock }}{{ storeInfo.unitNam }}
+ 库存{{ storeInfo.stock }}{{ storeInfo.unitName }}
{{ storeInfo.title }}
@@ -130,7 +130,7 @@
@@ -152,8 +152,8 @@
单独购买
¥
- {{ storeInfo.productPrice.split('.')[0] }}
- .{{ storeInfo.productPrice.split('.')[1] }}
+ {{ formatPrice(storeInfo.productPrice, 0) }}
+ .{{ formatPrice(storeInfo.productPrice, 1) }}
@@ -164,8 +164,8 @@
发起拼团
¥
- {{ storeInfo.price.split('.')[0] }}
- .{{ storeInfo.price.split('.')[1] }}
+ {{ formatPrice(storeInfo.price, 0) }}
+ .{{ formatPrice(storeInfo.price, 1) }}
@@ -205,7 +205,7 @@ export default {
StorePoster,
},
props: {},
- data: function () {
+ data: function() {
return {
domStatus: false,
posterData: {
@@ -246,19 +246,27 @@ export default {
userCollect: false,
}
},
+ computed: {},
watch: {
- $yroute: function (n) {
+ $yroute: function(n) {
var that = this
if (n.name === NAME) {
that.mountedStart()
}
},
},
- onShow: function () {
+ onShow: function() {
this.mountedStart()
},
methods: {
- onShareAppMessage: function () {
+ formatPrice(price, index) {
+ console.log(price)
+ if (price) {
+ return price.split('.')[index]
+ }
+ return ''
+ },
+ onShareAppMessage: function() {
return {
title: this.storeInfo.title,
imageUrl: this.storeInfo.image,
@@ -276,7 +284,7 @@ export default {
},
}
},
- openAlone: function () {
+ openAlone: function() {
this.$yrouter.push({
path: '/pages/shop/GoodsCon/index',
query: {
@@ -286,21 +294,21 @@ export default {
// this.$yrouter.replace({ path: "/detail/" + this.storeInfo.productId });
},
//收藏商品
- setCollect: function () {
+ setCollect: function() {
let that = this,
id = that.storeInfo.id,
category = 'product'
if (that.userCollect) {
- getCollectDel(id, category).then(function () {
+ getCollectDel(id, category).then(function() {
that.userCollect = !that.userCollect
})
} else {
- getCollectAdd(id, category).then(function () {
+ getCollectAdd(id, category).then(function() {
that.userCollect = !that.userCollect
})
}
},
- mountedStart: function () {
+ mountedStart: function() {
var that = this
let id = that.$yroute.query.id
getCombinationDetail(id).then(res => {
@@ -328,7 +336,7 @@ export default {
that.DefaultSelect()
})
},
- DefaultSelect: function () {
+ DefaultSelect: function() {
let productAttr = this.attr.productAttr
let value = []
for (let i = 0; i < productAttr.length; i++) {
@@ -367,19 +375,19 @@ export default {
this.$set(this, 'attrTxt', '请选择')
}
},
- getImageBase64: function () {
+ getImageBase64: function() {
let that = this
imageBase64(this.posterData.image, that.posterData.code).then(res => {
that.posterData.image = res.data.image
that.posterData.code = res.data.code
})
},
- setPosterImageStatus: function () {
+ setPosterImageStatus: function() {
// var sTop = document.body || document.documentElement;
// sTop.scrollTop = 0;
this.posterImageStatus = !this.posterImageStatus
},
- groupRule: function (id) {
+ groupRule: function(id) {
var that = this
that.$yrouter.push({
path: '/pages/activity/GroupRule/index',
@@ -388,7 +396,7 @@ export default {
},
})
},
- goReply: function () {
+ goReply: function() {
var that = this
that.$yrouter.push({
path: '/pages/shop/EvaluateList/index',
@@ -397,21 +405,21 @@ export default {
},
})
},
- setGroupListCount: function () {
+ setGroupListCount: function() {
this.groupListCount = this.groupListCount + 2
},
//将父级向子集多次传送的函数合二为一;
- changeFun: function (opt) {
+ changeFun: function(opt) {
if (typeof opt !== 'object') opt = {}
let action = opt.action || ''
let value = opt.value === undefined ? '' : opt.value
this[action] && this[action](value)
},
- changeattr: function (res) {
+ changeattr: function(res) {
var that = this
that.attr.cartAttr = res
},
- ChangeCartNum: function (res) {
+ ChangeCartNum: function(res) {
var that = this
that.attr.productSelect.cart_num = 1
that.cartNum = 1
@@ -422,7 +430,7 @@ export default {
})
},
//选择属性;
- ChangeAttr: function (res) {
+ ChangeAttr: function(res) {
// 修改了规格
let productSelect = this.productValue[res.value]
if (productSelect) {
@@ -445,7 +453,7 @@ export default {
}
},
- openTeam: function () {
+ openTeam: function() {
var that = this
if (that.attr.cartAttr == false) {
that.attr.cartAttr = !this.attr.cartAttr
@@ -475,7 +483,7 @@ export default {
}
},
//打开属性插件;
- selecAttrTap: function () {
+ selecAttrTap: function() {
this.attr.cartAttr = true
this.isOpen = true
},
@@ -994,6 +1002,18 @@ export default {
justify-content: center;
flex-direction: column;
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 {
@@ -1052,18 +1072,6 @@ export default {
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 {
display: flex;
align-items: flex-end;
diff --git a/pages/activity/SeckillDetails/index.vue b/pages/activity/SeckillDetails/index.vue
index c69e68c..0720f27 100644
--- a/pages/activity/SeckillDetails/index.vue
+++ b/pages/activity/SeckillDetails/index.vue
@@ -9,8 +9,8 @@
¥
- {{ storeInfo.price.split('.')[0] }}
- .{{ storeInfo.price.split('.')[1] }}
+ {{ formatPrice(storeInfo.price, 0) }}
+ .{{ formatPrice(storeInfo.price, 1) }}
@@ -28,17 +28,8 @@
{{ storeInfo.title }}
-
-
库存:{{ storeInfo.stock }}
月销{{ storeInfo.sales }}
@@ -62,14 +53,13 @@
-
@@ -83,7 +73,7 @@
收藏
-
+
单独购买
@@ -117,7 +107,7 @@
-
+
@@ -148,7 +138,7 @@ export default {
StorePoster,
},
props: {},
- data: function () {
+ data: function() {
return {
seckillStatus: '',
domStatus: false,
@@ -177,11 +167,18 @@ export default {
userCollect: false,
}
},
- onShow: function () {
+ onShow: function() {
this.mountedStart()
},
methods: {
- onShareAppMessage: function () {
+ formatPrice(price, index) {
+ console.log(price)
+ if (price) {
+ return price.split('.')[index]
+ }
+ return ''
+ },
+ onShareAppMessage: function() {
return {
title: this.storeInfo.title,
imageUrl: this.storeInfo.image,
@@ -199,7 +196,7 @@ export default {
},
}
},
- openAlone: function () {
+ openAlone: function() {
this.$yrouter.push({
path: '/pages/shop/GoodsCon/index',
query: {
@@ -214,21 +211,21 @@ export default {
})
},
//收藏商品
- setCollect: function () {
+ setCollect: function() {
let that = this,
id = that.storeInfo.id,
category = 'product'
if (that.userCollect) {
- getCollectDel(id, category).then(function () {
+ getCollectDel(id, category).then(function() {
that.userCollect = !that.userCollect
})
} else {
- getCollectAdd(id, category).then(function () {
+ getCollectAdd(id, category).then(function() {
that.userCollect = !that.userCollect
})
}
},
- mountedStart: function () {
+ mountedStart: function() {
var that = this
console.log(this)
let id = that.$yroute.query.id
@@ -260,12 +257,12 @@ export default {
updateTitle() {
// document.title = this.storeInfo.title || this.$yroute.meta.title;
},
- setPosterImageStatus: function () {
+ setPosterImageStatus: function() {
// var sTop = document.body || document.documentElement;
// sTop.scrollTop = 0;
this.posterImageStatus = !this.posterImageStatus
},
- DefaultSelect: function () {
+ DefaultSelect: function() {
let productAttr = this.attr.productAttr
let value = []
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 = {}
let action = opt.action || ''
let value = opt.value === undefined ? '' : opt.value
this[action] && this[action](value)
},
- changeattr: function (res) {
+ changeattr: function(res) {
var that = this
that.attr.cartAttr = res
},
@@ -330,7 +327,7 @@ export default {
// }
// }
// },
- ChangeCartNum: function (changeValue) {
+ ChangeCartNum: function(changeValue) {
//changeValue:是否 加|减
//获取当前变动属性
let productSelect = this.productValue[this.attrValue]
@@ -363,7 +360,7 @@ export default {
}
},
//选择属性;
- ChangeAttr: function (res) {
+ ChangeAttr: function(res) {
// 修改了规格
let productSelect = this.productValue[res.value]
if (productSelect) {
@@ -385,11 +382,11 @@ export default {
this.$set(this, 'attrTxt', '请选择')
}
},
- selecAttrTap: function () {
+ selecAttrTap: function() {
this.attr.cartAttr = true
this.isOpen = true
},
- tapBuy: function () {
+ tapBuy: function() {
var that = this
if (that.attr.cartAttr == false) {
that.attr.cartAttr = !this.attr.attrcartAttr
@@ -761,6 +758,19 @@ export default {
justify-content: center;
flex-direction: column;
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 {
diff --git a/store/index.js b/store/index.js
index 29f34df..cafa8e7 100644
--- a/store/index.js
+++ b/store/index.js
@@ -1,166 +1,150 @@
-import Vue from "vue";
-import Vuex from "vuex";
+import Vue from 'vue'
+import Vuex from 'vuex'
-Vue.use(Vuex);
-const debug = process.env.NODE_ENV !== "production";
+Vue.use(Vuex)
+const debug = process.env.NODE_ENV !== 'production'
-import cookie from "@/utils/store/cookie";
-import {
- getUserInfo,
- getUser
-} from "@/api/user";
-import dialog from "@/utils/dialog";
+import cookie from '@/utils/store/cookie'
+import { getUserInfo, getUser } from '@/api/user'
+import dialog from '@/utils/dialog'
-const loginKey = "login_status";
+const loginKey = 'login_status'
const vuexStore = new Vuex.Store({
- state: {
- // 是否已经在授权页面
- isAuthorizationPage: false,
- // 是否授权
- isAuthorization: false,
- // 不建议从这里取 token,但是删除掉会影响其他的页面
- token: cookie.get(loginKey) || null,
- userInfo: cookie.get('userInfo'),
- $deviceType: null,
- location: {
- latitude: '',
- longitude: ''
- },
- storeItems: cookie.get("storeItems") || null,
- goName: cookie.get("goName") || ""
- },
- mutations: {
- login(state, token, expires_time) {
- state.token = token;
- cookie.set(loginKey, token, expires_time);
- },
- logout(state) {
- console.log('清除数据')
- state.token = null;
- state.userInfo = null
- cookie.clearAll()
- },
- backgroundColor(state, color) {
- state.color = color;
- // document.body.style.backgroundColor = color;
- },
- updateUserInfo(state, userInfo) {
- state.userInfo = userInfo;
- if (userInfo) {
- cookie.set('userInfo', userInfo)
- } else {
- cookie.set('userInfo', null)
- }
- },
- updateAuthorizationPage(state, isAuthorizationPage) {
- state.isAuthorizationPage = isAuthorizationPage;
- },
- updateAuthorization(state, isAuthorization) {
- state.isAuthorization = isAuthorization;
- },
- updateDevicetype(state, $deviceType) {
- state.$deviceType = $deviceType;
- },
- setLocation(state, location) {
- state.location = location
- },
- get_store(state, storeItems) {
- state.storeItems = storeItems;
- cookie.set("storeItems", storeItems);
- },
- get_to(state, goName) {
- state.goName = goName;
- cookie.set("goName", goName);
- }
- },
- actions: {
- getLocation({ state, commit }, force) {
- uni.getLocation({
- type: 'gcj02',
- success: function (res) {
- console.log(res)
- commit("setLocation", {
- longitude: res.longitude,
- latitude: res.latitude,
- });
- }
- });
- },
- userInfo({ state, commit }, force) {
- if (state.userInfo !== null && !force) {
- return Promise.resolve(state.userInfo);
- }
- return new Promise(reslove => {
- getUserInfo().then(res => {
- commit("updateUserInfo", res.data);
- reslove(res.data);
- });
- }).catch(() => {
- uni.showToast({
- title: "获取信息失败!",
- icon: "none",
- duration: 2000,
- });
- });
- },
- getUser({ state, commit }) {
- if (!state.token) {
- return Promise.reject('未获取到token');
- }
- return new Promise(reslove => {
- getUserInfo().then(res => {
- console.log(res)
- commit("updateUserInfo", res.data);
- reslove(res.data);
- });
- }).catch((error) => {
- console.log(error)
- uni.showToast({
- title: "获取信息失败!",
- icon: "none",
- duration: 2000,
- });
- });
- },
- changeLogin({
- state,
- commit
- }, data, date) {
- commit("login", data, date);
- },
- setUserInfo({
- state,
- commit
- }, user) {
-
- commit("updateUserInfo", user);
- },
- changeAuthorizationPage({
- state,
- commit
- }, index) {
- commit("updateAuthorizationPage", index);
- },
- changeAuthorization({
- state,
- commit
- }, index) {
- commit("updateAuthorization", index);
- },
- },
- 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
-});
+ state: {
+ // 是否已经在授权页面
+ isAuthorizationPage: false,
+ // 是否授权
+ isAuthorization: false,
+ // 不建议从这里取 token,但是删除掉会影响其他的页面
+ token: cookie.get(loginKey) || null,
+ userInfo: cookie.get('userInfo'),
+ $deviceType: null,
+ location: {
+ latitude: '',
+ longitude: '',
+ },
+ storeItems: cookie.get('storeItems') || null,
+ goName: cookie.get('goName') || '',
+ },
+ mutations: {
+ login(state, token, expires_time) {
+ state.token = token
+ cookie.set(loginKey, token, expires_time)
+ },
+ logout(state) {
+ console.log('清除数据')
+ state.token = null
+ state.userInfo = null
+ cookie.clearAll()
+ },
+ backgroundColor(state, color) {
+ state.color = color
+ // document.body.style.backgroundColor = color;
+ },
+ updateUserInfo(state, userInfo) {
+ state.userInfo = userInfo
+ if (userInfo) {
+ cookie.set('userInfo', userInfo)
+ } else {
+ cookie.set('userInfo', null)
+ }
+ },
+ updateAuthorizationPage(state, isAuthorizationPage) {
+ state.isAuthorizationPage = isAuthorizationPage
+ },
+ updateAuthorization(state, isAuthorization) {
+ state.isAuthorization = isAuthorization
+ },
+ updateDevicetype(state, $deviceType) {
+ state.$deviceType = $deviceType
+ },
+ setLocation(state, location) {
+ state.location = location
+ },
+ get_store(state, storeItems) {
+ state.storeItems = storeItems
+ cookie.set('storeItems', storeItems)
+ },
+ get_to(state, goName) {
+ state.goName = goName
+ cookie.set('goName', goName)
+ },
+ },
+ actions: {
+ getLocation({ state, commit }, force) {
+ uni.getLocation({
+ type: 'gcj02',
+ success: function(res) {
+ console.log(res)
+ commit('setLocation', {
+ longitude: res.longitude,
+ latitude: res.latitude,
+ })
+ },
+ })
+ },
+ userInfo({ state, commit }, force) {
+ if (state.userInfo !== null && !force) {
+ return Promise.resolve(state.userInfo)
+ }
+ return new Promise(reslove => {
+ getUserInfo().then(res => {
+ commit('updateUserInfo', res.data)
+ reslove(res.data)
+ })
+ }).catch(() => {
+ uni.showToast({
+ title: '获取信息失败!',
+ icon: 'none',
+ duration: 2000,
+ })
+ })
+ },
+ getUser({ state, commit }) {
+ if (!state.token) {
+ return Promise.reject('未获取到token')
+ }
+ return new Promise(reslove => {
+ getUserInfo().then(res => {
+ console.log(res)
+ commit('updateUserInfo', res.data)
+ reslove(res.data)
+ })
+ }).catch(error => {
+ console.log(error)
+ uni.showToast({
+ title: '获取信息失败!',
+ icon: 'none',
+ duration: 2000,
+ })
+ })
+ },
+ changeLogin({ state, commit }, data, date) {
+ commit('login', data, date)
+ },
+ setUserInfo({ state, commit }, user) {
+ commit('updateUserInfo', user)
+ },
+ changeAuthorizationPage({ state, commit }, index) {
+ commit('updateAuthorizationPage', index)
+ },
+ changeAuthorization({ state, commit }, index) {
+ commit('updateAuthorization', index)
+ },
+ },
+ 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
diff --git a/utils/dialog.js b/utils/dialog.js
index f0f4a69..94dff6e 100644
--- a/utils/dialog.js
+++ b/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 = {
- confirm: (options) => {
- uni.showModal({
- title: '提示',
- content: options.mes,
- success(res) {
- if (res.confirm) {
- opts()
- } else if (res.cancel) {}
- }
- })
- },
- alert: null,
- // alert: Dialog.alert,
- notify: null,
- // notify,
- loading: {
- open: () => {
- // uni.showLoading({
- // title: '加载中'
- // })
- },
- close: () => {
- uni.hideLoading()
- }
- }
-};
+ confirm: options => {
+ uni.showModal({
+ title: '提示',
+ content: options.mes,
+ success(res) {
+ if (res.confirm) {
+ opts()
+ } else if (res.cancel) {
+ }
+ },
+ })
+ },
+ alert: null,
+ // alert: Dialog.alert,
+ notify: null,
+ // notify,
+ loading: {
+ open: () => {
+ // uni.showLoading({
+ // title: '加载中'
+ // })
+ },
+ close: () => {
+ uni.hideLoading()
+ },
+ },
+}
// const icons = { error: "操作失败", success: "操作成功" };
// Object.keys(icons).reduce((dialog, key) => {
@@ -55,49 +45,49 @@ const dialog = {
// return dialog;
// }, dialog);
-dialog.message = (mes = "操作失败", obj = {}) => {
- return new Promise(function(resolve) {
- uni.showToast({
- title: mes,
- icon: "none",
- duration: 2000,
- complete: () => {
- resolve();
- }
- });
- });
-};
+dialog.message = (mes = '操作失败', obj = {}) => {
+ return new Promise(function(resolve) {
+ uni.showToast({
+ title: mes,
+ icon: 'none',
+ duration: 2000,
+ complete: () => {
+ resolve()
+ },
+ })
+ })
+}
-dialog.toast = (options) => {
- uni.showToast({
- title: options.mes,
- icon: "none",
- duration: 2000,
- complete: () => {
- options.callback ? options.callback() : null
- }
- });
-};
+dialog.toast = options => {
+ uni.showToast({
+ title: options.mes,
+ icon: 'none',
+ duration: 2000,
+ complete: () => {
+ options.callback ? options.callback() : null
+ },
+ })
+}
-dialog.error = (mes) => {
- uni.showToast({
- title: mes,
- icon: "none",
- duration: 2000
- });
-};
+dialog.error = mes => {
+ uni.showToast({
+ title: mes,
+ icon: 'none',
+ duration: 2000,
+ })
+}
dialog.validateError = (...args) => {
- validatorDefaultCatch(...args);
-};
+ validatorDefaultCatch(...args)
+}
-export function validatorDefaultCatch(err, type = "message") {
- uni.showToast({
- title: err.errors[0].message,
- icon: 'none',
- duration: 2000
- })
- return false
+export function validatorDefaultCatch(err, type = 'message') {
+ uni.showToast({
+ title: err.errors[0].message,
+ icon: 'none',
+ duration: 2000,
+ })
+ return false
}
-export default dialog;
+export default dialog
diff --git a/utils/request.js b/utils/request.js
index 633ba54..323edef 100644
--- a/utils/request.js
+++ b/utils/request.js
@@ -1,22 +1,21 @@
// #ifdef H5
// h5端
-import Fly from "flyio/dist/npm/fly";
+import Fly from 'flyio/dist/npm/fly'
// #endif
// #ifdef APP-PLUS
// app端
-import Fly from "flyio/dist/npm/wx";
+import Fly from 'flyio/dist/npm/wx'
// #endif
// #ifdef MP-WEIXIN
-import Fly from "flyio/dist/npm/wx";
+import Fly from 'flyio/dist/npm/wx'
// #endif
-import store from "../store";
-import { handleLoginFailure } from "@/utils";
-import { VUE_APP_API_URL } from "@/config";
-import cookie from "@/utils/store/cookie";
-
+import store from '../store'
+import { handleLoginFailure } from '@/utils'
+import { VUE_APP_API_URL } from '@/config'
+import cookie from '@/utils/store/cookie'
const fly = new Fly()
fly.config.baseURL = VUE_APP_API_URL
@@ -25,82 +24,87 @@ fly.interceptors.response.use(
response => {
// console.log(response)
// 定时刷新access-token
- return response;
+ return response
},
error => {
if (error.toString() == 'Error: Network Error') {
console.log('————————')
console.log('发送请求失败', error)
console.log('————————')
- handleLoginFailure();
- return Promise.reject({ msg: "未登录", toLogin: true });
+ handleLoginFailure()
+ return Promise.reject({ msg: '未登录', toLogin: true })
}
if (error.status == 401) {
console.log('————————')
console.log('登录失效 401', error)
console.log('————————')
- handleLoginFailure();
- return Promise.reject({ msg: "未登录", toLogin: true });
+ handleLoginFailure()
+ return Promise.reject({ msg: '未登录', toLogin: true })
}
if (error.response.data.status == 5109) {
uni.showToast({
title: error.response.data.msg,
- icon: "none",
- duration: 2000
- });
+ icon: 'none',
+ duration: 2000,
+ })
}
- return Promise.reject(error);
+ return Promise.reject(error)
}
-);
+)
-const defaultOpt = { login: true };
+const defaultOpt = { login: true }
function baseRequest(options) {
-
// 从缓存中获取 token 防止 token 失效后还会继续请求的情况
- const token = cookie.get('login_status');
+ const token = cookie.get('login_status')
// 合并传参过来的 headers
// 如果接口需要登录,携带 token 去请求
options.headers = {
- ...options.headers
+ ...options.headers,
}
if (options.login === true) {
options.headers = {
...options.headers,
- Authorization: "Bearer " + token
+ Authorization: 'Bearer ' + token,
}
}
// 如果需要登录才可访问的接口没有拿到 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
// 发起请求
- return fly.request(url, params || data, {
- ...option
- }).then(res => {
- const data = res.data || {};
- if (res.status !== 200) {
- return Promise.reject({ msg: "请求失败", res, data });
- }
- if ([401, 403].indexOf(data.status) !== -1) {
- handleLoginFailure();
- return Promise.reject({ msg: res.data.msg, res, data, toLogin: true });
- } else if (data.status === 200) {
- return Promise.resolve(data, res);
- } else {
- return Promise.reject({ msg: res.data.msg, res, data });
- }
- });
+ return fly
+ .request(url, params || data, {
+ ...option,
+ })
+ .then(res => {
+ const data = res.data || {}
+
+ if (res.status !== 200) {
+ return Promise.reject({ msg: '请求失败', res, data })
+ }
+ console.log(data)
+ if ([401, 403].indexOf(data.status) !== -1) {
+ handleLoginFailure()
+ 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
*
*/
-const request = ["post", "put", "patch"].reduce((request, method) => {
+const request = ['post', 'put', 'patch'].reduce((request, method) => {
/**
*
* @param url string 接口地址
@@ -117,14 +121,12 @@ const request = ["post", "put", "patch"].reduce((request, method) => {
* @returns {AxiosPromise}
*/
request[method] = (url, data = {}, options = {}) => {
- return baseRequest(
- Object.assign({ url, data, method }, defaultOpt, options)
- );
- };
- return request;
-}, {});
-
-["get", "delete", "head"].forEach(method => {
+ return baseRequest(Object.assign({ url, data, method }, defaultOpt, options))
+ }
+ return request
+}, {})
+
+;['get', 'delete', 'head'].forEach(method => {
/**
*
* @param url string 接口地址
@@ -133,10 +135,8 @@ const request = ["post", "put", "patch"].reduce((request, method) => {
* @returns {AxiosPromise}
*/
request[method] = (url, params = {}, options = {}) => {
- return baseRequest(
- Object.assign({ url, params, method }, defaultOpt, options)
- );
- };
-});
+ return baseRequest(Object.assign({ url, params, method }, defaultOpt, options))
+ }
+})
-export default request;
+export default request