123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- import Vue from 'vue'
- import Vuex from 'vuex';
- import utils from "../library/utils/Comm.js";
- import api from "../config/api.js";
- import md5 from "../library/vendor/md5.js";
- import base64 from "@/library/vendor/base64.js";
- import {
- v4 as uuidv4
- } from "uuid";
- import permission from './modules/permission.js';
- const namespaced = true;
- var isWxLoad = false;
- Vue.use(Vuex)
- const store = new Vuex.Store({
- state: {
- lbs: null,
- user: null,
- weixin: null,
- tj_uid: 0,
- txbagenum: {
- chatCount: 0,
- applyCount: 0
- },
- uuid: "",
- http: "",
- sysData: {
- "bank": 1,
- "ailpay": 1,
- "wxpay": 0,
- "app_code": 0,
- "is_audit": 1,
- app_update: "你有新版本要更新"
- },
- // #ifdef APP
- showData: false,
- // #endif
- // #ifndef APP
- showData: true,
- // #endif
- },
- mutations: {
- // 修改显示隐藏app
- chnangeSshowData(store, data){
- store.showData = data;
- },
- init(store, page) {
- // try{
- var uuid = uni.getStorageSync("uuid");
- if (!utils.isDefine(uuid)) {
- uuid = uuidv4();
- uni.setStorageSync("uuid", uuid);
- }
- store.uuid = uuid;
- var userStr = uni.getStorageSync(uuid + "_user");
- var lbs = uni.getStorageSync(uuid + "_lbs");
- // userStr = '{"token":"M2QzNDYwM2E5NDA4Yzk2MzU5NWUzMmM0NjY3YTc0MTk="}';
- if (utils.isDefine(userStr)) {
- this.commit('setUser', JSON.parse(userStr));
- page.webSocket.connect();
- }
- if (utils.isDefine(lbs)) {
- this.commit('setLbs', JSON.parse(lbs));
- }
- //#ifdef H5
- var wxStr = uni.getStorageSync(uuid + "_wx");
- if (utils.isDefine(wxStr)) {
- this.commit('setWeixin', JSON.parse(wxStr));
- }
- //#endif
- //#ifdef H5
- var tjUID = uni.getStorageSync(uuid + "_tj");
- if (utils.isDefine(tjUID)) {
- this.commit('setTjuid', tjUID);
- }
- //#endif
- // #ifdef H5
- this.commit("setSys", {
- "bank": 1,
- "ailpay": 1,
- "wxpay": 0,
- "app_code": 0,
- "is_audit": 0,
- app_update: "你有新版本要更新"
- });
- // #endif
- this.commit("setHttp", page.global.apiHttps[0]);
- // } catch (e) {
- // console.log(e.message);
- // }
- },
- setHttp: function(store, http) {
- store.http = http;
- },
- /** 设置用户数据
- * @param {Object} store
- * @param {Object} user
- */
- setUser(store, user) {
- store.user = user;
- let app = getApp();
- uni.setStorage({
- key: store.uuid + "_user",
- data: JSON.stringify(user)
- });
- },
- loginOut(store) {
- store.user = null;
- uni.removeStorage({
- key: store.uuid + "_user"
- });
- let app = getApp();
- app.webSocket.ttClose();
- },
- setSys(store, data) {
- store.sysData = data;
- },
- /**
- * 设置定位信息
- * @param {Object} store
- * @param {Object} lbs
- */
- setLbs(store, lbs) {
- store.lbs = lbs;
- uni.setStorage({
- key: store.uuid + '_lbs',
- data: JSON.stringify(lbs)
- });
- },
- /**
- * 获取GPS信息
- */
- getGps: function(store, data) {
- var $page = data.page;
- var fn = data.fn || function() {};
- var err = data.err || function() {};
- var backCall = (gps) => {
- this.commit('setLbs', gps);
- fn(gps);
- };
- // #ifdef H5
- uni.getLocation({
- type: 'wgs84',
- success: (res) => {
- backCall(res);
- },
- fail: () => {
- err();
- console.log('err');
- }
- });
- //#endif
- // #ifdef APP
- let p = uni.getSystemInfoSync().platform;
- if (p === "ios") {
- this.dispatch('permission/requestPermissions', 'ACCESS_FINE_LOCATION').then(res => {
- if (res == 1) {
- uni.getLocation({
- type: 'wgs84',
- success: (res) => {
- backCall(res);
- },
- fail: (er) => {
- err();
- }
- });
- }
- });
- }
- // #endif
- // #ifdef MP-WEIXIN
- uni.getSetting({
- success(res) {
- if (res.authSetting['scope.userLocation'] == null) {
- uni.getLocation({
- type: 'wgs84',
- success: (res) => {
- console.log(res);
- backCall(res);
- },
- fail: (er) => {
- console.log(er);
- err();
- }
- });
- return;
- }
- if (!res.authSetting['scope.userLocation']) {
- uni.showModal({
- title: '系统提示',
- content: "你的位置信息将用于检索附近车行信息",
- success: res => {
- if (res.confirm) {
- uni.openSetting({
- success: () => {
- uni.getLocation({
- type: 'wgs84',
- success: (res) => {
- backCall(
- res);
- },
- fail: () => {
- err();
- }
- });
- }
- });
- } else {
- err();
- }
- }
- });
- return;
- }
- uni.getLocation({
- type: 'wgs84',
- success: (res) => {
- backCall(res);
- },
- fail: (er) => {
- err();
- }
- });
- }
- })
- // #endif
- },
- /**
- * 判断是否登录
- * @param {Object} store
- * @param {Object} $page
- */
- checkUserLogin(store, data) {
- var that = this;
- var $page = data.page;
- var fn = data['fn'] || null;
- var errFn = data['err'] || null;
- var isLogin = data['isLogin'] || null;
- if (store.user == null || store.user.token == null) {
- if (isLogin != null) {
- this.commit('login', 'app');
- } else {
- if (errFn != null) errFn(res);
- }
- this.commit('loginOut', '');
- return;
- }
- $page
- .request
- .post("userInit")
- .then(res => {
- if (res.code == 200) {
- that.commit('setUser', res.data);
- if (fn != null) fn();
- }
- if (res.code == -66) {
- uni.showModal({
- title: '系统提示',
- content: res.msg,
- showCancel: false
- });
- return;
- }
- if (res.code == -99) {
- this.commit('loginOut', '');
- if (isLogin != null) {
- this.commit('login', 'app');
- } else {
- if (errFn != null) errFn(res);
- }
- }
- })
- .catch(e => {
- console.log(e);
- });
- return true;
- },
- /**
- * 支付类型
- * @param {Object} store
- * @param {Object} data
- */
- payPayment: function(store, data) {
- var $page = data.page;
- var isBalance = data.isBalance || 0;
- var isClose = data.isClose || false;
- if (data.afterFn != null) {
- data.afterFn();
- }
- if (data.payOk != null) {
- data.payOk = null;
- }
- uni.showLoading({
- title: "跳转支付中.."
- });
- var post = {
- order_id: data.orderId,
- buy_type: data.buyType,
- pay_type: data.payType,
- device_type: $page.$deviceType,
- bankId: data.bankId == null ? '' : data.bankId,
- value: 0
- };
- $page
- .request
- .post("payPayment", post)
- .then(res => {
- uni.hideLoading();
- if (res.code == 200) {
- //支付宝
- if (data.payType == 'ailpay') {
- if (res.data.openType == 'app') {
- uni.requestPayment({
- provider: 'alipay',
- orderInfo: res.data.url,
- success: (res) => {
- uni.showToast({
- title: "支付成功",
- mask: true,
- icon: "none"
- });
- setTimeout(() => {
- uni.redirectTo({
- url: '/pages/user/pay/order_ok?orderId=' +
- data.orderId +
- "&but_type=" + data
- .buyType
- });
- }, 500);
- },
- fail: (err) => {
- console.log(err);
- uni.showToast({
- title: '你已取消支付'
- });
- }
- });
- }
- if (res.data.openType == 'web') {
- var authUrl = "alipays://platformapi/startapp?appId=20000067&url=" +
- encodeURIComponent(res.data.url);
- if ($page.$device.platform == 'ios') {
- authUrl = ("alipay://platformapi/startapp?appId=20000067&url=" +
- encodeURIComponent(res.data.url));
- }
- // #ifdef APP-PLUS
- $page.$refs['uipay'].show(data.orderId, data.payOk);
- plus.runtime.openURL(authUrl, function(res) {
- uni.showToast({
- icon: "none",
- title: $page.$device.platform +
- "请安装支付宝之后再进行支付!" + JSON.stringify(res)
- });
- });
- // #endif
- // #ifndef APP-PLUS
- location.href = authUrl;
- // #endif
- }
- }
- if (data.payType == 'unionpay') {
- var tts = base64.encode(res.data.url);
- uni.navigateTo({
- url: "/pages/web/index?title=银联支付&url=" + encodeURIComponent(
- tts) + "&type=base64"
- });
- $page.$refs['uipay'].show(data.orderId, data.fn, true);
- }
- if (data.payType == 'wxpay') {
- // #ifdef APP-PLUS
- $page.$refs['uipay'].show(data.orderId, data.payOk);
- plus.runtime.openURL(res.data.url, function(res) {
- uni.showToast({
- icon: "none",
- title: $page.$device.platform + "请安装微信支付!" + JSON
- .stringify(res)
- });
- });
- // #endif
- // #ifndef APP-PLUS
- location.href = res.data.url;
- // #endif
- }
- //银行卡
- if (data.payType == 'bank') {
- if (isClose) {
- uni.redirectTo({
- url: "/pages/user/buy/order_ok?payType=" + data.payType +
- "&orderId=" + data.orderId +
- "&time=" + res.data.time +
- "&pay_card=" + res.data.pay_card
- });
- } else {
- uni.navigateTo({
- url: "/pages/user/buy/order_ok?payType=" + data.payType +
- "&orderId=" + data.orderId +
- "&time=" + res.data.time + "&pay_card=" + res.data
- .pay_card
- });
- }
- }
- } else {
- uni.showToast({
- title: res.msg
- });
- }
- })
- .catch(err => {
- console.log(err);
- uni.hideLoading();
- uni.showModal({
- title: '系统提示',
- content: "支付错误:" + err,
- showCancel: false
- });
- });
- },
- setTxbagenum(store, data) {
- let count = data.chatCount + data.applyCount;
- if (count <= 0) {
- uni.removeTabBarBadge({
- index: 2
- });
- } else {
- uni.setTabBarBadge({
- index: 2,
- text: count + ""
- });
- }
- store.txbagenum = data;
- },
- /**
- * 登录数据 |
- * @param {Object} store
- * @param {Object} type
- */
- login(store, type) {
- //手机app
- if (type == 'app') {
- uni.redirectTo({
- url: "/pages/login/login"
- });
- }
- }
- },
- modules: {
- permission: {
- namespaced,
- ...permission
- },
- }
- });
- export default store
|