增加倾斜摄影
This commit is contained in:
parent
a249052559
commit
958177952f
|
|
@ -1,4 +1,4 @@
|
|||
# school-front
|
||||
# 朋义矿场一体化平台
|
||||
|
||||
## Build Setup
|
||||
|
||||
|
|
@ -79,3 +79,8 @@ https://1x.antdv.com/components/icon/
|
|||
视频广场 /video/list 未做
|
||||
|
||||
|
||||
|
||||
|
||||
访问地址
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -60,21 +60,28 @@ export default {
|
|||
let xAxisName = []
|
||||
let nameLengthMaxIndex = 0
|
||||
let nameLength = 0
|
||||
//找出name最多的数据
|
||||
for (const index in dataSource) {
|
||||
let xAxisNameList = dataSource[index].map(item => item.name) || []
|
||||
|
||||
dataSource.forEach((arr = [], index) => {
|
||||
let xAxisNameList = arr.map(item => item.name) || []
|
||||
if (xAxisNameList.length > nameLength) {
|
||||
nameLength = xAxisNameList.length
|
||||
nameLengthMaxIndex = index
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
//将挑选的name作为x轴数据
|
||||
xAxisName = dataSource[nameLengthMaxIndex].map(item => item.name) || []
|
||||
//获取y周值
|
||||
let attrNames = Object.keys(dataSourceByAttrObj)
|
||||
let seriesList = []
|
||||
for (const index in dataSource) {
|
||||
let yAxisDataSource = dataSource[index].map(item => item.value)
|
||||
|
||||
|
||||
dataSource.forEach((arr = [], index) => {
|
||||
let yAxisDataSource = arr.map(item => item.value)
|
||||
let series = {
|
||||
name: attrNames[index],
|
||||
type: 'line',
|
||||
|
|
@ -88,7 +95,9 @@ export default {
|
|||
}
|
||||
}
|
||||
seriesList.push(series)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
let option = {
|
||||
color: color,
|
||||
legend: {
|
||||
|
|
|
|||
|
|
@ -110,6 +110,19 @@ export const ms3dConfig = {
|
|||
],
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"pid": 10,
|
||||
"name": "倾斜摄影影像",
|
||||
"type": "3dtiles",
|
||||
"url": "http://101.43.201.20:666/tiles/tileset.json",
|
||||
"position": {
|
||||
"alt": 0 // 根据实际高度调整
|
||||
},
|
||||
"maximumScreenSpaceError": 1,
|
||||
"dynamicScreenSpaceError": true,
|
||||
"cullWithChildrenBounds": false,
|
||||
"show": true
|
||||
},
|
||||
],
|
||||
"layers": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,8 +14,18 @@ export default {
|
|||
info: state => state.system.info
|
||||
})
|
||||
},
|
||||
watch: {
|
||||
'$route': {
|
||||
immediate: true,
|
||||
deep: true,
|
||||
handler(to) {
|
||||
if (to.path.indexOf('login') < 0) {
|
||||
this.getViewData()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getViewData()
|
||||
},
|
||||
methods: {
|
||||
...mapActions('system', ['setInfo']),
|
||||
|
|
|
|||
|
|
@ -27,7 +27,12 @@
|
|||
<ModuleContent padding="0" height="180">
|
||||
<air-quality-trend-charts :data-source="airQualityTrendDataSource"/>
|
||||
</ModuleContent>
|
||||
<web3-title>设备报警信息汇总</web3-title>
|
||||
<web3-title>
|
||||
设备报警信息汇总
|
||||
<template slot="action">
|
||||
<a-button type="primary" @click="exportAlarmList">导出</a-button>
|
||||
</template>
|
||||
</web3-title>
|
||||
<ModuleContent padding="0">
|
||||
<peak-custom-table :table-title="columnsForTable" :data-source="dataSource" :limit-move-num="3"/>
|
||||
</ModuleContent>
|
||||
|
|
@ -57,19 +62,26 @@
|
|||
<ModuleContent padding="20px 0 0" height="140">
|
||||
<div class="pf">
|
||||
<div class="t">当前VOC的日排放量</div>
|
||||
<div class="v">{{ todaypf.today?.voc || 0 }}mg/m3</div>
|
||||
<div class="v">{{ (todaypf.today?.voc || 0).superFixed(2) }}mg/m3</div>
|
||||
</div><div class="pf">
|
||||
<div class="t">当前CEMS的日排放量</div>
|
||||
<div class="v">{{ todaypf.today?.cems || 0 }}mg/m3</div>
|
||||
<div class="v">{{ (todaypf.today?.cems || 0).superFixed(2) }}mg/m3</div>
|
||||
</div>
|
||||
|
||||
</ModuleContent>
|
||||
<web4-title>周排放量</web4-title>
|
||||
<ModuleContent padding="0 ">
|
||||
<peak-custom-table :table-title="columns2ForTable" :data-source="weekData" :limit-move-num="3"/>
|
||||
<air-quality-trend-charts :data-source="weekData"/>
|
||||
<!-- <peak-custom-table :table-title="columns2ForTable" :data-source="weekData" :limit-move-num="3"/>-->
|
||||
</ModuleContent>
|
||||
<web3-title>设备超标报警</web3-title>
|
||||
<ModuleContent padding="0 20px 20px">
|
||||
<web3-title>
|
||||
设备超标报警
|
||||
<template slot="action">
|
||||
<a-button type="primary" @click="exportAlarmList">导出</a-button>
|
||||
</template>
|
||||
</web3-title>
|
||||
<ModuleContent padding="0">
|
||||
<peak-custom-table :table-title="columnsForChaobiao" :data-source="[]" :limit-move-num="3"/>
|
||||
</ModuleContent>
|
||||
</flex-col>
|
||||
|
||||
|
|
@ -244,16 +256,30 @@ export default {
|
|||
const week = this.todaypf.week || {}
|
||||
const results = []
|
||||
for (const weekKey in week) {
|
||||
const row = {
|
||||
// 折线图
|
||||
|
||||
for (const weekElement of week[weekKey]) {
|
||||
if (weekElement && weekElement.Key) {
|
||||
const row = {
|
||||
attr:weekKey,
|
||||
name: weekElement.Key,
|
||||
value: weekElement.value || 0
|
||||
}
|
||||
results.push(row)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// table
|
||||
/*const row = {
|
||||
deviceName:weekKey,
|
||||
}
|
||||
if (!week[weekKey].length) continue
|
||||
|
||||
for (const weekElement of week[weekKey]) {
|
||||
console.log(weekElement)
|
||||
row[weekElement.Key] = weekElement.value
|
||||
}
|
||||
results.push(row)
|
||||
results.push(row)*/
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
|
@ -262,7 +288,30 @@ export default {
|
|||
return {
|
||||
mapTab: 'rl',
|
||||
active: 'yesterday',
|
||||
columnsForChaobiao: [
|
||||
{
|
||||
title: '工序',
|
||||
dataIndex: 'gx',
|
||||
width: '16.66667%'
|
||||
},{
|
||||
title: '阈值',
|
||||
dataIndex: 'yz',
|
||||
width: '16.66667%'
|
||||
},{
|
||||
title: '超标值',
|
||||
dataIndex: 'cbz',
|
||||
width: '16.66667%'
|
||||
},{
|
||||
title: '设备名称',
|
||||
dataIndex: 'sbmc',
|
||||
width: '20%'
|
||||
},{
|
||||
title: '超标名称',
|
||||
dataIndex: 'cbmc',
|
||||
width: '20%'
|
||||
},
|
||||
|
||||
],
|
||||
columnsForTable: [
|
||||
{
|
||||
title: '设备名称',
|
||||
|
|
@ -283,6 +332,10 @@ export default {
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
// 导出报警数据
|
||||
exportAlarmList () {
|
||||
// todo 导出数据
|
||||
},
|
||||
/**
|
||||
* 图层构造器
|
||||
* @param { object } props
|
||||
|
|
@ -359,7 +412,9 @@ export default {
|
|||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@
|
|||
<butgroup class="bottom-btn">
|
||||
<cus-button>
|
||||
<nuxt-link to="/youzuzhi/paifangtongji">环保排放统计</nuxt-link>
|
||||
<nuxt-link to="">DCS</nuxt-link>
|
||||
<nuxt-link to="">日报、周报、月报</nuxt-link>
|
||||
</cus-button>
|
||||
</butgroup>
|
||||
</ModuleContent>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ import checkTypes from "../utils/checkTypes";
|
|||
axios.defaults.withcredentials =true
|
||||
// create an axios instance
|
||||
const service = axios.create({
|
||||
baseURL: process.env.NODE_ENV === 'development' ? '' : 'http://101.43.201.20:5000', // 所有异步请求都加上/api,nginx转发到后端Springboot
|
||||
// baseURL: process.env.NODE_ENV === 'development' ? '' : 'http://101.43.201.20:5000', // 所有异步请求都加上/api,nginx转发到后端Springboot
|
||||
baseURL: '', // 所有异步请求都加上/api,nginx转发到后端Springboot
|
||||
timeout: 5000 // request timeout
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import Vue from 'vue'
|
||||
import '@/utils/systemToolExtend'
|
||||
|
||||
Vue.prototype.$evBus = new Vue()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { notification } from 'ant-design-vue'
|
||||
export const state = {
|
||||
title: '',
|
||||
info: null
|
||||
|
|
@ -20,5 +21,13 @@ export const actions = {
|
|||
setInfo ({ commit, dispatch }, info) {
|
||||
commit('setInfo', info)
|
||||
dispatch('setTitle', info.home?.title || '')
|
||||
if (info?.alerts) {
|
||||
notification.error({
|
||||
message: '温馨提示',
|
||||
description: info?.alerts[0].alarmName,
|
||||
onClick: () => { },
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
252
test/test.js
252
test/test.js
|
|
@ -1,47 +1,217 @@
|
|||
const XLSX = require('xlsx');
|
||||
|
||||
const fs = require('fs');
|
||||
// 读取xlsx文件
|
||||
const workbook = XLSX.readFile('./test.xlsx');
|
||||
|
||||
// 读取特定的worksheet,默认第一个worksheet
|
||||
const worksheet = workbook.Sheets['Sheet2'];
|
||||
|
||||
// 将worksheet转换为JSON对象
|
||||
const jsonData = XLSX.utils.sheet_to_json(worksheet);
|
||||
function dmsToDecimal(degrees, minutes, seconds) {
|
||||
return degrees + minutes / 60 + seconds / 3600;
|
||||
}
|
||||
const c1 = [
|
||||
'张子藤',
|
||||
'刘嘉文',
|
||||
'徐嘉豪',
|
||||
'刘家泽',
|
||||
'徐雅渲',
|
||||
'张子悦',
|
||||
'王奕萱',
|
||||
'王卓然',
|
||||
'云安琪',
|
||||
'宁梓豪',
|
||||
'崔晨岳',
|
||||
'王紫涵',
|
||||
'邢雨梵',
|
||||
'程诗尧',
|
||||
'特穆伦',
|
||||
'姜智皓',
|
||||
'梁芯蕊',
|
||||
'李婕冉',
|
||||
'李奕宣',
|
||||
'郜梓涵',
|
||||
'霍梓祺',
|
||||
'吴若帆',
|
||||
'韩熙莀',
|
||||
'张宸雅',
|
||||
'薛安琪',
|
||||
'杜宇墨',
|
||||
'杨宸赫',
|
||||
'杨润泽',
|
||||
'杨亿晨',
|
||||
'银泽诚',
|
||||
'姜锦岳',
|
||||
'邵璟瑄',
|
||||
'邢伊晨',
|
||||
'赵家甫',
|
||||
'孟昱杰',
|
||||
'王亚萱',
|
||||
'李睿辰',
|
||||
'王一',
|
||||
'庞毅阳',
|
||||
'石浩栋',
|
||||
'张佑宁',
|
||||
'刘昊辰',
|
||||
'郭馨瑶',
|
||||
'张屹凯',
|
||||
'陈琳',
|
||||
'汪子翔',
|
||||
'李苒',
|
||||
'田昕',
|
||||
'苏子琪',
|
||||
'云索朵丽玛',
|
||||
'马嘉铎',
|
||||
'冯杰',
|
||||
]
|
||||
|
||||
|
||||
const results = []
|
||||
|
||||
for (const jsonDatum of jsonData) {
|
||||
const location = jsonDatum['经纬度']
|
||||
const [lat, lon] = location.split(' ')
|
||||
let latStr = lat.replace(/\°|\'|["(N|E)]/g, '@')
|
||||
let lonStr = lon.replace(/\°|\'|["(N|E)]/g, '@')
|
||||
const [latDegrees, latMinutes, latSeconds] = latStr.split('@')
|
||||
const [longDegrees, longMinutes, longSeconds] = lonStr.split('@')
|
||||
const latitude = dmsToDecimal(parseInt(latDegrees), parseInt(latMinutes), parseInt(latSeconds));
|
||||
const longitude = dmsToDecimal(parseInt(longDegrees), parseInt(longMinutes),parseInt( longSeconds));
|
||||
results.push( {
|
||||
longitude,
|
||||
latitude
|
||||
})
|
||||
}
|
||||
const c2 = ['安子涵',
|
||||
'白明倧',
|
||||
'陈颢元',
|
||||
'陈诗菡',
|
||||
'崔槿雯',
|
||||
'崔伟宸',
|
||||
'单铭竹',
|
||||
'董轩宁',
|
||||
'杜凌赫',
|
||||
'冯婧',
|
||||
'傅越琦',
|
||||
'富钰涵',
|
||||
'富振凯',
|
||||
'高浚恺',
|
||||
'韩梓钰',
|
||||
'霍博臣',
|
||||
'贾剀歆',
|
||||
'贾梓墨',
|
||||
'姜舒萌',
|
||||
'李殿雍',
|
||||
'李嘉祺',
|
||||
'李水阳',
|
||||
'李婉瑜',
|
||||
'李宇晴',
|
||||
'李子璐',
|
||||
'刘牧格',
|
||||
'刘一铭',
|
||||
'刘亦凡',
|
||||
'鲁屹',
|
||||
'吕辰溪',
|
||||
'马嘉锴',
|
||||
'牛菡钰',
|
||||
'邵逸凡',
|
||||
'孙子懿',
|
||||
'王楚喻',
|
||||
'王轲纶',
|
||||
'王若欣',
|
||||
'王劭伊',
|
||||
'王新雅',
|
||||
'王鑫甫',
|
||||
'王鑫妤',
|
||||
'王艺博',
|
||||
'王逸辰',
|
||||
'王泽',
|
||||
'魏宇彬',
|
||||
'魏庄惠',
|
||||
'吴浩轩',
|
||||
'张佳荣',
|
||||
'张茗禹',
|
||||
'张若熙',
|
||||
'张纹菲',
|
||||
'张亦扬',
|
||||
'张云睿',
|
||||
'张泽昊',
|
||||
'朱益楷',]
|
||||
|
||||
|
||||
// 文件内容
|
||||
const content = JSON.stringify(results, null, 2)
|
||||
const b1 =
|
||||
[
|
||||
'王卓然',
|
||||
'郜梓源',
|
||||
'邵璟瑄',
|
||||
'姜锦岳',
|
||||
'冯杰',
|
||||
'李苒',
|
||||
'张子悦',
|
||||
'汪子翔',
|
||||
'王紫涵',
|
||||
'郭馨瑶',
|
||||
'杜宇墨',
|
||||
'银泽诚',
|
||||
'陈琳',
|
||||
'石浩栋',
|
||||
'张佑宁',
|
||||
'云安琪',
|
||||
'宁梓豪',
|
||||
'刘家泽',
|
||||
'张宸雅',
|
||||
'云索朵丽玛',
|
||||
'霍梓祺',
|
||||
'刘嘉文',
|
||||
'韩熙莀',
|
||||
'特穆伦',
|
||||
'徐嘉豪',
|
||||
'苏子琪',
|
||||
'徐雅渲',
|
||||
'杨宸赫',
|
||||
'马嘉铎',
|
||||
'李睿辰',
|
||||
'姜智皓',
|
||||
'杨亿晨',
|
||||
'王亚萱',
|
||||
'张屹凯',
|
||||
'王奕萱',
|
||||
'庞毅阳',
|
||||
'邢雨梵',
|
||||
'杨润泽',
|
||||
'孟昱杰',
|
||||
'刘昊辰',
|
||||
'王一',
|
||||
'李婕冉',
|
||||
'李睿辰妈妈',
|
||||
'田昕',
|
||||
'薛安琪',
|
||||
'李奕宣',
|
||||
'李奕宣爸爸',
|
||||
'程诗尧',
|
||||
]
|
||||
|
||||
// 文件路径
|
||||
const filePath = './output.json';
|
||||
|
||||
// 写入文件
|
||||
fs.writeFile(filePath, content, 'utf8', function(err) {
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
console.log('文件已保存');
|
||||
});
|
||||
const b2 = [
|
||||
'王泽',
|
||||
'李宇晴',
|
||||
'张云睿',
|
||||
'魏庄惠',
|
||||
'张亦扬',
|
||||
'刘牧格',
|
||||
'张纹菲',
|
||||
'邵逸凡',
|
||||
'安子涵',
|
||||
'朱益楷',
|
||||
'张泽昊',
|
||||
'张佳荣',
|
||||
'牛菡钰',
|
||||
'崔伟宸',
|
||||
'王逸辰',
|
||||
'李殿雍',
|
||||
'陈颢元',
|
||||
'孙子懿',
|
||||
'刘一铭',
|
||||
'贾剀歆',
|
||||
'崔槿雯',
|
||||
'韩梓钰',
|
||||
'魏宇彬',
|
||||
'高浚恺',
|
||||
'吕辰溪',
|
||||
'王轲纶',
|
||||
'杜凌赫',
|
||||
'王艺博',
|
||||
'张若熙',
|
||||
'李水阳',
|
||||
'霍博臣',
|
||||
'鲁屹',
|
||||
'李子璐',
|
||||
'冯婧',
|
||||
'王鑫甫、妤',
|
||||
'贾芓墨',
|
||||
'傅越琦',
|
||||
'马嘉锴',
|
||||
'王劭伊',
|
||||
'五劭伊',
|
||||
'李婉瑜',
|
||||
'王新雅',
|
||||
'富钰涵',
|
||||
'王楚喻',
|
||||
|
||||
|
||||
]
|
||||
|
||||
console.log('四一班:', c1.filter(name => !b1.includes(name)))
|
||||
console.log('四六班:', c2.filter(name => !b2.includes(name)))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,155 @@
|
|||
/**
|
||||
* @Description: 扩展基类原型方法
|
||||
* @ComponentName: System.tools
|
||||
* @Author: wangzhigang11
|
||||
* @Date: 2022-06-24 19:35
|
||||
*/
|
||||
/**
|
||||
* 扩展基类原型方法,已载入全局基类,可直接调用
|
||||
* @module common/systemToolExtend
|
||||
* @Author: wangzhigang11
|
||||
* @Date: 2022-07-19 14:07
|
||||
*/
|
||||
|
||||
import checkTypes from "@/utils/checkTypes";
|
||||
const ArrayPrototype = Array.prototype
|
||||
const NumberPrototype = Number.prototype
|
||||
const StringPrototype = String.prototype
|
||||
const FilePrototype = File.prototype
|
||||
|
||||
/**
|
||||
* 根据内容结果获取列表中的内容项
|
||||
* @function
|
||||
* @param { string } code 编码
|
||||
* @param { string } itemKey 列表项中的筛选项 默认为value
|
||||
* @example
|
||||
* const arr1 = [ { label: 'xxx', value: 1 }, { label: 'yyy', value: 2 } ]
|
||||
* arr1.getItemByCode(1) // -> { label: 'xxx', value: 1 }
|
||||
* * const arr2 = [ { a: '1', b: 2 }, { a: '3', b: 4 } ]
|
||||
* arr2.getItemByCode(1, 'a') // -> { a: '1', b: 2 }
|
||||
* @returns {object}
|
||||
*/
|
||||
ArrayPrototype.getItemByCode = function (code, itemKey = 'value') {
|
||||
if (!checkTypes.isArray(this)) return {}
|
||||
for (const item of this) {
|
||||
if (`${item[itemKey]}` === `${code}`) return item
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据逗号分割的内容获取结果
|
||||
* @param { string[] } code 需要查找的内容
|
||||
* @param { string } code 需要查找的内容
|
||||
* @param { object } option 查找的配置
|
||||
* @param { string } option.label 查找结果字符串的映射字段
|
||||
* @param { string } option.key 查找结果的键的映射字段
|
||||
* @param { string } option.separator 分割符,默认为','
|
||||
* @param { string } option.emptyText 查找结果无效时显示的内容
|
||||
* @example
|
||||
* const arr = [{id: 1, name: '小红'}, [id: 3, name: '小明']]
|
||||
* arr.getLabelByCodes('1,3', { label: 'name', key: 'id' }) // => '小红,小明'
|
||||
* arr.getLabelByCodes('1,3', { label: 'name', key: 'id', separator: '/' }) // => '小红/小明'
|
||||
* @returns {string}
|
||||
*/
|
||||
ArrayPrototype.getLabelByCodes = function (code, option = {}) {
|
||||
if (!checkTypes.isArray(this)) return ''
|
||||
const curCode = checkTypes.isNumber(code) && code === 0 ? '0' : code || ''
|
||||
let filterCode = []
|
||||
if (checkTypes.isArray(code)) {
|
||||
filterCode = code.filter(item => !!item)
|
||||
} else {
|
||||
filterCode = `${curCode}`.split(',').filter(item => !!item)
|
||||
}
|
||||
return filterCode.map(itemCode => {
|
||||
return this.getItemByCode(itemCode, option.key || 'value')[option.label || 'label'] || ''
|
||||
}).filter(item => item !== '').join(option.separator || ',') || option.emptyText || ''
|
||||
}
|
||||
|
||||
ArrayPrototype.getIndexByCode = function (code, itemKey = 'value') {
|
||||
return this.findIndex(cur => cur[itemKey] === code)
|
||||
}
|
||||
|
||||
ArrayPrototype.hasCode = function (code, key = 'value') {
|
||||
const filter = this.findIndex(item => item[key] === code)
|
||||
return filter >= 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据处理工具,保留小数点后几位,并添加单位
|
||||
* @function superFixed
|
||||
* @private
|
||||
* @param { number} len 保留位数
|
||||
* @param { string } unit 单位
|
||||
* @example
|
||||
* const test = 1
|
||||
* test.superFixed(2) // => 1.00
|
||||
* test.superFixed(2, '个') // => '1.00个'
|
||||
* @returns {string|number}
|
||||
*/
|
||||
NumberPrototype.superFixed = function (len = 0, unit = '') {
|
||||
return (this || 0).toFixed(len) + unit
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据处理工具,保留小数点后几位,并添加单位
|
||||
* @function superFixed
|
||||
* @param { number} len 保留位数
|
||||
* @param { string } unit 单位
|
||||
* @example
|
||||
* const test1 = '1'
|
||||
* test1.superFixed(2) // => 1.00
|
||||
* test1.superFixed(2) // => 1.00
|
||||
* const test2 = 1
|
||||
* test2.superFixed(2) // => 1.00
|
||||
* test2.superFixed(2, '个') // => '1.00个'
|
||||
* @returns {string|number}
|
||||
*/
|
||||
StringPrototype.superFixed = function (len = 0, unit = '') {
|
||||
// 如果是数字型字符串 返回保留后的
|
||||
if (/^[-\+]?[\d]*\.?[\d]*$/.test(this)) return Number(this).superFixed(len, unit)
|
||||
// 如果是其他字符串,返回本身
|
||||
return this
|
||||
}
|
||||
|
||||
function base64ToBlob(base64) {
|
||||
const parts = base64.split(';base64,');
|
||||
const contentType = parts[0].split(':')[1];
|
||||
const raw = window.atob(parts[1]);
|
||||
const rawLength = raw.length;
|
||||
const uInt8Array = new Uint8Array(rawLength);
|
||||
for (let i = 0; i < rawLength; ++i) {
|
||||
uInt8Array[i] = raw.charCodeAt(i);
|
||||
}
|
||||
return new Blob([uInt8Array], {type: contentType});
|
||||
}
|
||||
|
||||
|
||||
StringPrototype.toFile = function () {
|
||||
// 使用Base64字符串创建一个File对象
|
||||
return new File([base64ToBlob(this)], `file_${new Date().valueOf()}`, {
|
||||
type: 'image/png',
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件转base64
|
||||
* @param {boolean} splitHeader 是否需要切掉base64头
|
||||
* @example
|
||||
* file.toBase64() // => 'image/jpeg;base64,VFZSSmVrMVVTWG8lM0Q='
|
||||
* file.toBase64(true) // => 'VFZSSmVrMVVTWG8lM0Q='
|
||||
* @returns {string}
|
||||
*/
|
||||
FilePrototype.toBase64 = function (splitHeader = false) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fileReader = new FileReader()
|
||||
fileReader.readAsDataURL(this)
|
||||
fileReader.onload = (e) => {
|
||||
let base64Str = e.target.result
|
||||
if (splitHeader) {
|
||||
base64Str = base64Str.substr(base64Str.indexOf(',') + 1)
|
||||
}
|
||||
resolve(base64Str)
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue