当前位置:网站首页>Remember the common JS methods of projects
Remember the common JS methods of projects
2022-07-28 15:53:00 【Line line_ A champion】
// Generate random colors
color16(){ // Hex color random
let r = Math.floor(Math.random()*256);
let g = Math.floor(Math.random()*256);
let b = Math.floor(Math.random()*256);
let color = '#'+(Array(6).join(0) + (r.toString(16)+g.toString(16)+b.toString(16))).slice(-6);
return color;
}
rgb(){ //rgb The color is random
let r = Math.floor(Math.random()*256);
let g = Math.floor(Math.random()*256);
let b = Math.floor(Math.random()*256);
let rgb = 'rgb('+r+','+g+','+b+')';
return rgb;
}
let sum = this.seriesData.reduce((sum, e) => sum + e.value, 0); // Sum up
let max = Math.max.apply(Math,this.seriesData.map(item => { return item.value })); // For maximum //string format
repalceHtml (str) {
let s1 = str.replace(/<\/?.+?>/g, '')
let s2 = s1.replace(/ /g, '')// Go to html
let s3 = s2.replace(/ /ig, '') // Turn to space
// let s4 = s3.replace(/\s*/g, '')// Go to space ;
return s3
}// Percentage to decimal
toPoint (percent) {
let str = percent.replace('%', '')
str = str / 100
return str
}// Amount in words
DX (n) {
if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n)) { return ' data is invalid ' }
let unit = ' Ten billion yuan and cents '
let str = ''
n += '00'
let p = n.indexOf('.')
if (p >= 0) { n = n.substring(0, p) + n.substr(p + 1, 2) }
unit = unit.substr(unit.length - n.length)
for (let i = 0; i < n.length; i++) { str += ' One two three four five six seven eight nine '.charAt(n.charAt(i)) + unit.charAt(i) }
return str.replace(/ zero ( thousand | hundred | Ten | horn )/g, ' zero ').replace(/( zero )+/g, ' zero ').replace(/ zero ( ten thousand | Billion | element )/g, '$1').replace(/( Billion ) ten thousand | one ( Ten )/g, '$1$2').replace(/^ Yuan zero ?| Zero point /g, '').replace(/ element $/g, ' Yuan only ')
}// Cell phone number is regular
let reg = 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/
if (!reg.test(this.form.account)) {
this.$message.warning(' Mobile number format does not match !')
return false
}// Array to object
array2obj (array, key) {
let resObj = {}
for (let i = 0; i < array.length; i++) {
resObj[array[i][key]] = array[i]
}
return resObj
}// Array to tree structure
let newArr = roleTree.data.treeList
if (newArr.length !== 0) {
newArr.forEach(item => {
const pid = item.pid
if (pid !== '') {
newArr.forEach(ele => {
if (ele.id === pid) {
let childArray = ele.children
if (!childArray) {
childArray = []
}
childArray.push(item)
ele.children = childArray
}
})
}
})
}// File download
let fileName = data.data.replace(/redirect:/, '') // File address
let downName = row.name // File download name
const blob = new Blob([fileName])
if (window.navigator.msSaveOrOpenBlob) {
// compatible IE10
navigator.msSaveBlob(blob, downName)
} else {
// chrome/firefox
let aTag = document.createElement('a')
aTag.download = downName
aTag.href = URL.createObjectURL(blob)
aTag.click()
URL.revokeObjectURL(aTag.href)
}// State transition
convertStatus (status) {
switch (status) {
case 'NORMAL':
return ' normal '
case 'REST':
return ' Shut down '
case 'VIOLATION':
return ' Violations, '
case 'TO_CHECK':
return ' To audit '
case 'NO_PASS':
return ' Not through '
}
}
isAbled (state) {
if (state === 'TO_PAY') {
return ' To be paid '
} else if (state === 'TO_CHECK') {
return ' Pending approval '
} else if (state === 'TO_DELIVERY') {
return ' Being adjusted '
} else if (state === 'TO_RECEIVED') {
return ' To be received '
} else if (state === 'TO_APPRAISE') {
return ' To be evaluated '
} else if (state === 'COMPLETED') {
return ' Successful trade '
} else if (state === 'REFUNDING') {
return ' Refunding '
} else if (state === 'REFUND_COMPLETE') {
return ' Refund successful '
} else if (state === 'CLOSED') {
return ' Deal closed '
}
}
item.state = this.isAbled(item.state)To be continued ...
边栏推荐
- Software architecture and design (x) -- Architecture Technology
- DNS域名解析协议
- Software architecture and design (VI) -- hierarchy
- Learning methods 123
- Software architecture and design (V) -- data centric architecture
- 屏下指纹价格战再起,二线厂商今年有望拿下30%市场?
- 软件架构与设计(五)-----以数据为中心的架构
- How to effectively conduct the review meeting (Part 1)?
- VirturalBox解决kernel driver问题
- samba服务器如何配置
猜你喜欢

Shell编程规范与变量

Docker container implements MySQL master-slave replication

光学雨量计应用降雨量检测

光学雨量计对比翻斗式雨量计的优势
![[live broadcast reservation] a new challenge under the evolution of data architecture - Shanghai railway station](/img/46/2a641ea3a0c805ff2377253a824a04.png)
[live broadcast reservation] a new challenge under the evolution of data architecture - Shanghai railway station

Software architecture and design (VIII) -- distributed architecture

生命的感悟

Principle and application of low cost / small volume module rs485/232 to analog signal ibf33

远距离串口服务器( 适配器)UART 转 1-Wire 应用

5-channel di/do relay output remote IO acquisition module Modbus tcp/ibf95
随机推荐
多用型混合信号8AI/4DI/DO转串口RS485/232MODBUS采集模块IBF30
Using SYSTEMd to manage services
软件架构与设计(八)-----分布式架构
光学雨量计对比翻斗式雨量计的优势
记:数值向上取整十,整百,整千,整万
Framework定制系列(一)-----SystemUI NavigationBar导航栏上滑返回Launcher
2路DI高速脉冲计数器1路编码器转Modbus TCP有线无线模块IBF161
远距离串口服务器( 适配器)UART 转 1-Wire 应用
FTP文件传输协议
samba服务器搭建指南
数牍 X Rust,那些不得不说的事
Encoder high speed pulse counter Modbus RTU module ibf150
Software architecture and design (I) -- key principles
软件架构与设计(七)-----互动架构
玩死原型链
monkey压力测试
分体式测斜探头安装要点及注意事项
Pyqt5 rapid development and practice 5.2 container: load more controls
MLX90640 红外热成像仪测温传感器模块开发笔记(八)
Flutter中是使用RxDart代替Stateful