本次提交主要包含以下内容: 1. 新增积分申请系统核心功能: - 添加登录页面及API接口 - 实现积分申请记录查看功能 - 集成微信小程序分享功能 - 添加请求管理工具类 2. 引入Tuniao UI组件库: - 添加时间线、折叠面板、表格等UI组件 - 集成头像组、单选框组等交互组件 - 配置全局样式和主题颜色 3. 基础架构搭建: - 配置项目manifest和pages.json路由 - 添加状态管理store - 实现自定义导航栏适配 - 添加工具函数(加解密、数字处理等) 4. 静态资源: - 添加项目logo和背景图片 - 配置uni.scss全局样式变量 本次提交为系统基础功能搭建,后续将进一步完善积分申请流程和审批功能。
128 lines
2.6 KiB
JavaScript
128 lines
2.6 KiB
JavaScript
/**
|
||
* 格式化数字字符串
|
||
* @param {String, Number} value 待格式化的字符串
|
||
* @param {Number} digits 保留位数
|
||
*/
|
||
function formatNumberString(value, digits = 2) {
|
||
let number = 0
|
||
// 判断是什么类型
|
||
if (typeof value === 'string') {
|
||
number = Number(value)
|
||
} else if (typeof value === 'number') {
|
||
number = value
|
||
}
|
||
if (isNaN(number) || number === 0) {
|
||
return 0
|
||
}
|
||
|
||
let maxNumber = Math.pow(10, digits) - 1
|
||
if (number > maxNumber) {
|
||
return `${maxNumber}+`
|
||
}
|
||
|
||
return number
|
||
}
|
||
|
||
/**
|
||
* 格式化数字字符串,往数字前添加0
|
||
*
|
||
* @param {Object} num 待格式化的数值
|
||
*/
|
||
function formatNumberAddZero(value) {
|
||
let number = 0
|
||
// 判断是什么类型
|
||
if (typeof value === 'string') {
|
||
number = Number(value)
|
||
} else if (typeof value === 'number') {
|
||
number = value
|
||
}
|
||
if (isNaN(number) || +number < 10) {
|
||
return '0' + number
|
||
} else {
|
||
return String(number)
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 格式化数字,往数值后添加单位
|
||
*
|
||
* @param {Object} value 待格式化的数值
|
||
* @param {Object} digits 保留位数
|
||
*/
|
||
function formatNumberAddPriceUnit(value, digits = 2) {
|
||
// 数值分割点
|
||
const unitSplit = [
|
||
{ value: 1, symbol: ''},
|
||
{ value: 1E3, symbol: 'K'},
|
||
{ value: 1E4, symbol: 'W'},
|
||
]
|
||
|
||
const reg = /\.0+$|(\.[0=9]*[1-9])0+$/
|
||
|
||
let number = 0
|
||
// 判断是什么类型
|
||
if (typeof value === 'string') {
|
||
number = Number(value)
|
||
} else if (typeof value === 'number') {
|
||
number = value
|
||
}
|
||
|
||
let i
|
||
for (i = unitSplit.length - 1; i > 0; i--) {
|
||
if (number >= unitSplit[i].value) break
|
||
}
|
||
return (number / unitSplit[i].value).toFixed(digits).replace(reg, "$1") + unitSplit[i].symbol
|
||
}
|
||
|
||
/**
|
||
* 获取数值的整数位数
|
||
*
|
||
* @param {Object} number 数值
|
||
*/
|
||
function getDigit(number) {
|
||
let digit = -1
|
||
while (number >= 1) {
|
||
digit++
|
||
number = number / 10
|
||
}
|
||
return digit
|
||
}
|
||
|
||
/**
|
||
* 获取指定范围的随机数(返回整数)
|
||
|
||
* @param {Object} min 最小值
|
||
* @param {Object} max 最大值
|
||
*/
|
||
function random(min, max) {
|
||
if (min >= 0 && max > 0 && max >= min) {
|
||
let gab = max - min
|
||
return Math.random() * gab + min
|
||
} else {
|
||
return 0
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取指定范围的随机数(返回整数)
|
||
|
||
* @param {Object} min 最小值
|
||
* @param {Object} max 最大值
|
||
*/
|
||
function randomInt(min, max) {
|
||
if (min >= 0 && max > 0 && max >= min) {
|
||
let gab = max - min + 1
|
||
return Math.floor(Math.random() * gab + min)
|
||
} else {
|
||
return 0
|
||
}
|
||
}
|
||
|
||
export default {
|
||
formatNumberString,
|
||
formatNumberAddZero,
|
||
formatNumberAddPriceUnit,
|
||
random,
|
||
randomInt
|
||
} |