| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- import $C from './config.js'
- const {
- brandId,
- branchId
- } = uni.getStorageSync('brandInfo')
- export default {
- // 获取存储列表数据
- getStorage(key) {
- // let data = null;
- // // #ifdef H5
- // if($C.env === 'dev'){
- // data = window.sessionStorage.getItem(key)
- // } else {
- // data = uni.getStorageSync(key)
- // }
- // // #endif
- // // #ifndef H5
- // data = uni.getStorageSync(key)
- // // #endif
- return uni.getStorageSync(key)
- },
- // 设置存储
- setStorage(key, data) {
- // // #ifdef H5
- // if($C.env === 'dev'){
- // return window.sessionStorage.setItem(key,data)
- // } else {
- // return uni.setStorageSync(key,data)
- // }
- // // #endif
- // // #ifndef H5
- return uni.setStorageSync(key, data)
- // // #endif
- },
- // 删除存储
- removeStorage(key) {
- // // #ifdef H5
- // if($C.env === 'dev'){
- // return window.sessionStorage.removeItem(key);
- // } else {
- // return uni.removeStorageSync(key)
- // }
- // // #endif
- // // #ifndef H5
- return uni.removeStorageSync(key)
- // // #endif
- },
- setUserInfo(userInfoData) {
- // console.log(userInfoData);
- var userInfoStr = uni.setStorageSync("userInfo", JSON.stringify(userInfoData))
- console.log(userInfoStr);
- },
- getUserInfo() {
- var userInfoData = uni.getStorageSync(`userInfo_${brandId}`);
- return userInfoData;
- },
- getConfigName(data, key, value, nameKey) {
- if (Array.isArray(data)) {
- let result = data.find(item => item[key] == value)
- return result && result[nameKey] || ''
- }
- },
- getDataName(key) {
- console.log(9000, key, `${key}_${brandId}_${branchId}`)
- return `${key}_${brandId}_${branchId}`
- },
- /**
- * 获取当前页面路由
- * @param index
- * @returns {(() => void)|null}
- */
- getCurrentPageRoute(index=0) {
- const pages = getCurrentPages();
- if (pages.length === 0) return null;
- return pages[pages.length - 1-index].route; // 不带 /
- }
- ,
- /**
- * 判断当前页面是否是指定页面
- * @param pagePath
- * @returns {boolean}
- */
- isCurrentPage(pagePath) {
- const current = this.getCurrentPageRoute();
- return current === pagePath;
- },
- /**
- * 获取当前页面参数
- * @param index
- * @returns {{}|*|null}
- */
- getCurrentPageOptions(index) {
- const pages = getCurrentPages();
- if (pages.length === 0) return null;
- const currentPage = pages[pages.length - 1-index]; // 当前页面实例
- // 小程序 & App 平台:参数在 options 属性上
- if (currentPage.options) {
- return currentPage.options;
- }
- // H5 可能需要从 $page 取(uni-app 特有)
- if (currentPage.$page && currentPage.$page.options) {
- return currentPage.$page.options;
- }
- // 兜底:尝试 onLoad 时传入的参数(部分平台)
- return {};
- },
- /**
- * 获取上一页完整路径
- * @returns {string|null}
- */
- getPrevPageFullUrl() {
- const pages = getCurrentPages();
- let str=""
- pages.forEach(
- (page, index) => {
- str += page.route
- }
- )
- // 至少要有两个页面(当前页 + 上一页)
- if (pages.length < 2) {
- return null;
- }
- const prevPage = pages[pages.length - 2]; // 上一页(倒数第二个)
- const route = prevPage.route; // 页面路径,如 'pages/detail/detail'
- const options = prevPage.options || {}; // 参数对象,如 { id: '123' }
- if (!route) return null;
- // 拼接查询字符串
- const queryStr = Object.keys(options)
- .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(options[key])}`)
- .join('&');
- return `/${route}${queryStr ? '?' + queryStr : ''}`;
- }
- }
|