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