|
|
/*
|
|
|
* @Author: your name
|
|
|
* @Date: 2021-10-12 13:56:13
|
|
|
* @LastEditTime: 2021-11-08 12:03:25
|
|
|
* @LastEditors: Please set LastEditors
|
|
|
* @Description: In User Settings Edit
|
|
|
* @FilePath: /data-show/src/mixins/index.js
|
|
|
*/
|
|
|
import { mapGetters, mapActions } from "vuex";
|
|
|
import Loading from './loading'
|
|
|
function detectZoom (){
|
|
|
let ratio = 0,
|
|
|
screen = window.screen,
|
|
|
ua = navigator.userAgent.toLowerCase();
|
|
|
|
|
|
if (window.devicePixelRatio !== undefined) {
|
|
|
ratio = window.devicePixelRatio;
|
|
|
}
|
|
|
else if (ua.indexOf('msie')) {
|
|
|
if (screen.deviceXDPI && screen.logicalXDPI) {
|
|
|
ratio = screen.deviceXDPI / screen.logicalXDPI;
|
|
|
}
|
|
|
}
|
|
|
else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
|
|
|
ratio = window.outerWidth / window.innerWidth;
|
|
|
}
|
|
|
|
|
|
// if (ratio){
|
|
|
// ratio ;
|
|
|
// }
|
|
|
|
|
|
return ratio;
|
|
|
}
|
|
|
|
|
|
export default {
|
|
|
install(Vue) {
|
|
|
Vue.mixin({
|
|
|
directives: {
|
|
|
'loading': Loading,
|
|
|
resize: { // 指令的名称
|
|
|
bind(el, binding) { // el为绑定的元素,binding为绑定给指令的对象
|
|
|
// console.log(el, "绑定", binding);
|
|
|
let width = '', height = '';
|
|
|
function isReize() {
|
|
|
const style = document.defaultView.getComputedStyle(el);
|
|
|
if (width !== style.width || height !== style.height) {
|
|
|
binding.value({ width: style.width, height: style.height, ratio: detectZoom() }); // 关键(这传入的是函数,所以执行此函数)
|
|
|
}
|
|
|
width = style.width;
|
|
|
height = style.height;
|
|
|
}
|
|
|
el.__vueSetInterval__ = setInterval(isReize, 300);
|
|
|
},
|
|
|
unbind(el) {
|
|
|
// console.log(el, "解绑");
|
|
|
clearInterval(el.__vueSetInterval__);
|
|
|
}
|
|
|
},
|
|
|
highly: {
|
|
|
bind(el, binding) { // el为绑定的元素,binding为绑定给指令的对象
|
|
|
let height = '';
|
|
|
let z = binding.value;
|
|
|
let firstH = "";
|
|
|
let b = true;
|
|
|
function adaptive() {
|
|
|
const style = document.defaultView.getComputedStyle(el); // 获取元素
|
|
|
const wh = document.body.clientHeight;
|
|
|
let h = style.height;
|
|
|
firstH = firstH || h;
|
|
|
if (height == wh) return
|
|
|
if(wh >= 760 && wh < 930 && b) {
|
|
|
el.style.height = z * parseFloat(h) + 'px';
|
|
|
b = !b
|
|
|
} else {
|
|
|
el.style.height = firstH;
|
|
|
b = !b;
|
|
|
}
|
|
|
height = wh
|
|
|
}
|
|
|
el.__vueSetInterval__ = setInterval(adaptive, 300);
|
|
|
},
|
|
|
// inserted(el, binding) {
|
|
|
// adaptive(el, binding.value)
|
|
|
// },
|
|
|
unbind(el) {
|
|
|
// console.log(el, "解绑");
|
|
|
clearInterval(el.__vueSetInterval__);
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
...mapGetters(['getZoom', 'getToken', 'getUser', 'getAccount', 'getCommTime', 'getCtime', 'getCtime2', 'getHeaderType', 'getBrand', 'getModel','getSComparison','getBComparison'])
|
|
|
},
|
|
|
methods: {
|
|
|
...mapActions(["setZoom", 'setToken', 'setUser', 'setAccount', 'setCommTime', 'setCtime', 'setCtime2', 'setHeaderType', 'setBrand', 'setModel', 'setSComparison','setBComparison']),
|
|
|
// 获取当前日期时间
|
|
|
getDatetime() {
|
|
|
let now = new Date();
|
|
|
let weeks = new Array(
|
|
|
"星期日",
|
|
|
"星期一",
|
|
|
"星期二",
|
|
|
"星期三",
|
|
|
"星期四",
|
|
|
"星期五",
|
|
|
"星期六"
|
|
|
);
|
|
|
let year = now.getFullYear();
|
|
|
let month = now.getMonth() + 1;
|
|
|
let day = now.getDate();
|
|
|
let hh = now.getHours();
|
|
|
let mm = now.getMinutes();
|
|
|
let ss = now.getSeconds();
|
|
|
let clock = year + "-";
|
|
|
let sClock = "";
|
|
|
let dayw = now.getDay();
|
|
|
let week = weeks[dayw];
|
|
|
if (month < 10) clock += "0";
|
|
|
clock += month + "-";
|
|
|
if (day < 10) clock += "0";
|
|
|
clock += day + " ";
|
|
|
if (hh < 10) sClock += "0";
|
|
|
sClock += hh + ":";
|
|
|
if (mm < 10) sClock += "0";
|
|
|
sClock += mm + ":";
|
|
|
if (ss < 10) sClock += "0";
|
|
|
sClock += ss;
|
|
|
return { clock: clock, sClock: sClock, week: week };
|
|
|
},
|
|
|
getDatetimeSs() {
|
|
|
let now = new Date();
|
|
|
let year = now.getFullYear();
|
|
|
let month = now.getMonth() + 1;
|
|
|
let day = now.getDate();
|
|
|
let hh = now.getHours();
|
|
|
let mm = now.getMinutes();
|
|
|
let ss = now.getSeconds();
|
|
|
let clock = year + "";
|
|
|
let sClock = "";
|
|
|
if (month < 10) clock += "0";
|
|
|
clock += month + "";
|
|
|
if (day < 10) clock += "0";
|
|
|
clock += day + "";
|
|
|
if (hh < 10) sClock += "0";
|
|
|
sClock += hh + "";
|
|
|
if (mm < 10) sClock += "0";
|
|
|
sClock += mm + "";
|
|
|
if (ss < 10) sClock += "0";
|
|
|
sClock += ss;
|
|
|
return clock + sClock;
|
|
|
},
|
|
|
},
|
|
|
filters: {
|
|
|
// 处理超出字后面...
|
|
|
doStr(str, n) {
|
|
|
let totalCount = 0;
|
|
|
let txt = "";
|
|
|
for (var i = 0; i < str.length; i++) {
|
|
|
let c = str.charCodeAt(i);
|
|
|
if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
|
|
|
totalCount++;
|
|
|
} else {
|
|
|
totalCount += 2;
|
|
|
}
|
|
|
if (totalCount <= n) {
|
|
|
txt += str[i];
|
|
|
} else {
|
|
|
txt += '...';
|
|
|
return txt
|
|
|
}
|
|
|
}
|
|
|
return txt;
|
|
|
},
|
|
|
// 数字转化成金额
|
|
|
formatMoney(val, places, symbol, thousand, decimal) {
|
|
|
places = !isNaN(places = Math.abs(places)) ? places : 2;
|
|
|
symbol = symbol !== undefined ? symbol : "¥";
|
|
|
thousand = thousand || ",";
|
|
|
decimal = decimal || ".";
|
|
|
let number = !isNaN(parseFloat(val)) ? parseFloat(val) : 0;
|
|
|
let negative = number < 0 ? "-" : "";
|
|
|
let i = parseInt(number = Math.abs(+val || 0).toFixed(places), 10) + "";
|
|
|
let j = (j = i.length) > 3 ? j % 3 : 0;
|
|
|
return symbol + negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|