添加storage
This commit is contained in:
parent
d1d70d29b9
commit
2cc928c5bb
|
@ -4,7 +4,7 @@ export default {
|
|||
pageConfig: {},
|
||||
},
|
||||
onLaunch: function () {
|
||||
let pageConfig = uni.getStorageSync("system_config");
|
||||
let pageConfig = this.$storage.get("system_config");
|
||||
if (!pageConfig) {
|
||||
const { windowWidth, windowHeight, statusBarHeight, safeAreaInsets } = uni.getSystemInfoSync();
|
||||
// #ifndef H5
|
||||
|
@ -15,7 +15,7 @@ export default {
|
|||
const headerHeight = 40; // 乘2再使用rpx2px转px使用
|
||||
// #endif
|
||||
pageConfig = { windowWidth, windowHeight, statusBarHeight, headerHeight, safeAreaInsets };
|
||||
uni.setStorageSync("system_config", pageConfig);
|
||||
this.$storage.set("system_config", pageConfig);
|
||||
}
|
||||
this.globalData.pageConfig = pageConfig;
|
||||
// 初始化用户
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
export default {
|
||||
name: "熊熊安装",
|
||||
storagePrefix: "user_",
|
||||
appId: "wx239055764f21ba10",
|
||||
root: "http://xiongxiong.vipwjf.com/api.php"
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import $storage from '@/core/storage'
|
||||
|
||||
function time() {
|
||||
return parseInt(Math.round(new Date() / 1000));
|
||||
};
|
||||
|
@ -143,13 +145,13 @@ function debounce(func, wait = 500, immediate = false) {
|
|||
}
|
||||
|
||||
function px2rpx(px) {
|
||||
let { windowWidth } = uni.getStorageSync('system_config');
|
||||
let { windowWidth } = $storage.get('system_config');
|
||||
windowWidth = (windowWidth > 750) ? 750 : windowWidth;
|
||||
return 750 * (px / windowWidth);
|
||||
}
|
||||
|
||||
function rpx2px(rpx) {
|
||||
let { windowWidth } = uni.getStorageSync('system_config');
|
||||
let { windowWidth } = $storage.get('system_config');
|
||||
windowWidth = (windowWidth > 750) ? 750 : windowWidth;
|
||||
return (rpx / 750) * windowWidth;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ export default {
|
|||
*/
|
||||
list(refresh) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let cacheList = uni.getStorageSync('USER_CART');
|
||||
let cacheList = prototype.$storage.get('user_cart');
|
||||
if ((typeof refresh === "undefined" || false === refresh) && cacheList) {
|
||||
return resolve(cacheList);
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ export default {
|
|||
api: "service.cart.list",
|
||||
}).then(response => {
|
||||
if (response.code == 1) {
|
||||
uni.setStorageSync('USER_CART', response.data);
|
||||
prototype.$storage.set('user_cart', response.data);
|
||||
return resolve(response.data);
|
||||
}
|
||||
return reject(response.msg);
|
||||
|
|
|
@ -18,7 +18,7 @@ export default {
|
|||
code: result.code
|
||||
}
|
||||
}).then((response) => {
|
||||
uni.setStorageSync("open_id", response.data.openid);
|
||||
prototype.$storage.set("open_id", response.data.openid);
|
||||
return resolve(response.data);
|
||||
}).catch(e => { });
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ export default {
|
|||
*/
|
||||
async initUser() {
|
||||
// openid
|
||||
let openId = uni.getStorageSync("open_id");
|
||||
let openId = prototype.$storage.get("open_id");
|
||||
if (!openId) {
|
||||
await this.platformLogin().then((response) => {
|
||||
openId = response.openid;
|
||||
|
@ -44,7 +44,7 @@ export default {
|
|||
}
|
||||
$store.commit("user/openId", openId);
|
||||
// token
|
||||
let token = uni.getStorageSync("user_access_token");
|
||||
let token = prototype.$storage.get("user_access_token");
|
||||
$store.commit('user/token', token);
|
||||
},
|
||||
/**
|
||||
|
@ -74,7 +74,7 @@ export default {
|
|||
*/
|
||||
info() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let cacheUser = uni.getStorageSync('userinfo');
|
||||
let cacheUser = prototype.$storage.get('userinfo');
|
||||
if (cacheUser) {
|
||||
return resolve(cacheUser);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ export default {
|
|||
mobile: response.data.mobile,
|
||||
create_time: response.data.create_time,
|
||||
};
|
||||
uni.setStorageSync('userinfo', user);
|
||||
prototype.$storage.set('userinfo', user);
|
||||
return resolve(user);
|
||||
} else {
|
||||
return reject(response.msg);
|
||||
|
@ -148,7 +148,7 @@ export default {
|
|||
}
|
||||
}).then(async response => {
|
||||
if (response.code == 1) {
|
||||
uni.setStorageSync('user_access_token', response.data.token);
|
||||
prototype.$storage.set('user_access_token', response.data.token);
|
||||
// 提交token到store
|
||||
await this.initUser();
|
||||
return resolve(response);
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import config from '@/core/config';
|
||||
|
||||
export default {
|
||||
prefix: config.storagePrefix,
|
||||
set(key, value) {
|
||||
uni.setStorageSync(this.prefix + key, value);
|
||||
},
|
||||
get(key) {
|
||||
return uni.getStorageSync(this.prefix + key);
|
||||
},
|
||||
remove(key) {
|
||||
uni.removeStorageSync(this.prefix + key);
|
||||
},
|
||||
clear(key, value) {
|
||||
uni.clearStorageSync();
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ import Vue from 'vue'
|
|||
import App from './App'
|
||||
|
||||
import store from "./store/index"
|
||||
import storage from './core/storage'
|
||||
import request from './core/request'
|
||||
import upload from './core/upload'
|
||||
import test from './core/libs/test'
|
||||
|
@ -14,6 +15,7 @@ import './static/iconfont/iconfont.css'
|
|||
|
||||
Vue.use({
|
||||
install(Vue, options) {
|
||||
Vue.prototype.$storage = storage
|
||||
Vue.prototype.$request = request
|
||||
Vue.prototype.$upload = upload
|
||||
Vue.prototype.$test = test
|
||||
|
|
Loading…
Reference in New Issue