|
|
- import Vue from 'vue'
- import Vuex from 'vuex'
-
- Vue.use(Vuex); //vue的插件机制
-
- import api from '@/api/api.js'
-
- //Vuex.Store 构造器选项
- const store = new Vuex.Store({
- state: {
- configList: {}, //配置列表
- // 角色 true为老板 false为工人
- role : false,
- userInfo : {}, //用户信息
- banner : [],//轮播图
- jobTypeList : [],//工种
- natureList : [],//工作性质
- addressList : [],//开放地址
- },
- getters: {
- },
- mutations: {
- // 初始化配置
- initConfig(state){
- api('getConfig', res => {
- if(res.code == 200){
- res.result.forEach(n => {
- state.configList[n.paramCode] = n.paramValueText ||
- n.paramValue ||
- n.paramValueImage
- // state.configList[n.keyName + '_keyValue'] = n.keyValue
- })
- }
- })
-
- // let config = ['getPrivacyPolicy', 'getUserAgreement']
- // config.forEach(k => {
- // api(k, res => {
- // if (res.code == 200) {
- // state.configList[k] = res.result
- // }
- // })
- // })
- },
- login(state){
- uni.showLoading({
- title: '登录中...'
- })
- uni.login({
- success(res) {
- if(res.errMsg != "login:ok"){
- return
- }
-
- api('wxLogin', {
- code : res.code
- }, res => {
-
- uni.hideLoading()
-
- if(res.code != 200){
- return
- }
-
- state.userInfo = res.result.userInfo
- uni.setStorageSync('token', res.result.token)
-
- if(!state.userInfo.nickName || !state.userInfo.headImage
- || !state.userInfo.phone){
- uni.navigateTo({
- url: '/pages_order/auth/wxUserInfo'
- })
- }else{
- uni.navigateBack(-1)
- }
- })
- }
- })
- },
- getUserInfo(state){
- api('getInfo', res => {
- if(res.code == 200){
- state.userInfo = res.result
-
- // if(!state.userInfo.nickName || !state.userInfo.headImage
- // || !state.userInfo.phone){
- // uni.navigateTo({
- // url: '/pages_order/auth/wxUserInfo'
- // })
- // }
- }
- })
- },
- // 获取工种列表
- getJobTypeList(state){
- api('commonQueryJobTypeList', {
- pageNo : 1,
- pageSize : 99999,
- }, res => {
- if(res.code != 200){
- return
- }
- state.jobTypeList = res.result.records
- })
- },
- // 获取开放地址
- getAddressList(state){
- api('commonQueryAddressList', {
- pageNo : 1,
- pageSize : 99999,
- }, res => {
- if(res.code != 200){
- return
- }
- state.addressList = res.result.records
- })
- },
- // 获取轮播图
- getBanner(state){
- api('commonQueryBannerList', {
- pageNo : 1,
- pageSize : 99999,
- }, res => {
- if(res.code != 200){
- return
- }
- state.banner = res.result.records
- })
- },
- // 获取工作性质列表
- getNatureList(state){
- api('commonQueryJobNatureList', {
- pageNo : 1,
- pageSize : 99999,
- }, res => {
- if(res.code != 200){
- return
- }
- state.natureList = res.result.records
- })
- },
- logout(state){
- uni.showModal({
- title: '确认退出登录吗',
- success(r) {
- if(r.confirm){
- state.userInfo = {}
- state.role = false
- uni.removeStorageSync('token')
- uni.redirectTo({
- url: '/pages/index/index'
- })
- }
- }
- })
- },
- setRole(state, role){
- state.role = role
- },
- },
- actions: {},
- })
-
- export default store
|