第一次提交
This commit is contained in:
285
utils/app.js
Executable file
285
utils/app.js
Executable file
@@ -0,0 +1,285 @@
|
||||
import store from '../store'
|
||||
import * as util from './util'
|
||||
import { paginate } from '@/common/constant'
|
||||
|
||||
/**
|
||||
* 显示成功提示框
|
||||
*/
|
||||
export const showSuccess = (msg, callback) => {
|
||||
uni.showToast({
|
||||
title: msg,
|
||||
icon: 'success',
|
||||
mask: true,
|
||||
duration: 1500,
|
||||
success() {
|
||||
callback && callback()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示失败提示框
|
||||
*/
|
||||
export const showError = (msg, callback) => {
|
||||
uni.showModal({
|
||||
title: '友情提示',
|
||||
content: msg,
|
||||
showCancel: false,
|
||||
success(res) {
|
||||
callback && callback()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示纯文字提示框
|
||||
*/
|
||||
export const showToast = (msg, duration = 1500) => {
|
||||
uni.showToast({
|
||||
title: msg,
|
||||
icon: 'none',
|
||||
duration
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* tabBar页面路径列表 (用于链接跳转时判断)
|
||||
* tabBarLinks为常量, 无需修改
|
||||
*/
|
||||
export const getTabBarLinks = () => {
|
||||
const tabBarLinks = [
|
||||
'pages/index/index',
|
||||
'pages/zone/zone',
|
||||
'pages/love/love',
|
||||
'pages/notice/notice',
|
||||
'pages/user/user'
|
||||
]
|
||||
return tabBarLinks
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成完整的H5地址 [带参数]
|
||||
* @param {string} baseUrl H5访问地址
|
||||
* @param {string} path 页面路径
|
||||
* @param {object} params 页面参数
|
||||
* @return {string}
|
||||
*/
|
||||
export const buildUrL = (h5Url, path, params) => {
|
||||
let complete = h5Url
|
||||
if (!util.isEmpty(path)) {
|
||||
complete += '#/' + path
|
||||
const shareParamsStr = getShareUrlParams(params)
|
||||
if (!util.isEmpty(shareParamsStr)) {
|
||||
complete += '?' + shareParamsStr
|
||||
}
|
||||
}
|
||||
return complete
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成转发的url参数(string格式)
|
||||
* @param {object} params
|
||||
* @return {string}
|
||||
*/
|
||||
export const getShareUrlParams = params => {
|
||||
return util.urlEncode(getShareParams(params))
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成转发的url参数(object格式)
|
||||
* @param {object} params
|
||||
* @return {object}
|
||||
*/
|
||||
export const getShareParams = params => {
|
||||
return {
|
||||
refereeId: store.getters.userId, // 推荐人ID
|
||||
...params
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到指定页面url
|
||||
* 支持tabBar页面
|
||||
* @param {string} url
|
||||
* @param {object} query
|
||||
*/
|
||||
export const navTo = (url, query = {}) => {
|
||||
if (!url || url.length == 0) {
|
||||
return false
|
||||
}
|
||||
// tabBar页面, 使用switchTab
|
||||
if (util.inArray(url, getTabBarLinks())) {
|
||||
uni.switchTab({
|
||||
url: `/${url}`
|
||||
})
|
||||
return true
|
||||
}
|
||||
// 生成query参数
|
||||
const queryStr = !util.isEmpty(query) ? '?' + util.urlEncode(query) : ''
|
||||
// 普通页面, 使用navigateTo
|
||||
uni.navigateTo({
|
||||
url: `/${url}${queryStr}`
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前页面数据
|
||||
* @param {object}
|
||||
*/
|
||||
export const getCurrentPage = () => {
|
||||
const pages = getCurrentPages()
|
||||
const { route, options } = pages[pages.length - 1]
|
||||
return { path: route, query: options }
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取购物车商品总数量
|
||||
* @param {*} value
|
||||
*/
|
||||
export const getCartTotalNum = (value) => {
|
||||
const cartTotal = uni.getStorageSync('cartTotalNum') || 0
|
||||
return checkLogin() ? cartTotal : 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录购物车商品总数量
|
||||
* @param {*} value
|
||||
*/
|
||||
export const setCartTotalNum = (value) => {
|
||||
uni.setStorageSync('cartTotalNum', Number(value))
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置购物车tabbar的角标
|
||||
* 该方法只能在tabbar页面中调用, 其他页面调用会报错
|
||||
*/
|
||||
export const setCartTabBadge = () => {
|
||||
const cartTabbarIndex = 2
|
||||
const cartTotal = getCartTotalNum()
|
||||
if (cartTotal > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: cartTabbarIndex,
|
||||
text: `${cartTotal}`
|
||||
})
|
||||
} else {
|
||||
uni.removeTabBarBadge({
|
||||
index: cartTabbarIndex
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否已登录
|
||||
*/
|
||||
export const checkLogin = () => {
|
||||
return !!store.getters.userId
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起支付请求
|
||||
* @param {Object} 参数
|
||||
*/
|
||||
export const wxPayment = (option) => {
|
||||
const options = {
|
||||
timeStamp: '',
|
||||
nonceStr: '',
|
||||
prepay_id: '',
|
||||
paySign: '',
|
||||
...option
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay',
|
||||
timeStamp: options.timeStamp,
|
||||
nonceStr: options.nonceStr,
|
||||
'package': `prepay_id=${options.prepay_id}`,
|
||||
signType: 'MD5',
|
||||
paySign: options.paySign,
|
||||
success: res => resolve(res),
|
||||
fail: res => reject(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载更多列表数据
|
||||
* @param {Object} resList 新列表数据
|
||||
* @param {Object} oldList 旧列表数据
|
||||
* @param {int} pageNo 当前页码
|
||||
*/
|
||||
export const getEmptyPaginateObj = () => {
|
||||
return util.cloneObj(paginate)
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载更多列表数据
|
||||
* @param {Object} resList 新列表数据
|
||||
* @param {Object} oldList 旧列表数据
|
||||
* @param {int} pageNo 当前页码
|
||||
*/
|
||||
export const getMoreListData = (resList, oldList, pageNo) => {
|
||||
// 如果是第一页需手动制空列表
|
||||
if (pageNo == 1) oldList.data = []
|
||||
// 合并新数据
|
||||
return oldList.data.concat(resList.data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前运行的终端(App H5 小程序)
|
||||
* https://uniapp.dcloud.io/platform
|
||||
*/
|
||||
export const getPlatform = () => {
|
||||
// #ifdef APP-PLUS
|
||||
const platform = 'App'
|
||||
// #endif
|
||||
// #ifdef APP-PLUS-NVUE
|
||||
const platform = 'App'
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
const platform = 'H5'
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
const platform = 'MP-WEIXIN'
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
const platform = 'MP-ALIPAY'
|
||||
// #endif
|
||||
// #ifdef MP-BAIDU
|
||||
const platform = 'MP-BAIDU'
|
||||
// #endif
|
||||
// #ifdef MP-TOUTIAO
|
||||
const platform = 'MP-TOUTIAO'
|
||||
// #endif
|
||||
// #ifdef MP-QQ
|
||||
const platform = 'MP-QQ'
|
||||
// #endif
|
||||
// #ifdef MP-360
|
||||
const platform = 'MP-360'
|
||||
// #endif
|
||||
return platform
|
||||
}
|
||||
|
||||
/**
|
||||
* scene解码
|
||||
* 用于解码微信小程序二维码参数,并返回对象
|
||||
*/
|
||||
export const sceneDecode = (str) => {
|
||||
if (str === undefined)
|
||||
return {}
|
||||
const data = {}
|
||||
const params = decodeURIComponent(str).split(',')
|
||||
for (const i in params) {
|
||||
const val = params[i].split(':');
|
||||
val.length > 0 && val[0] && (data[val[0]] = val[1] || null)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取二维码场景值(scene)
|
||||
*/
|
||||
export const getSceneData = (query) => {
|
||||
return query.scene ? sceneDecode(query.scene) : {}
|
||||
}
|
||||
67
utils/color.js
Executable file
67
utils/color.js
Executable file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 16进制转rgb
|
||||
* @param {String} color
|
||||
* @returns {String}
|
||||
*/
|
||||
export const hex2rgb = (color) => {
|
||||
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
|
||||
var sColor = color.toLowerCase()
|
||||
if (sColor && reg.test(sColor)) {
|
||||
if (sColor.length === 4) {
|
||||
var sColorNew = "#"
|
||||
for (var i = 1; i < 4; i += 1) {
|
||||
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1))
|
||||
}
|
||||
sColor = sColorNew
|
||||
}
|
||||
//处理六位的颜色值
|
||||
var sColorChange = [];
|
||||
for (var i = 1; i <= 6; i += 2) {
|
||||
sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
|
||||
}
|
||||
return "rgba(" + sColorChange.join(",") + ")"
|
||||
} else {
|
||||
return sColor
|
||||
}
|
||||
}
|
||||
|
||||
// rbg带透明度转16进制
|
||||
export const rgb2hex = (color) => {
|
||||
var values = color
|
||||
.replace(/rgba?\(/, '')
|
||||
.replace(/\)/, '')
|
||||
.replace(/[\s+]/g, '')
|
||||
.split(',')
|
||||
var a = parseFloat(values[3] || 1),
|
||||
r = Math.floor(a * parseInt(values[0]) + (1 - a) * 255),
|
||||
g = Math.floor(a * parseInt(values[1]) + (1 - a) * 255),
|
||||
b = Math.floor(a * parseInt(values[2]) + (1 - a) * 255);
|
||||
return "#" +
|
||||
("0" + r.toString(16)).slice(-2) +
|
||||
("0" + g.toString(16)).slice(-2) +
|
||||
("0" + b.toString(16)).slice(-2)
|
||||
}
|
||||
|
||||
// 16进制转换rgb,并设置透明度
|
||||
export const hex2rgba = (color, opacity) => {
|
||||
var theColor = color.toLowerCase()
|
||||
//十六进制颜色值的正则表达式
|
||||
var r = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
|
||||
// 如果是16进制颜色
|
||||
if (theColor && r.test(theColor)) {
|
||||
if (theColor.length === 4) {
|
||||
var sColorNew = "#"
|
||||
for (var i = 1; i < 4; i += 1) {
|
||||
sColorNew += theColor.slice(i, i + 1).concat(theColor.slice(i, i + 1))
|
||||
}
|
||||
theColor = sColorNew
|
||||
}
|
||||
//处理六位的颜色值
|
||||
var sColorChange = []
|
||||
for (var i = 1; i < 7; i += 2) {
|
||||
sColorChange.push(parseInt("0x" + theColor.slice(i, i + 2)))
|
||||
}
|
||||
return "rgba(" + sColorChange.join(",") + "," + opacity + ")"
|
||||
}
|
||||
return theColor
|
||||
}
|
||||
346
utils/iconfont.scss
Executable file
346
utils/iconfont.scss
Executable file
@@ -0,0 +1,346 @@
|
||||
@font-face {
|
||||
font-family: "iconfont"; /* Project id 2282770 */
|
||||
src: url('https://at.alicdn.com/t/font_2282770_p9nx0bv86i.woff2?t=1649761463203') format('woff2'),
|
||||
url('https://at.alicdn.com/t/font_2282770_p9nx0bv86i.woff?t=1649761463203') format('woff'),
|
||||
url('https://at.alicdn.com/t/font_2282770_p9nx0bv86i.ttf?t=1649761463203') format('truetype'),
|
||||
url('https://at.alicdn.com/t/font_2282770_p9nx0bv86i.svg?t=1649761463203#iconfont') format('svg');
|
||||
}
|
||||
|
||||
.iconfont {
|
||||
font-family: "iconfont" !important;
|
||||
font-style: normal;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
.icon-jiagou3:before {
|
||||
content: "\e69c";
|
||||
}
|
||||
|
||||
.icon-jiagou2:before {
|
||||
content: "\e602";
|
||||
}
|
||||
|
||||
.icon-jiagou1:before {
|
||||
content: "\e626";
|
||||
}
|
||||
|
||||
.icon-youhuiquan:before {
|
||||
content: "\e672";
|
||||
}
|
||||
|
||||
.icon-fenxiao:before {
|
||||
content: "\e70e";
|
||||
}
|
||||
|
||||
.icon-kanjia:before {
|
||||
content: "\e735";
|
||||
}
|
||||
|
||||
.icon-pintuan:before {
|
||||
content: "\e671";
|
||||
}
|
||||
|
||||
.icon-alipay:before {
|
||||
content: "\e6d3";
|
||||
}
|
||||
|
||||
.icon-balance-pay:before {
|
||||
content: "\e6d4";
|
||||
}
|
||||
|
||||
.icon-wechat-pay:before {
|
||||
content: "\e6d5";
|
||||
}
|
||||
|
||||
.icon-poster:before {
|
||||
content: "\e61a";
|
||||
}
|
||||
|
||||
.icon-weixin:before {
|
||||
content: "\e60e";
|
||||
}
|
||||
|
||||
.icon-qzone:before {
|
||||
content: "\e642";
|
||||
}
|
||||
|
||||
.icon-link:before {
|
||||
content: "\e613";
|
||||
}
|
||||
|
||||
.icon-weibo:before {
|
||||
content: "\e62a";
|
||||
}
|
||||
|
||||
.icon-qq:before {
|
||||
content: "\e612";
|
||||
}
|
||||
|
||||
.icon-timeline:before {
|
||||
content: "\e812";
|
||||
}
|
||||
|
||||
.icon-fenxiao1:before {
|
||||
content: "\e606";
|
||||
}
|
||||
|
||||
.icon-delete:before {
|
||||
content: "\e668";
|
||||
}
|
||||
|
||||
.icon-edit:before {
|
||||
content: "\e7f8";
|
||||
}
|
||||
|
||||
.icon-daifukuan:before {
|
||||
content: "\e65c";
|
||||
}
|
||||
|
||||
.icon-qpdingdan:before {
|
||||
content: "\e667";
|
||||
}
|
||||
|
||||
.icon-daifahuo:before {
|
||||
content: "\e60c";
|
||||
}
|
||||
|
||||
.icon-daishouhuo:before {
|
||||
content: "\e771";
|
||||
}
|
||||
|
||||
.icon-jifen:before {
|
||||
content: "\e628";
|
||||
}
|
||||
|
||||
.icon-shouhou:before {
|
||||
content: "\e788";
|
||||
}
|
||||
|
||||
.icon-shouhuodizhi:before {
|
||||
content: "\e67e";
|
||||
}
|
||||
|
||||
.icon-kefu:before {
|
||||
content: "\e654";
|
||||
}
|
||||
|
||||
.icon-lingquan:before {
|
||||
content: "\e60b";
|
||||
}
|
||||
|
||||
.icon-bangzhu:before {
|
||||
content: "\e63a";
|
||||
}
|
||||
|
||||
.icon-bianji:before {
|
||||
content: "\e6a4";
|
||||
}
|
||||
|
||||
.icon-fuwu:before {
|
||||
content: "\e732";
|
||||
}
|
||||
|
||||
.icon-gouwuche:before {
|
||||
content: "\e61b";
|
||||
}
|
||||
|
||||
.icon-view-tile:before {
|
||||
content: "\e6c8";
|
||||
}
|
||||
|
||||
.icon-view-list:before {
|
||||
content: "\e637";
|
||||
}
|
||||
|
||||
.icon-arrow-down:before {
|
||||
content: "\e603";
|
||||
}
|
||||
|
||||
.icon-arrow-up:before {
|
||||
content: "\e604";
|
||||
}
|
||||
|
||||
.icon-cart:before {
|
||||
content: "\e68c";
|
||||
}
|
||||
|
||||
.icon-chaping:before {
|
||||
content: "\e68f";
|
||||
}
|
||||
|
||||
.icon-dingwei:before {
|
||||
content: "\e698";
|
||||
}
|
||||
|
||||
.icon-fanhuidingbu:before {
|
||||
content: "\e69b";
|
||||
}
|
||||
|
||||
.icon-haoping:before {
|
||||
content: "\e6a5";
|
||||
}
|
||||
|
||||
.icon-home:before {
|
||||
content: "\e6a6";
|
||||
}
|
||||
|
||||
.icon-help:before {
|
||||
content: "\e6a7";
|
||||
}
|
||||
|
||||
.icon-iconxx:before {
|
||||
content: "\e6ae";
|
||||
}
|
||||
|
||||
.icon-profile:before {
|
||||
content: "\e6b6";
|
||||
}
|
||||
|
||||
.icon-shanchu:before {
|
||||
content: "\e6b7";
|
||||
}
|
||||
|
||||
.icon-search:before {
|
||||
content: "\e6bf";
|
||||
}
|
||||
|
||||
.icon-camera:before {
|
||||
content: "\e6c4";
|
||||
}
|
||||
|
||||
.icon-arrow-right:before {
|
||||
content: "\e6cb";
|
||||
}
|
||||
|
||||
.icon-x:before {
|
||||
content: "\e6cc";
|
||||
}
|
||||
|
||||
.icon-wushuju:before {
|
||||
content: "\e6ce";
|
||||
}
|
||||
|
||||
.icon-zhongping:before {
|
||||
content: "\e6d9";
|
||||
}
|
||||
|
||||
.icon-radio:before {
|
||||
content: "\e600";
|
||||
}
|
||||
|
||||
.icon-dingdan:before {
|
||||
content: "\e60f";
|
||||
}
|
||||
|
||||
.icon-erweima:before {
|
||||
content: "\e601";
|
||||
}
|
||||
|
||||
.icon-tuandui:before {
|
||||
content: "\e6d1";
|
||||
}
|
||||
|
||||
.icon-zhangben:before {
|
||||
content: "\ea2c";
|
||||
}
|
||||
|
||||
.icon-shenhezhong:before {
|
||||
content: "\e723";
|
||||
}
|
||||
|
||||
.icon-fenxiang:before {
|
||||
content: "\e63e";
|
||||
}
|
||||
|
||||
.icon-wenhao:before {
|
||||
content: "\e69f";
|
||||
}
|
||||
|
||||
.icon-shibai:before {
|
||||
content: "\e6b5";
|
||||
}
|
||||
|
||||
.icon-success:before {
|
||||
content: "\e644";
|
||||
}
|
||||
|
||||
.icon-pintuan_huaban:before {
|
||||
content: "\e6c3";
|
||||
}
|
||||
|
||||
.icon-cate:before {
|
||||
content: "\e6c7";
|
||||
}
|
||||
|
||||
.icon-daohang:before {
|
||||
content: "\e650";
|
||||
}
|
||||
|
||||
.icon-check1:before {
|
||||
content: "\e609";
|
||||
}
|
||||
|
||||
.icon-check:before {
|
||||
content: "\e60a";
|
||||
}
|
||||
|
||||
.icon-locate:before {
|
||||
content: "\e652";
|
||||
}
|
||||
|
||||
.icon-dianhua:before {
|
||||
content: "\e670";
|
||||
}
|
||||
|
||||
.icon-shijian:before {
|
||||
content: "\e661";
|
||||
}
|
||||
|
||||
.icon-qr-extract:before {
|
||||
content: "\e635";
|
||||
}
|
||||
|
||||
.icon-qianbao:before {
|
||||
content: "\e632";
|
||||
}
|
||||
|
||||
.icon-shangcheng:before {
|
||||
content: "\e605";
|
||||
}
|
||||
|
||||
.icon-sy-yh:before {
|
||||
content: "\e7b1";
|
||||
}
|
||||
|
||||
.icon-naozhong:before {
|
||||
content: "\e76e";
|
||||
}
|
||||
|
||||
.icon-shouye:before {
|
||||
content: "\e73d";
|
||||
}
|
||||
|
||||
.icon-kefu1:before {
|
||||
content: "\e75c";
|
||||
}
|
||||
|
||||
.icon-artboard:before {
|
||||
content: "\e7b5";
|
||||
}
|
||||
|
||||
.icon-miaosha-b:before {
|
||||
content: "\e646";
|
||||
}
|
||||
|
||||
.icon-shijian-s:before {
|
||||
content: "\e6eb";
|
||||
}
|
||||
|
||||
.icon-shipin:before {
|
||||
content: "\e67d";
|
||||
}
|
||||
|
||||
.icon-zhibozhong:before {
|
||||
content: "\e837";
|
||||
}
|
||||
86
utils/storage.js
Executable file
86
utils/storage.js
Executable file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* 缓存数据优化
|
||||
* const storage = require('@/utils/storage');
|
||||
* import storage from '@/utils/storage'
|
||||
* 使用方法 【
|
||||
* 一、设置缓存
|
||||
* string storage.set('k', 'string你好啊');
|
||||
* json storage.set('k', { "b": "3" }, 2);
|
||||
* array storage.set('k', [1, 2, 3]);
|
||||
* boolean storage.set('k', true);
|
||||
* 二、读取缓存
|
||||
* 默认值 storage.get('k')
|
||||
* string storage.get('k', '你好')
|
||||
* json storage.get('k', { "a": "1" })
|
||||
* 三、移除/清理
|
||||
* 移除: storage.remove('k');
|
||||
* 清理:storage.clear();
|
||||
* 】
|
||||
* @type {String}
|
||||
*/
|
||||
|
||||
const postfix = '_expiry' // 缓存有效期后缀
|
||||
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
* 设置缓存
|
||||
* @param {[type]} k [键名]
|
||||
* @param {[type]} v [键值]
|
||||
* @param {[type]} t [时间、单位秒]
|
||||
*/
|
||||
set(k, v, t) {
|
||||
uni.setStorageSync(k, v)
|
||||
const seconds = parseInt(t)
|
||||
if (seconds > 0) {
|
||||
let timestamp = Date.parse(new Date())
|
||||
timestamp = timestamp / 1000 + seconds
|
||||
uni.setStorageSync(k + postfix, timestamp + '')
|
||||
} else {
|
||||
uni.removeStorageSync(k + postfix)
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取缓存
|
||||
* @param {[type]} k [键名]
|
||||
* @param {[type]} def [获取为空时默认]
|
||||
*/
|
||||
get(k, def) {
|
||||
const deadtime = parseInt(uni.getStorageSync(k + postfix))
|
||||
if (deadtime) {
|
||||
if (parseInt(deadtime) < Date.parse(new Date()) / 1000) {
|
||||
if (def) {
|
||||
return def
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
const res = uni.getStorageSync(k)
|
||||
if (res) {
|
||||
return res
|
||||
}
|
||||
if (def == undefined || def == "") {
|
||||
def = false
|
||||
}
|
||||
return def
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除指定缓存
|
||||
* @param {Object} k
|
||||
*/
|
||||
remove(k) {
|
||||
uni.removeStorageSync(k)
|
||||
uni.removeStorageSync(k + postfix)
|
||||
},
|
||||
|
||||
/**
|
||||
* 清理所有缓存
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
clear() {
|
||||
uni.clearStorageSync()
|
||||
}
|
||||
}
|
||||
330
utils/util.js
Executable file
330
utils/util.js
Executable file
@@ -0,0 +1,330 @@
|
||||
import md5 from 'js-md5';
|
||||
import {
|
||||
fileUrl
|
||||
} from '@/config.js';
|
||||
/**
|
||||
* 格式化日期格式 (用于兼容ios Date对象)
|
||||
*/
|
||||
export const formatDate = (time) => {
|
||||
// 将xxxx-xx-xx的时间格式,转换为 xxxx/xx/xx的格式
|
||||
return time.replace(/\-/g, "/");
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转URL参数
|
||||
* @param {object} obj
|
||||
* @return {string}
|
||||
*/
|
||||
export const urlEncode = (obj = {}) => {
|
||||
const result = []
|
||||
for (const key in obj) {
|
||||
const item = obj[key]
|
||||
if (!item) {
|
||||
continue
|
||||
}
|
||||
if (isArray(item)) {
|
||||
item.forEach(val => {
|
||||
result.push(key + '=' + val)
|
||||
})
|
||||
} else {
|
||||
result.push(key + '=' + item)
|
||||
}
|
||||
}
|
||||
return result.join('&')
|
||||
}
|
||||
|
||||
/**
|
||||
* URL参数转对象
|
||||
* @param {string} queryStr
|
||||
* @return {object}
|
||||
*/
|
||||
export const urlDecode = (queryStr = '') => {
|
||||
var newObj = new Object()
|
||||
if (queryStr) {
|
||||
var strs = queryStr.split("&")
|
||||
for (var i = 0; i < strs.length; i++) {
|
||||
newObj[strs[i].split("=")[0]] = (strs[i].split("=")[1]) || ''
|
||||
}
|
||||
}
|
||||
return newObj
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历对象
|
||||
*/
|
||||
export const objForEach = (obj, callback) => {
|
||||
Object.keys(obj).forEach((key) => {
|
||||
callback(obj[key], key)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否在数组内
|
||||
*/
|
||||
export const inArray = (search, array) => {
|
||||
for (var i in array) {
|
||||
if (array[i] == search) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 对Date的扩展,将 Date 转化为指定格式的String
|
||||
* 月(Y)、月(m)、日(d)、小时(H)、分(M)、秒(S) 可以用 1-2 个占位符,
|
||||
* 例子:
|
||||
* dateFormat('YYYY-mm-dd HH:MM:SS', new Date()) ==> 2020-01-01 08:00:00
|
||||
*/
|
||||
export const dateFormat = (fmt, date) => {
|
||||
const opt = {
|
||||
"Y+": date.getFullYear().toString(), // 年
|
||||
"m+": (date.getMonth() + 1).toString(), // 月
|
||||
"d+": date.getDate().toString(), // 日
|
||||
"H+": date.getHours().toString(), // 时
|
||||
"M+": date.getMinutes().toString(), // 分
|
||||
"S+": date.getSeconds().toString() // 秒
|
||||
// 有其他格式化字符需求可以继续添加,必须转化成字符串
|
||||
};
|
||||
let ret
|
||||
for (let k in opt) {
|
||||
ret = new RegExp("(" + k + ")").exec(fmt)
|
||||
if (ret) {
|
||||
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
|
||||
};
|
||||
};
|
||||
return fmt
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为空对象
|
||||
* @param {*} object 源对象
|
||||
*/
|
||||
export const isEmptyObject = (object) => {
|
||||
return Object.keys(object).length === 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为对象
|
||||
* @param {*} object
|
||||
*/
|
||||
export const isObject = (object) => {
|
||||
return Object.prototype.toString.call(object) === '[object Object]'
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为数组
|
||||
* @param {*} array
|
||||
*/
|
||||
export const isArray = (array) => {
|
||||
return Object.prototype.toString.call(array) === '[object Array]'
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为空
|
||||
* @param {*} object 源对象
|
||||
*/
|
||||
export const isEmpty = (value) => {
|
||||
if (isArray(value)) {
|
||||
return value.length === 0
|
||||
}
|
||||
if (isObject(value)) {
|
||||
return isEmptyObject(value)
|
||||
}
|
||||
return !value
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象深拷贝
|
||||
* @param {*} obj 源对象
|
||||
*/
|
||||
export const cloneObj = (obj) => {
|
||||
let newObj = isArray(obj) ? [] : {};
|
||||
if (typeof obj !== 'object') {
|
||||
return;
|
||||
}
|
||||
for (let i in obj) {
|
||||
newObj[i] = typeof obj[i] === 'object' ? cloneObj(obj[i]) : obj[i];
|
||||
}
|
||||
return newObj
|
||||
}
|
||||
|
||||
// 节流函数
|
||||
// 思路: 第一次先设定一个变量true,
|
||||
// 第二次执行这个函数时,会判断变量是否true,
|
||||
// 是则返回。当第一次的定时器执行完函数最后会设定变量为flase。
|
||||
// 那么下次判断变量时则为flase,函数会依次运行。
|
||||
export function throttle(fn, delay = 100) {
|
||||
// 首先设定一个变量,在没有执行我们的定时器时为null
|
||||
var timer = null
|
||||
return function() {
|
||||
// 当我们发现这个定时器存在时,则表示定时器已经在运行中,需要返回
|
||||
if (timer) return
|
||||
timer = setTimeout(() => {
|
||||
fn.apply(this, arguments)
|
||||
timer = null
|
||||
}, delay)
|
||||
}
|
||||
}
|
||||
|
||||
// 防抖函数
|
||||
// 首次运行时把定时器赋值给一个变量, 第二次执行时,
|
||||
// 如果间隔没超过定时器设定的时间则会清除掉定时器,
|
||||
// 重新设定定时器, 依次反复, 当我们停止下来时,
|
||||
// 没有执行清除定时器, 超过一定时间后触发回调函数。
|
||||
// 参考文档:https://segmentfault.com/q/1010000021145192
|
||||
export function debounce(fn, delay = 100) {
|
||||
let timer
|
||||
return function() {
|
||||
const that = this
|
||||
const _args = arguments // 存一下传入的参数
|
||||
if (timer) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
timer = setTimeout(function() {
|
||||
fn.apply(that, _args)
|
||||
}, delay)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数组交集
|
||||
* @param {Array} 数组1
|
||||
* @param {Array} 数组2
|
||||
* @return {Array}
|
||||
*/
|
||||
export const arrayIntersect = (array1, array2) => {
|
||||
return array1.filter(val => array2.indexOf(val) > -1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前客户端的rpx比值
|
||||
* @return {Number}
|
||||
*/
|
||||
export const rpx = () => {
|
||||
const {
|
||||
windowWidth
|
||||
} = uni.getSystemInfoSync()
|
||||
// #ifdef H5
|
||||
// 与pages.json文件中的 rpxCalcMaxDeviceWidth参数对应, 请勿修改
|
||||
const rpxCalcMaxDeviceWidth = 750
|
||||
// 与pages.json文件中的 rpxCalcBaseDeviceWidth参数对应, 请勿修改
|
||||
const rpxCalcBaseDeviceWidth = 560
|
||||
const calcWindowWidth = windowWidth > rpxCalcMaxDeviceWidth ? rpxCalcBaseDeviceWidth : windowWidth
|
||||
return calcWindowWidth / 750
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
return windowWidth / 750
|
||||
// #endif
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前客户端的rpx比值
|
||||
* @return {Number}
|
||||
*/
|
||||
export const rpx2px = (num) => {
|
||||
return num * rpx()
|
||||
}
|
||||
|
||||
// 生成订单编号
|
||||
export function createOrderNo() {
|
||||
const data = new Date();
|
||||
return `${data.getFullYear()}${data.getMonth()}${data.getDate()}${data.getHours()}${data.getMilliseconds()}${uni.$u.random(800, 12000)}`;
|
||||
}
|
||||
|
||||
|
||||
// 封装签名
|
||||
export function getSign(form, appSecret) {
|
||||
if (form == null) {
|
||||
return false;
|
||||
}
|
||||
let sign = '';
|
||||
form.timestamp = new Date().getTime();
|
||||
// form.version = 'v3';
|
||||
const arr = objKeySort(form);
|
||||
Object.keys(arr).forEach((k) => {
|
||||
if (form[k] != null && form[k] != '') {
|
||||
sign = sign.concat(form[k]).concat('-');
|
||||
}
|
||||
});
|
||||
sign = sign.concat(appSecret);
|
||||
console.log("md5加密前的字符串: ", sign);
|
||||
return md5(sign);
|
||||
}
|
||||
|
||||
// 参数按照字母顺序排序
|
||||
export const objKeySort = (obj) => {
|
||||
//排序的函数
|
||||
const newkey = Object.keys(obj).sort();
|
||||
//先用Object内置类的keys方法获取要排序对象的属性名,再利用Array原型上的sort方法对获取的属性名进行排序,newkey是一个数组
|
||||
const newObj = {}; //创建一个新的对象,用于存放排好序的键值对
|
||||
for (let i = 0; i < newkey.length; i++) {
|
||||
//遍历newkey数组
|
||||
newObj[newkey[i]] = obj[newkey[i]]; //向新创建的对象中按照排好的顺序依次增加键值对
|
||||
}
|
||||
return newObj; //返回排好序的新对象
|
||||
};
|
||||
|
||||
export const getWeek = (text) => {
|
||||
const week = [
|
||||
'星期日',
|
||||
'星期一',
|
||||
'星期二',
|
||||
'星期三',
|
||||
'星期四',
|
||||
'星期五',
|
||||
'星期六'
|
||||
];
|
||||
return week[text];
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取输入内容的长度
|
||||
* @param value
|
||||
* @return 内容的长度
|
||||
*/
|
||||
export const getInputSize = (value) => {
|
||||
if (!value) {
|
||||
return 0
|
||||
}
|
||||
const charCount = value.split('').reduce((prev, curr) => {
|
||||
// 英文字母和数字等算一个字符;这个暂时还不完善;
|
||||
if (/[a-z]|[0-9]|[,;.!@#-+/\\$%^*()<>?:"'{}~]/i.test(curr)) {
|
||||
return prev + 1
|
||||
}
|
||||
// 其他的算是2个字符
|
||||
return prev + 2
|
||||
}, 0)
|
||||
|
||||
// 向上取整,防止出现半个字的情况
|
||||
const count = Math.ceil(charCount / 2)
|
||||
// 省略超出部分,显示’… 详情>>’
|
||||
if (count < 25) {
|
||||
return value
|
||||
}
|
||||
return value
|
||||
|
||||
// return Math.ceil(charCount / 2)
|
||||
}
|
||||
|
||||
/* 获取缩列图地址 */
|
||||
export const thumbnail = (url) => {
|
||||
if (url.indexOf('/thumbnail/') < 0) {
|
||||
return url.replace(fileUrl, fileUrl + '/thumbnail');
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
/* 获取预览图地址 */
|
||||
export const thumb = (url) => {
|
||||
if (url.indexOf('/thumb/') < 0) {
|
||||
return url.replace(fileUrl, fileUrl + '/thumb');
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
/* 获取原图地址 */
|
||||
export const original = (url) => {
|
||||
if (url.indexOf('/thumbnail/') > -1) {
|
||||
return url.replace('/thumbnail/', '/');
|
||||
}
|
||||
return url;
|
||||
};
|
||||
340
utils/utils.scss
Executable file
340
utils/utils.scss
Executable file
@@ -0,0 +1,340 @@
|
||||
.container, input {
|
||||
font-family: PingFang-Medium,
|
||||
PingFangSC-Regular,
|
||||
Heiti,
|
||||
Heiti SC,
|
||||
DroidSans,
|
||||
DroidSansFallback,
|
||||
"Microsoft YaHei",
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
.b-f {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.tf-180 {
|
||||
transform: rotate(-180deg);
|
||||
}
|
||||
|
||||
.tf-90 {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.dis-block {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.dis-flex {
|
||||
display: flex !important;
|
||||
/* flex-wrap: wrap; */
|
||||
}
|
||||
|
||||
.flex-box {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.flex-dir-row {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.flex-dir-column {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.flex-x-center {
|
||||
/* display: flex; */
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.flex-x-between {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.flex-x-around {
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.flex-x-end {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.flex-y-center {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.flex-y-end {
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.flex-five {
|
||||
box-sizing: border-box;
|
||||
flex: 0 0 50%;
|
||||
}
|
||||
|
||||
.flex-three {
|
||||
float: left;
|
||||
width: 33.3%;
|
||||
}
|
||||
|
||||
.flex-four {
|
||||
box-sizing: border-box;
|
||||
flex: 0 0 25%;
|
||||
}
|
||||
|
||||
.t-l {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.t-c {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.t-r {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.p-a {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.p-r {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.fl {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.fr {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.clearfix::after {
|
||||
clear: both;
|
||||
content: " ";
|
||||
display: table;
|
||||
}
|
||||
|
||||
.f-36 {
|
||||
font-size: 36rpx;
|
||||
}
|
||||
|
||||
.f-34 {
|
||||
font-size: 34rpx;
|
||||
}
|
||||
|
||||
.f-32 {
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.f-31 {
|
||||
font-size: 31rpx;
|
||||
}
|
||||
|
||||
.f-30 {
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
.f-29 {
|
||||
font-size: 29rpx;
|
||||
}
|
||||
|
||||
.f-28 {
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.f-26 {
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.f-25 {
|
||||
font-size: 25rpx;
|
||||
}
|
||||
|
||||
.f-24 {
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.f-22 {
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.col-f {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.col-3 {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.col-6 {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.col-7 {
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.col-8 {
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.col-9 {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.col-m {
|
||||
color: $main-bg !important;
|
||||
}
|
||||
|
||||
.col-s {
|
||||
color: #be0117 !important;
|
||||
}
|
||||
|
||||
.col-green {
|
||||
color: #0ed339 !important;
|
||||
}
|
||||
|
||||
.cont-box {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.cont-bot {
|
||||
margin-bottom: 120rpx;
|
||||
}
|
||||
|
||||
.padding-box {
|
||||
padding: 0 24rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.pl-12 {
|
||||
padding-left: 12px;
|
||||
}
|
||||
|
||||
.pr-12 {
|
||||
padding-right: 12px;
|
||||
}
|
||||
|
||||
.pr-6 {
|
||||
padding-right: 6px;
|
||||
}
|
||||
|
||||
.m-top4 {
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
|
||||
.m-top10 {
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
|
||||
.m-top20 {
|
||||
margin-top: 25rpx;
|
||||
}
|
||||
|
||||
.m-top30 {
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
.m-l-10 {
|
||||
margin-left: 10rpx;
|
||||
}
|
||||
|
||||
.m-l-20 {
|
||||
margin-left: 20rpx;
|
||||
}
|
||||
|
||||
.m-r-6 {
|
||||
margin-right: 6rpx;
|
||||
}
|
||||
|
||||
.m-r-10 {
|
||||
margin-right: 10rpx;
|
||||
}
|
||||
|
||||
.p-bottom {
|
||||
padding-bottom: 112rpx;
|
||||
}
|
||||
|
||||
.oneline-hide {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.twoline-hide {
|
||||
display: -webkit-box;
|
||||
word-break: break-all;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
}
|
||||
|
||||
.b-r {
|
||||
border-right: 1rpx solid #eee;
|
||||
}
|
||||
|
||||
.b-b {
|
||||
border-bottom: 1rpx solid #eee;
|
||||
}
|
||||
|
||||
.b-t {
|
||||
border-top: 1rpx solid #eee;
|
||||
}
|
||||
|
||||
.ts-1 {
|
||||
-moz-transition: all 0.1s;
|
||||
-o-transition: all 0.1s;
|
||||
transition: all 0.1s;
|
||||
}
|
||||
|
||||
.ts-2 {
|
||||
-moz-transition: all 0.2s;
|
||||
-o-transition: all 0.2s;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.ts-3 {
|
||||
-moz-transition: all 0.3s;
|
||||
-o-transition: all 0.3s;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.ts-5 {
|
||||
-moz-transition: all 0.5s;
|
||||
-o-transition: all 0.5s;
|
||||
transition: all 0.5s;
|
||||
}
|
||||
|
||||
/* 无样式button (用于伪submit) */
|
||||
|
||||
.btn-normal {
|
||||
display: block;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
line-height: normal;
|
||||
background: none;
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
border: none;
|
||||
font-size: unset;
|
||||
text-align: unset;
|
||||
overflow: visible;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.btn-normal:after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.btn-normal.button-hover {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
button:after {
|
||||
content: none;
|
||||
border: none;
|
||||
}
|
||||
69
utils/verify.js
Executable file
69
utils/verify.js
Executable file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 用户输入内容验证类
|
||||
*/
|
||||
|
||||
// 是否为空
|
||||
export const isEmpty = (str) => {
|
||||
return str.trim() == ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配phone
|
||||
*/
|
||||
export const isPhone = (str) => {
|
||||
const reg = /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/
|
||||
return reg.test(str)
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配phone
|
||||
*/
|
||||
export const isMobile = (str) => {
|
||||
const reg = /^(1[3456789]\d{9})$/
|
||||
return reg.test(str)
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配Email地址
|
||||
*/
|
||||
export const isEmail = (str) => {
|
||||
if (str == null || str == "") return false
|
||||
var result = str.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)
|
||||
if (result == null) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断数值类型,包括整数和浮点数
|
||||
*/
|
||||
export const isNumber = (str) => {
|
||||
if (isDouble(str) || isInteger(str)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为正整数(只能输入数字[0-9])
|
||||
*/
|
||||
export const isPositiveInteger = (str) => {
|
||||
return /(^[0-9]\d*$)/.test(str)
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配integer
|
||||
*/
|
||||
export const isInteger = (str) => {
|
||||
if (str == null || str == "") return false
|
||||
var result = str.match(/^[-\+]?\d+$/)
|
||||
if (result == null) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配double或float
|
||||
*/
|
||||
export const isDouble = (str) => {
|
||||
if (str == null || str == "") return false
|
||||
var result = str.match(/^[-\+]?\d+(\.\d+)?$/)
|
||||
if (result == null) return false
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user