当前位置:网站首页>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 ...
边栏推荐
- Voice social system -- improve the audio system industry chain
- 2.855 billion yuan! Qingdao Xinen completed the capital increase: Xingcheng Jidian became the largest shareholder, holding 57.10%
- Return the two subscripts of the array according to the input target.
- 使用systemd管理服务
- Pytorch - optimize model parameters
- VM501开发套件开发版单振弦式传感器采集模块岩土工程监测
- 软件架构与设计(七)-----互动架构
- 软件架构与设计(五)-----以数据为中心的架构
- 管理区解耦架构见过吗?能帮客户搞定大难题的
- How to quickly access the unified authentication system
猜你喜欢

多功能混合信号AI采集/开关量DI/DO采集转RS485/232/MODBUS模块

电压转电流/电流转电压模块

使用systemd管理服务

How to quickly access the unified authentication system

MySQL add and delete indexes

高速计数器转RS485Modbus RTU模块IBF150

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

活动速递| Apache Doris 性能优化实战系列直播课程初公开,诚邀您来参加!

What is the concept of game testing? What are the test methods and processes?

Communication between client and server based on rsocket protocol
随机推荐
Software architecture and design (I) -- key principles
多用型混合信号8AI/4DI/DO转串口RS485/232MODBUS采集模块IBF30
Data real-time feedback technology
Solve the problem that the right-click menu "edit with idle" of the 『 py 』 file is invalid or missing
Using SYSTEMd to manage services
阿里云的rds mysql 只读实例在哪里创建
如何快速接入统一的认证鉴权体系
Software architecture and design (VI) -- hierarchy
A failed cracking experience
1路编码器2路DI转速测量RS485串口连接1路DO报警模块IBF151
远距离串口服务器( 适配器)UART/I2C/1-Wire/SPI PS304常见问题及注意事项
VM501开发套件开发版单振弦式传感器采集模块岩土工程监测
如何压缩与解压缩ramdisk.img
Software architecture and design (IV) -- data flow architecture
Voice social system -- improve the audio system industry chain
Multifunctional mixed signal AI acquisition / switching value di/do acquisition to rs485/232/modbus module
知识点qwer
玩死原型链
Thermistor PT100, NTC to 0-10v/4-20ma converter
学习方法123