58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
import { defineStore } from 'pinia';
|
||
import { computed,ref } from 'vue';
|
||
export const useCounterStore = defineStore('counter',()=>{
|
||
//定义数据(state)
|
||
const openId = ref('');
|
||
const nikeName = ref('');
|
||
const key = ref('');
|
||
const phone = ref('');
|
||
const uid = ref('');
|
||
const statusHeight = ref(uni.getMenuButtonBoundingClientRect()['height']);
|
||
const headerHeight = ref(uni.getSystemInfoSync()['statusBarHeight']);
|
||
const statusBartop = ref(uni.getMenuButtonBoundingClientRect()['top']);
|
||
const ButtonWidth = ref(uni.getMenuButtonBoundingClientRect().width);
|
||
const ButtonHeight = ref(uni.getMenuButtonBoundingClientRect().height)
|
||
const storeName = ref('');
|
||
const storeId = ref('');
|
||
const token = ref(uni.getStorageSync('token') || '');
|
||
const latitude = ref('');
|
||
const longitude = ref('');
|
||
const locationName = ref('正在获取定位');
|
||
const locationShow = ref(false);
|
||
const cartcount = ref(0)
|
||
// 设置 Token
|
||
const setToken = (tokens,uids,phones,nikeNames) => {
|
||
token.value = tokens;
|
||
uid.value = uids;
|
||
phone.value = phones;
|
||
nikeName.value = nikeNames;
|
||
uni.setStorageSync('token', tokens);
|
||
};
|
||
// 清除 Token
|
||
const clearToken = () => {
|
||
token.value = '';
|
||
uni.removeStorageSync('token');
|
||
};
|
||
//以对象的形式return供组件调用
|
||
return{
|
||
storeId,
|
||
storeName,
|
||
nikeName,
|
||
key,
|
||
token,
|
||
setToken,
|
||
clearToken,
|
||
phone,
|
||
uid,
|
||
ButtonWidth,
|
||
ButtonHeight,
|
||
statusHeight,
|
||
headerHeight,
|
||
statusBartop,
|
||
latitude,
|
||
longitude,
|
||
locationName,
|
||
locationShow,
|
||
cartcount
|
||
}
|
||
}) |