初始化代码
This commit is contained in:
10
uniapp/uni-app/store/index.js
Normal file
10
uniapp/uni-app/store/index.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import Vue from "vue"
|
||||
import Vuex from "vuex"
|
||||
Vue.use(Vuex)
|
||||
const files = require.context('./modules', false, /\.js$/)
|
||||
const modules = {}
|
||||
files.keys().forEach(key => {
|
||||
modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default
|
||||
})
|
||||
|
||||
export default new Vuex.Store({modules})
|
||||
57
uniapp/uni-app/store/modules/config.js
Normal file
57
uniapp/uni-app/store/modules/config.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import $api from "@/api/index.js"
|
||||
|
||||
export default {
|
||||
state: {
|
||||
//主题颜色
|
||||
configInfo: {
|
||||
id: 0,
|
||||
navBarHeight: uni.getSystemInfoSync().statusBarHeight * 1 + 44,
|
||||
isIos: uni.getSystemInfoSync().system.includes('iOS'),
|
||||
canIUseGetUserProfile: uni.getUserProfile ? true : false,
|
||||
primaryColor: '#39b54a',
|
||||
subColor: '#F3A664',
|
||||
refund_img: 'https://lbqny.migugu.com/paotui/errand.png',
|
||||
curSysHeight: '',
|
||||
tabbarHeight: '',
|
||||
expressList: [{
|
||||
id: 1,
|
||||
title: '同城配送'
|
||||
}, {
|
||||
id: 2,
|
||||
title: '中通快递'
|
||||
}, {
|
||||
id: 3,
|
||||
title: '圆通快递'
|
||||
}, {
|
||||
id: 4,
|
||||
title: '申通快递'
|
||||
}, {
|
||||
id: 5,
|
||||
title: '韵达快递'
|
||||
}]
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
updateConfigItem(state, item) {
|
||||
let {
|
||||
key,
|
||||
val
|
||||
} = item
|
||||
state[key] = val
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
// 获取基本配置
|
||||
async getConfigInfo({
|
||||
commit,
|
||||
state
|
||||
}, param) {
|
||||
let config = await $api.base.configInfo()
|
||||
let data = Object.assign(state.configInfo, config)
|
||||
commit('updateConfigItem', {
|
||||
key: 'configInfo',
|
||||
val: data
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
47
uniapp/uni-app/store/modules/order.js
Normal file
47
uniapp/uni-app/store/modules/order.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import $util from "@/utils/index.js"
|
||||
import $api from "@/api/index.js"
|
||||
import {
|
||||
req
|
||||
} from '@/utils/req.js';
|
||||
export default {
|
||||
state: {
|
||||
shopCarList: {},
|
||||
restaurantCarList: {},
|
||||
orderInfo: {},
|
||||
haveOperItem: false
|
||||
},
|
||||
mutations: {
|
||||
updateOrderItem(state, item) {
|
||||
let {
|
||||
key,
|
||||
val
|
||||
} = item
|
||||
state[key] = val
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// 获取购物车数据
|
||||
async getShopCarList({
|
||||
commit,
|
||||
state
|
||||
}, param) {
|
||||
let data = await $api.shop.carInfo(param)
|
||||
data.selectAll = data.car_count === data.all_count
|
||||
commit('updateOrderItem', {
|
||||
key: 'shopCarList',
|
||||
val: data
|
||||
})
|
||||
},
|
||||
// 获取购物车数据
|
||||
async getRestaurantCarList({
|
||||
commit,
|
||||
state
|
||||
}, param) {
|
||||
let data = await $api.restaurant.carInfo(param)
|
||||
commit('updateOrderItem', {
|
||||
key: 'restaurantCarList',
|
||||
val: data
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
142
uniapp/uni-app/store/modules/user.js
Normal file
142
uniapp/uni-app/store/modules/user.js
Normal file
@@ -0,0 +1,142 @@
|
||||
import $util from "@/utils/index.js"
|
||||
import $api from "@/api/index.js"
|
||||
export default {
|
||||
state: {
|
||||
pageActiveHome: false,
|
||||
pageActiveShop: false,
|
||||
pageActiveMine: false,
|
||||
autograph: '',
|
||||
userInfo: '',
|
||||
appLogin: '',
|
||||
loginType: '',
|
||||
loginPage: '',
|
||||
isShowLogin: true,
|
||||
push_id: '',
|
||||
commonOptions: {},
|
||||
location: {},
|
||||
isShowAuth: true,
|
||||
mineInfo: {}
|
||||
},
|
||||
mutations: {
|
||||
//更新内容
|
||||
async updateUserItem(state, item) {
|
||||
let {
|
||||
key,
|
||||
val
|
||||
} = item
|
||||
if (key == 'userInfo') {
|
||||
let {
|
||||
phone = ''
|
||||
} = val
|
||||
if (phone) {
|
||||
val.split_phone = phone.substring(0, 3) + '****' + phone.substring(7, 11)
|
||||
}
|
||||
}
|
||||
state[key] = val
|
||||
if (['autograph', 'userInfo', 'appLogin', 'loginType', 'push_id'].includes(key)) {
|
||||
uni.setStorageSync(key, val)
|
||||
}
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
//获取个人信息
|
||||
async getUserInfo({
|
||||
commit,
|
||||
state
|
||||
}, param) {
|
||||
let data = await $api.user.userInfo()
|
||||
commit('updateUserItem', {
|
||||
key: 'userInfo',
|
||||
val: data
|
||||
})
|
||||
},
|
||||
//获取用户个人中心数据
|
||||
async getMineInfo({
|
||||
commit,
|
||||
state
|
||||
}, param) {
|
||||
let data = await $api.mine.index()
|
||||
let {
|
||||
farmer_status = -1,
|
||||
is_landlord = 0
|
||||
} = data
|
||||
data.id = data.id || -1
|
||||
data.is_user = (farmer_status == 2 || farmer_status == 3 || is_landlord) ? 0 : 1
|
||||
commit('updateUserItem', {
|
||||
key: 'mineInfo',
|
||||
val: data
|
||||
})
|
||||
},
|
||||
// 获取用户信息
|
||||
async getAuthUserProfile({
|
||||
commit,
|
||||
state
|
||||
}, param) {
|
||||
let {
|
||||
nickName,
|
||||
avatarUrl
|
||||
} = param
|
||||
let params = $util.pick(param, ['nickName', 'avatarUrl', 'city', 'country', 'gender', 'province'])
|
||||
await $api.user.userUpdate(params)
|
||||
let data = Object.assign(state.userInfo, {
|
||||
nickName,
|
||||
avatarUrl
|
||||
})
|
||||
commit('updateUserItem', {
|
||||
key: 'userInfo',
|
||||
val: data
|
||||
})
|
||||
},
|
||||
// 获取手机号
|
||||
async getAuthPhone({
|
||||
commit,
|
||||
state
|
||||
}, {
|
||||
e = {
|
||||
detail: {}
|
||||
},
|
||||
must = false
|
||||
} = {}) {
|
||||
let {
|
||||
encryptedData = '', iv = ''
|
||||
} = e.detail;
|
||||
let phone = ''
|
||||
if (encryptedData && iv) {
|
||||
let phone = await $api.user.reportPhone({
|
||||
encryptedData,
|
||||
iv
|
||||
})
|
||||
let data = Object.assign(state.userInfo, {
|
||||
phone
|
||||
})
|
||||
commit('updateUserItem', {
|
||||
key: 'userInfo',
|
||||
val: data
|
||||
})
|
||||
return phone;
|
||||
}
|
||||
},
|
||||
// 更新公共参数
|
||||
async updateCommonOptions({
|
||||
commit,
|
||||
state
|
||||
}, param) {
|
||||
let target = {}
|
||||
if (param.scene) {
|
||||
let res = await $api.base.getWxCodeData({
|
||||
code_id: param.scene
|
||||
})
|
||||
target = Object.assign({}, state.commonOptions, res.data)
|
||||
} else {
|
||||
target = Object.assign({}, state.commonOptions, param)
|
||||
}
|
||||
let data = $util.pick(target, ['id', 'record_id'])
|
||||
commit('updateUserItem', {
|
||||
key: 'commonOptions',
|
||||
val: data
|
||||
})
|
||||
console.log(target, "======target");
|
||||
return target
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user