123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- import { isFunc, isEmpty } from "./base";
- function getUserInfo() {
- return wx.getStorageSync('userInfo') || null;
- }
- function setUserInfo(user) {
- wx.setStorageSync('userInfo', user)
- }
- function setaddress(address) {
- wx.setStorageSync('address', address)
- }
- function getaddress() {
- return wx.getStorageSync('address')
- }
- function setUserInfoPart(userPart) {
- let user = getUserInfo()
- if (user == null) {
- user = userPart
- } else {
- for(let k in userPart) {
- user[k] = userPart[k]
- }
- }
- setUserInfo(user)
- }
- /**
- * 获取用户当前选中的店铺
- */
- function getCurrStore() {
- return wx.getStorageSync('store') || null
- }
- /**
- * 获取用户当前选中的桌位
- */
- function getCurrTable() {
- return wx.getStorageSync('table') || null
- }
- function getChooseStore() {
- return wx.getStorageSync('chooseStore') || null
- }
- function setChooseStore(chooseStore) {
- wx.setStorageSync('chooseStore', chooseStore)
- }
- function getMobile() {
- const userInfo = getUserInfo()
- if (userInfo != null) {
- return userInfo.mobile || ''
- }
- return ''
- }
- function getStoreId() {
- const store = getCurrStore()
- if (store != null) {
- return store.id || null;
- }
- return null
- }
- // 缓存门店取餐方式
- function setStoreWay(storeway) {
- wx.setStorageSync('storeway', storeway)
- }
- function getStoreWay(storeway) {
- return wx.getStorageSync('storeway')||null;
- }
- function setCurrStore(store) {
- wx.setStorageSync('store', store)
- }
- function setCurrTable(table) {
- wx.setStorageSync('table', table)
- }
- //存储最近的经纬度
- function setNearLocation(longitude,latitude) {
- wx.setStorageSync('nearLocation', {
- longitude:longitude,
- latitude:latitude
- })
- }
- //获取最近的经纬度
- function getNearLocation() {
- return wx.getStorageSync('nearLocation')||null;
- }
- function getTableId() {
- const table = getCurrTable()
- if (table != null) {
- return table.tableId || null
- }
- return null
- }
- function getSessionKey() {
- return wx.getStorageSync('loginInfo').sessionKey
- }
- function getOpenId() {
- return wx.getStorageSync('loginInfo').openId
- }
- function getLoginInfo() {
- wx.getStorageSync('loginInfo')||null;
- }
- /**
- * 授权手机号
- * @param {*} e
- * @param {*} func
- */
- function getPhoneNumber(e, func) {
- console.log(e)
- let code = e.detail.code;
- //获取手机号
- if (isEmpty(code)) {
- // 兼容老版本
- var encryptedData = e.detail.encryptedData;
- // console.log(encryptedData);
- var iv = e.detail.iv;
- if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
- return;
- }
- //获取手机号
- doDecodePhoneOld(encryptedData, iv, function (mobile) {
- func(mobile)
- });
- } else {
- doDecodePhone(code, function (mobile) {
- func(mobile)
- });
- }
- }
- function checkInvalid(param = {}, callBack) {
- // wx.checkSession({
- // success() {
- // if (isFunc(callBack)) {
- // callBack(param)
- // }
- // },
- // fail() {
- // login(callBack)
- // }
- // })
- login(callBack)
- }
- module.exports = {
- getMobile,
- getPhoneNumber,
- getStoreId,
- getTableId,
- setCurrStore,
- getCurrStore,
- getCurrTable,
- setCurrTable,
- setUserInfo,
- getUserInfo,
- setUserInfoPart,
- getLoginInfo,
- setNearLocation,
- getNearLocation,
- setStoreWay,
- getStoreWay,
- setaddress,
- getaddress,
- setChooseStore,
- getChooseStore,
- }
|