init
BIN
src/assets/css/font/PangMenZhengDao.ttf
Normal file
BIN
src/assets/css/font/SourceHanSansCN-Normal.otf
Executable file
28
src/assets/css/iconfont.styl
Normal file
@@ -0,0 +1,28 @@
|
||||
@font-face {
|
||||
font-family: "iconfont"; /* Project id 1255596 */
|
||||
src: url('iconfont/iconfont.woff2?t=1620977303191') format('woff2'),
|
||||
url('iconfont/iconfont.woff?t=1620977303191') format('woff'),
|
||||
url('iconfont/iconfont.ttf?t=1620977303191') format('truetype');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "PangMenZhengDao";
|
||||
src: url('font/PangMenZhengDao.ttf')
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "SourceHanSansCN";
|
||||
src: url('font/SourceHanSansCN-Normal.otf');
|
||||
}
|
||||
|
||||
.iconfont {
|
||||
font-family: "iconfont" !important;
|
||||
font-size: 16px;
|
||||
font-style: normal;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
.icon-guanbi:before {
|
||||
content: "\e60f";
|
||||
}
|
||||
37
src/assets/css/iconfont/iconfont.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"id": "1255596",
|
||||
"name": "nl-hht-hl",
|
||||
"font_family": "iconfont",
|
||||
"css_prefix_text": "icon-",
|
||||
"description": "",
|
||||
"glyphs": [
|
||||
{
|
||||
"icon_id": "2229060",
|
||||
"name": "无信号",
|
||||
"font_class": "no-signal",
|
||||
"unicode": "e76b",
|
||||
"unicode_decimal": 59243
|
||||
},
|
||||
{
|
||||
"icon_id": "400034",
|
||||
"name": "下拉",
|
||||
"font_class": "htmal5icon03",
|
||||
"unicode": "e626",
|
||||
"unicode_decimal": 58918
|
||||
},
|
||||
{
|
||||
"icon_id": "731140",
|
||||
"name": "选择",
|
||||
"font_class": "guanbi1",
|
||||
"unicode": "e608",
|
||||
"unicode_decimal": 58888
|
||||
},
|
||||
{
|
||||
"icon_id": "4736203",
|
||||
"name": "关闭",
|
||||
"font_class": "guanbi",
|
||||
"unicode": "e60f",
|
||||
"unicode_decimal": 58895
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
src/assets/css/iconfont/iconfont.ttf
Normal file
BIN
src/assets/css/iconfont/iconfont.woff
Normal file
BIN
src/assets/css/iconfont/iconfont.woff2
Normal file
5
src/assets/css/layout.styl
Normal file
@@ -0,0 +1,5 @@
|
||||
@import 'iconfont.styl'
|
||||
.bg
|
||||
width 100%
|
||||
height 100%
|
||||
overflow hidden
|
||||
40
src/assets/css/mixin.styl
Normal file
@@ -0,0 +1,40 @@
|
||||
$red = #ed4754
|
||||
$green = #67c23a
|
||||
$yellow = #f2d648
|
||||
$orange = #f17d3a
|
||||
$blue = #6798ef
|
||||
$gray = #c9c9c9
|
||||
$fc1 = #323232
|
||||
|
||||
|
||||
//宽高
|
||||
_wh(w, h)
|
||||
width: w
|
||||
height: h
|
||||
|
||||
//字体大小、行高、颜色
|
||||
_font(size,height,color=$fc1,weight=normal,align=left)
|
||||
font-size: size
|
||||
line-height: height
|
||||
color: color
|
||||
font-weight: weight
|
||||
text-align: align
|
||||
|
||||
//flex 布局和 子元素 对其方式
|
||||
_fj(x=space-between,y=center)
|
||||
display: flex
|
||||
justify-content: x
|
||||
align-items: y
|
||||
|
||||
// 背景图片地址和大小
|
||||
_bis(url,w,h=auto,x=center,y=center)
|
||||
background-position: x y
|
||||
background-size: w h
|
||||
background-image: url(url)
|
||||
background-repeat: no-repeat
|
||||
|
||||
// 定位上下居中
|
||||
_ct()
|
||||
position: absolute
|
||||
top: 50%
|
||||
transform: translateY(-50%)
|
||||
131
src/assets/css/reset.css
Normal file
@@ -0,0 +1,131 @@
|
||||
html, body, div, span, applet, object, iframe,
|
||||
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
||||
a, abbr, acronym, address, big, cite, code,
|
||||
del, dfn, em, img, ins, kbd, q, s, samp,
|
||||
small, strike, strong, sub, sup, tt, var,
|
||||
b, u, i, center,
|
||||
dl, dt, dd, ol, ul, li,
|
||||
fieldset, form, label, legend,
|
||||
table, caption, tbody, tfoot, thead, tr, th, td,
|
||||
article, aside, canvas, details, embed,
|
||||
figure, figcaption, footer, header,
|
||||
menu, nav, output, ruby, section, summary,
|
||||
time, mark, audio, video, input {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
font-size: 0.16rem;
|
||||
line-height: inherit;
|
||||
color: #ffffff;
|
||||
font-weight: normal;
|
||||
vertical-align: baseline;
|
||||
font-family: "lucida grande", "lucida sans unicode", lucida, helvetica, "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
|
||||
}
|
||||
|
||||
/* HTML5 display-role reset for older browsers */
|
||||
article, aside, details, figcaption, figure,
|
||||
footer, header, menu, nav, section {
|
||||
display: block;
|
||||
}
|
||||
|
||||
body {
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
blockquote, q {
|
||||
quotes: none;
|
||||
}
|
||||
|
||||
blockquote:before, blockquote:after,
|
||||
q:before, q:after {
|
||||
content: none;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
/* custom */
|
||||
a,a:link,a:visited,a:active {
|
||||
color: #7e8c8d;
|
||||
text-decoration: none;
|
||||
-webkit-backface-visibility: hidden;
|
||||
}
|
||||
|
||||
li {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track-piece {
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
-webkit-border-radius: 6px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:vertical {
|
||||
height: 5px;
|
||||
background-color: rgba(125, 125, 125, 0.7);
|
||||
-webkit-border-radius: 6px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:horizontal {
|
||||
width: 5px;
|
||||
background-color: rgba(125, 125, 125, 0.7);
|
||||
-webkit-border-radius: 6px;
|
||||
}
|
||||
|
||||
html, body {
|
||||
width: 1920px;
|
||||
height: 1080px;
|
||||
/* width: 100%;
|
||||
height: 100%;
|
||||
min-width: 1440px;
|
||||
min-height: 1080px; */
|
||||
}
|
||||
|
||||
body {
|
||||
-webkit-text-size-adjust: none;
|
||||
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
||||
background: #05032a center center / 100% 100% url(../../assets/images/screen1/bg.jpg) no-repeat;
|
||||
}
|
||||
|
||||
div, p {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.clearfix {
|
||||
zoom: 1;
|
||||
}
|
||||
|
||||
.clearfix:after {
|
||||
content: "";
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.ellipsis {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.fl {
|
||||
float: left !important;
|
||||
}
|
||||
|
||||
.fr {
|
||||
float: right !important;
|
||||
}
|
||||
|
||||
.fontselect {
|
||||
-moz-user-select:none;/*火狐*/
|
||||
-webkit-user-select:none;/*webkit浏览器*/
|
||||
-ms-user-select:none;/*IE10*/
|
||||
-khtml-user-select:none;/*早期浏览器*/
|
||||
user-select:none;
|
||||
}
|
||||
BIN
src/assets/images/bg.png
Normal file
|
After Width: | Height: | Size: 7.9 MiB |
BIN
src/assets/images/bg1.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
src/assets/images/bg2.png
Normal file
|
After Width: | Height: | Size: 599 KiB |
BIN
src/assets/images/bg3.png
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
BIN
src/assets/images/bg4.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
src/assets/images/header.png
Normal file
|
After Width: | Height: | Size: 459 KiB |
BIN
src/assets/images/mon_04.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
src/assets/images/screen1/bg.jpg
Normal file
|
After Width: | Height: | Size: 182 KiB |
BIN
src/assets/images/screen1/bg.png
Normal file
|
After Width: | Height: | Size: 1.8 MiB |
BIN
src/assets/images/screen1/bottom.png
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
src/assets/images/screen1/dot_1.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
src/assets/images/screen1/header.png
Normal file
|
After Width: | Height: | Size: 91 KiB |
BIN
src/assets/images/screen1/item_1.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/assets/images/screen1/item_2.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
src/assets/images/screen1/item_3.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
src/assets/images/screen1/item_4.png
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
src/assets/images/screen1/item_5.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
src/assets/images/screen1/item_6.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/assets/images/screen1/item_7.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/assets/images/screen1/line_1.png
Normal file
|
After Width: | Height: | Size: 492 B |
BIN
src/assets/images/screen1/line_2.png
Normal file
|
After Width: | Height: | Size: 979 B |
BIN
src/assets/images/screen1/line_3.png
Normal file
|
After Width: | Height: | Size: 871 B |
BIN
src/assets/images/screen1/title_bg_1.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
src/assets/images/screen1/title_bg_2.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
src/assets/images/screen1/title_bg_d1.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
src/assets/images/screen1/title_bg_d2.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
src/assets/images/screen1/top_1.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
src/assets/images/screen1/top_2.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
src/assets/images/screen1/top_3.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/assets/images/tip.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
14
src/assets/js/filter.js
Normal file
@@ -0,0 +1,14 @@
|
||||
// import store from '../vuex/store'
|
||||
|
||||
const filter = {
|
||||
numeric (value) {
|
||||
if (value === '') return ''
|
||||
return Number(value).toFixed(3)
|
||||
},
|
||||
numFixed (value, bit) {
|
||||
if (value === '') return ''
|
||||
return Number(value).toFixed(bit)
|
||||
}
|
||||
}
|
||||
|
||||
export default filter
|
||||
22
src/assets/js/getData1.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import {post} from '@js/http.js'
|
||||
|
||||
/** 1.1设备实时状态 */
|
||||
export const deviceStatus = (id) => post('api/deviceScreen/deviceStatus', {})
|
||||
/** 1.2设备综合效率OEE&产能利用效率TEEP */
|
||||
export const oeeAndTeep = (id) => post('api/deviceScreen/oeeAndTeep', {})
|
||||
/** 1.3运行设备大类产能比 */
|
||||
export const queryDeviceByWork = (id) => post('api/deviceScreen/queryDeviceByWork', {})
|
||||
/** 1.4设备TOP10故障次数 */
|
||||
export const deviceErrorNum = (id) => post('api/deviceScreen/deviceErrorNum', {})
|
||||
/** 1.5设备管理 */
|
||||
export const deviceManage = (id) => post('api/deviceScreen/deviceManage', {})
|
||||
/** 1.6设备综合统计 */
|
||||
export const deviceCensus = (id) => post('api/deviceScreen/deviceCensus', {})
|
||||
/** 1.7设备报警信息 */
|
||||
export const deviceErrorInfo = (id) => post('api/deviceScreen/deviceErrorInfo', {})
|
||||
/** 1.8设备产能利用 */
|
||||
export const deviceUseRate = (id) => post('api/deviceScreen/deviceUseRate', {})
|
||||
/** 1.9设备状态列表 */
|
||||
export const deviceStatusList = (id) => post('api/deviceScreen/deviceStatusList', {})
|
||||
/** 1.10近30天设备故障统计 */
|
||||
export const errCensus = (id) => post('api/deviceScreen/errCensus', {})
|
||||
34
src/assets/js/getData2.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import {post, post1} from '@js/http.js'
|
||||
|
||||
/** 1.1配粉设备下拉框 */
|
||||
export const queryDevice = (url) => post1(url + '/api/screen/pdm/queryDevice', {})
|
||||
|
||||
/** 1.1大屏左一 */
|
||||
export const planReached = (id) => post('api/bigscreen/product/planReached', {})
|
||||
|
||||
/** 1.2大屏左二 */
|
||||
export const worksectionHarvest = (id) => post('api/bigscreen/product/worksectionHarvest', {})
|
||||
|
||||
/** 1.3大屏左三 */
|
||||
export const monthHarvest = (id) => post('api/bigscreen/product/monthHarvest', {})
|
||||
|
||||
/** 1.4大屏右一 */
|
||||
export const output = (id) => post('api/bigscreen/product/output', {})
|
||||
|
||||
/** 1.5大屏右二 */
|
||||
export const topHarvest = (id) => post('api/bigscreen/product/topHarvest', {})
|
||||
|
||||
/** 1.6大屏右三 */
|
||||
export const monthOrder = (id) => post('api/bigscreen/product/monthOrder', {})
|
||||
|
||||
/** 1.7大屏中一 */
|
||||
export const productSchedule = (id) => post('api/bigscreen/product/productSchedule', {})
|
||||
|
||||
/** 1.8大屏中二 */
|
||||
export const unfinishOrder = (id) => post('api/bigscreen/product/unfinishOrder', {})
|
||||
|
||||
// 车间看板
|
||||
// 1.1任务数
|
||||
export const getTask = (id) => post('api/agvBigScreen/getTask', {})
|
||||
// 1.2车辆状态
|
||||
export const getAgvMsg = (id) => post('api/agvBigScreen/getAgvMsg', {})
|
||||
78
src/assets/js/http.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import axios from 'axios'
|
||||
import { Dialog, toast } from './mUtils.js'
|
||||
import store from '../../vuex/store'
|
||||
import router from '@/router'
|
||||
|
||||
axios.defaults.timeout = 50000
|
||||
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
|
||||
|
||||
axios.interceptors.request.use(
|
||||
config => {
|
||||
if (config.method === 'post') {
|
||||
if (!config.data.flag) {
|
||||
config.data = config.data
|
||||
} else {
|
||||
config.data = config.data.formData
|
||||
}
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
Dialog('错误的传参')
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
axios.interceptors.response.use(
|
||||
response => {
|
||||
if (response.status === 200) {
|
||||
return Promise.resolve(response)
|
||||
} else {
|
||||
return Promise.reject(response)
|
||||
}
|
||||
},
|
||||
error => {
|
||||
if (error && error.response) {
|
||||
switch (error.response.status) {
|
||||
case 401:
|
||||
toast(error.response.data.message)
|
||||
store.dispatch('setSignOut')
|
||||
router.push('/login')
|
||||
break
|
||||
}
|
||||
return Promise.reject(error.response.data)
|
||||
} else {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
export const post = (sevmethod, params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(`${store.getters.baseUrl}/` + sevmethod, params)
|
||||
.then(response => {
|
||||
resolve(response.data)
|
||||
}, error => {
|
||||
// toast(error.message)
|
||||
reject(error.message)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const post1 = (sevmethod, params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(sevmethod, params)
|
||||
.then(response => {
|
||||
resolve(response.data)
|
||||
}, error => {
|
||||
Dialog(error.message)
|
||||
reject(error.message)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
134
src/assets/js/mUtils.js
Normal file
@@ -0,0 +1,134 @@
|
||||
import store from '../../vuex/store'
|
||||
|
||||
/**
|
||||
* 弹出框
|
||||
*/
|
||||
export const Dialog = (str) => {
|
||||
store.dispatch('showAlert', true)
|
||||
store.dispatch('alertMsg', str)
|
||||
setTimeout(() => {
|
||||
store.dispatch('showAlert', false)
|
||||
}, 30000)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提示框
|
||||
*/
|
||||
export const toast = (str) => {
|
||||
store.dispatch('showToast', true)
|
||||
store.dispatch('toastMsg', str)
|
||||
setTimeout(() => {
|
||||
store.dispatch('showToast', false)
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储localStorage
|
||||
*/
|
||||
export const setStore = (name, content) => {
|
||||
if (!name) return
|
||||
if (typeof content !== 'string') {
|
||||
content = JSON.stringify(content)
|
||||
}
|
||||
window.localStorage.setItem(name, content)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取localStorage
|
||||
*/
|
||||
export const getStore = name => {
|
||||
if (!name) return
|
||||
return window.localStorage.getItem(name)
|
||||
}
|
||||
|
||||
/**
|
||||
* 小数加法
|
||||
*/
|
||||
export const accAdd = (arg1, arg2) => {
|
||||
var r1, r2, m, c
|
||||
try {
|
||||
r1 = arg1.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r1 = 0
|
||||
}
|
||||
try {
|
||||
r2 = arg2.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r2 = 0
|
||||
}
|
||||
c = Math.abs(r1 - r2)
|
||||
m = Math.pow(10, Math.max(r1, r2))
|
||||
if (c > 0) {
|
||||
var cm = Math.pow(10, c)
|
||||
if (r1 > r2) {
|
||||
arg1 = Number(arg1.toString().replace('.', ''))
|
||||
arg2 = Number(arg2.toString().replace('.', '')) * cm
|
||||
} else {
|
||||
arg1 = Number(arg1.toString().replace('.', '')) * cm
|
||||
arg2 = Number(arg2.toString().replace('.', ''))
|
||||
}
|
||||
} else {
|
||||
arg1 = Number(arg1.toString().replace('.', ''))
|
||||
arg2 = Number(arg2.toString().replace('.', ''))
|
||||
}
|
||||
return (arg1 + arg2) / m
|
||||
}
|
||||
|
||||
/**
|
||||
* 小数减法
|
||||
*/
|
||||
export const accSubtract = (arg1, arg2) => {
|
||||
var r1, r2, m, c
|
||||
try {
|
||||
r1 = arg1.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r1 = 0
|
||||
}
|
||||
try {
|
||||
r2 = arg2.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r2 = 0
|
||||
}
|
||||
c = Math.abs(r1 - r2)
|
||||
m = Math.pow(10, Math.max(r1, r2))
|
||||
if (c > 0) {
|
||||
var cm = Math.pow(10, c)
|
||||
if (r1 > r2) {
|
||||
arg1 = Number(arg1.toString().replace('.', ''))
|
||||
arg2 = Number(arg2.toString().replace('.', '')) * cm
|
||||
} else {
|
||||
arg1 = Number(arg1.toString().replace('.', '')) * cm
|
||||
arg2 = Number(arg2.toString().replace('.', ''))
|
||||
}
|
||||
} else {
|
||||
arg1 = Number(arg1.toString().replace('.', ''))
|
||||
arg2 = Number(arg2.toString().replace('.', ''))
|
||||
}
|
||||
return (arg1 - arg2) / m
|
||||
}
|
||||
|
||||
/**
|
||||
* 小数乘法
|
||||
*/
|
||||
export const accMul = (arg1, arg2) => {
|
||||
var m = 0
|
||||
var s1 = arg1.toString()
|
||||
var s2 = arg2.toString()
|
||||
try { m += s1.split('.')[1].length } catch (e) {}
|
||||
try { m += s2.split('.')[1].length } catch (e) {}
|
||||
return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m)
|
||||
}
|
||||
|
||||
/**
|
||||
* 求数组最大值
|
||||
*/
|
||||
export const maxArr = (arr) => {
|
||||
let max = Number(arr[0])
|
||||
let len = arr.length
|
||||
for (let i = 1; i < len; i++) {
|
||||
if (Number(arr[i]) > max) {
|
||||
max = Number(arr[i])
|
||||
}
|
||||
}
|
||||
return max
|
||||
}
|
||||
12
src/assets/js/rem.js
Normal file
@@ -0,0 +1,12 @@
|
||||
(function (doc, win) {
|
||||
var docEl = doc.documentElement
|
||||
var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'
|
||||
var recalc = function () {
|
||||
var clientWidth = docEl.clientWidth
|
||||
if (!clientWidth) return
|
||||
docEl.style.fontSize = 100 * (clientWidth / 1920) + 'px'
|
||||
document.body.style.display = 'block'
|
||||
}
|
||||
if (!doc.addEventListener) return win.addEventListener(resizeEvt, recalc, false)
|
||||
doc.addEventListener('DOMContentLoaded', recalc, false)
|
||||
})(document, window)
|
||||
72
src/assets/js/utils.js
Normal file
@@ -0,0 +1,72 @@
|
||||
const utils = {
|
||||
getUserIP: function () {
|
||||
var MyPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection
|
||||
var pc = new MyPeerConnection({
|
||||
iceServers: []
|
||||
})
|
||||
var noop = function () {}
|
||||
var localIPs = {}
|
||||
var newObj = {}
|
||||
var ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g
|
||||
function iterateIP (ip) {
|
||||
if (!localIPs[ip]) localStorage.setItem('localip', ip)
|
||||
localIPs[ip] = true
|
||||
newObj['ip'] = ip
|
||||
}
|
||||
pc.createDataChannel('')
|
||||
pc.createOffer().then(function (sdp) {
|
||||
sdp.sdp.split('\n').forEach(function (line) {
|
||||
if (line.indexOf('candidate') < 0) return
|
||||
line.match(ipRegex).forEach(iterateIP)
|
||||
})
|
||||
pc.setLocalDescription(sdp, noop, noop)
|
||||
}).catch(function (reason) {
|
||||
// An error occurred, so handle the failure to connect
|
||||
})
|
||||
pc.onicecandidate = function (ice) {
|
||||
if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return
|
||||
ice.candidate.candidate.match(ipRegex).forEach(iterateIP)
|
||||
}
|
||||
return newObj
|
||||
},
|
||||
// 小数加法
|
||||
accAdd (arg1, arg2) {
|
||||
var r1, r2, m, c
|
||||
try {
|
||||
r1 = arg1.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r1 = 0
|
||||
}
|
||||
try {
|
||||
r2 = arg2.toString().split('.')[1].length
|
||||
} catch (e) {
|
||||
r2 = 0
|
||||
}
|
||||
c = Math.abs(r1 - r2)
|
||||
m = Math.pow(10, Math.max(r1, r2))
|
||||
if (c > 0) {
|
||||
var cm = Math.pow(10, c)
|
||||
if (r1 > r2) {
|
||||
arg1 = Number(arg1.toString().replace('.', ''))
|
||||
arg2 = Number(arg2.toString().replace('.', '')) * cm
|
||||
} else {
|
||||
arg1 = Number(arg1.toString().replace('.', '')) * cm
|
||||
arg2 = Number(arg2.toString().replace('.', ''))
|
||||
}
|
||||
} else {
|
||||
arg1 = Number(arg1.toString().replace('.', ''))
|
||||
arg2 = Number(arg2.toString().replace('.', ''))
|
||||
}
|
||||
return (arg1 + arg2) / m
|
||||
},
|
||||
// 乘法
|
||||
accMul (arg1, arg2) {
|
||||
var m = 0
|
||||
var s1 = arg1.toString()
|
||||
var s2 = arg2.toString()
|
||||
try { m += s1.split('.')[1].length } catch (e) {}
|
||||
try { m += s2.split('.')[1].length } catch (e) {}
|
||||
return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m)
|
||||
}
|
||||
}
|
||||
export default utils
|
||||