perf: fix some types and delete some redundant

This commit is contained in:
xiaoxian521 2021-04-28 16:48:03 +08:00
parent 8cb2d896ad
commit 89162dee1e
14 changed files with 59 additions and 65 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB

View File

@ -59,12 +59,6 @@ export default defineComponent({
() => getBreadcrumb() () => getBreadcrumb()
); );
// const pathCompile = (path: string): string | Object => {
// const { params } = route;
// var toPath = pathToRegexp.compile(path);
// return toPath(params);
// };
const handleLink = (item: RouteLocationMatched): any => { const handleLink = (item: RouteLocationMatched): any => {
const { redirect, path } = item; const { redirect, path } = item;
if (redirect) { if (redirect) {

View File

@ -13,20 +13,20 @@ export default defineComponent({
// //
frontText: { frontText: {
type: [Number, String], type: [Number, String],
default: 0, default: 0
}, },
// back paper text // back paper text
// //
backText: { backText: {
type: [Number, String], type: [Number, String],
default: 1, default: 1
}, },
// flipping duration, please be consistent with the CSS animation-duration value. // flipping duration, please be consistent with the CSS animation-duration value.
// CSSanimation-duration // CSSanimation-duration
duration: { duration: {
type: Number, type: Number,
default: 600, default: 600
}, }
}, },
setup(props) { setup(props) {
const { frontText, backText, duration } = props; const { frontText, backText, duration } = props;
@ -86,9 +86,9 @@ export default defineComponent({
flipDown, flipDown,
flipUp, flipUp,
setFront, setFront,
setBack, setBack
}; };
}, }
}); });
</script> </script>

View File

@ -31,16 +31,16 @@ import { templateRef } from "@vueuse/core";
export default defineComponent({ export default defineComponent({
name: "Control", name: "Control",
props: { props: {
lf: Object || String, lf: <ElRef>Object,
catTurboData: Boolean catTurboData: Boolean
}, },
emits: ["catData"], emits: ["catData"],
setup(props, { emit }) { setup(props, { emit }) {
const controlButton3 = templateRef<HTMLElement | null>( const controlButton3 = templateRef<HTMLElement | any>(
"controlButton3", "controlButton3",
null null
); );
const controlButton4 = templateRef<HTMLElement | null>( const controlButton4 = templateRef<HTMLElement | any>(
"controlButton4", "controlButton4",
null null
); );

View File

@ -16,24 +16,24 @@ import {
toRefs, toRefs,
defineComponent, defineComponent,
onBeforeMount, onBeforeMount,
getCurrentInstance, getCurrentInstance
} from "vue"; } from "vue";
import { mapJson } from "/@/api/mock"; import { mapJson } from "/@/api/mock";
import { deviceDetection } from "/@/utils/deviceDetection" import { deviceDetection } from "/@/utils/deviceDetection";
import greenCar from "/@/assets/green.png"; import greenCar from "/@/assets/green.png";
let MarkerCluster = null; let MarkerCluster = <ElRef>null;
export interface MapConfigureInter { export interface MapConfigureInter {
on: any; on: Fn;
destroy?: any; destroy?: Fn;
clearEvents?: any; clearEvents?: Fn;
plugin?: any; addControl?: Fn;
addControl?: any; setCenter?: Fn;
setCenter?: any; setZoom?: Fn;
setZoom?: any; plugin?: Fn;
} }
export interface mapInter { export interface mapInter {
@ -47,7 +47,7 @@ export default defineComponent({
let map: MapConfigureInter; let map: MapConfigureInter;
const mapSet: mapInter = reactive({ const mapSet: mapInter = reactive({
loading: deviceDetection() ? false : true, loading: deviceDetection() ? false : true
}); });
// () // ()
@ -71,18 +71,18 @@ export default defineComponent({
if (!vm) return; if (!vm) return;
let { let {
MapConfigure, MapConfigure,
options, options
} = vm.appContext.config.globalProperties.$config; } = vm.appContext.config.globalProperties.$config;
AMapLoader.load({ AMapLoader.load({
key: MapConfigure.amapKey, key: MapConfigure.amapKey,
version: "2.0", version: "2.0",
plugins: ["AMap.MarkerCluster"], plugins: ["AMap.MarkerCluster"]
}) })
.then((AMap) => { .then(AMap => {
// //
map = new AMap.Map(vm.refs.mapview, { map = new AMap.Map(vm.refs.mapview, {
options, options
}); });
//ToolBar //ToolBar
@ -91,7 +91,7 @@ export default defineComponent({
// //
map.addControl( map.addControl(
new AMap.MapType({ new AMap.MapType({
defaultType: 0, defaultType: 0
}) })
); );
}); });
@ -103,14 +103,13 @@ export default defineComponent({
let { marker, data } = ctx; let { marker, data } = ctx;
if (Array.isArray(data) && data[0]) { if (Array.isArray(data) && data[0]) {
var { driver, plateNumber, orientation } = data[0]; var { driver, plateNumber, orientation } = data[0];
var content = `<img style="transform: scale(1) rotate(${ var content = `<img style="transform: scale(1) rotate(${360 -
360 - Number(orientation) Number(orientation)}deg);" src='${greenCar}' />`;
}deg);" src='${greenCar}' />`;
marker.setContent(content); marker.setContent(content);
marker.setLabel({ marker.setLabel({
direction: "bottom", direction: "bottom",
offset: new AMap.Pixel(-4, 0), // offset: new AMap.Pixel(-4, 0), //
content: `<div> ${plateNumber}(${driver})</div>`, // content: `<div> ${plateNumber}(${driver})</div>` //
}); });
marker.setOffset(new AMap.Pixel(-18, -10)); marker.setOffset(new AMap.Pixel(-18, -10));
marker.on("click", ({ lnglat }) => { marker.on("click", ({ lnglat }) => {
@ -118,27 +117,27 @@ export default defineComponent({
map.setCenter(lnglat); map.setCenter(lnglat);
}); });
} }
}, }
}); });
// //
mapJson() mapJson()
.then((res) => { .then(res => {
let points: object = res.info.map((v: any) => { let points: object = res.info.map((v: any) => {
return { return {
lnglat: [v.lng, v.lat], lnglat: [v.lng, v.lat],
...v, ...v
}; };
}); });
if (MarkerCluster) MarkerCluster.setData(points); if (MarkerCluster) MarkerCluster.setData(points);
}) })
.catch((err) => { .catch(err => {
console.log("err:", err); console.log("err:", err);
}); });
complete(); complete();
}) })
.catch((err) => { .catch(err => {
mapSet.loading = false; mapSet.loading = false;
throw "地图加载失败,请重新加载"; throw "地图加载失败,请重新加载";
}); });
@ -148,9 +147,9 @@ export default defineComponent({
...toRefs(mapSet), ...toRefs(mapSet),
complete, complete,
destroyMap, destroyMap,
greenCar, greenCar
}; };
}, }
}); });
</script> </script>

View File

@ -1,11 +1,12 @@
// 延迟函数 // 延迟函数
export const delay = (timeout: number) => new Promise(resolve => setTimeout(resolve, timeout)) export const delay = (timeout: number) =>
new Promise((resolve) => setTimeout(resolve, timeout));
// 防抖函数 // 防抖函数
export const debounce = (fn: () => any, timeout: number) => { export const debounce = (fn: () => Fn, timeout: number) => {
let timmer: any let timmer: TimeoutHandle;
return () => { return () => {
timmer ? clearTimeout(timmer) : null timmer ? clearTimeout(timmer) : null;
timmer = setTimeout(fn, timeout) timmer = setTimeout(fn, timeout);
} };
} };

View File

@ -1,18 +1,18 @@
interface deviceInter { interface deviceInter {
match: any match: Fn;
} }
// 检测设备类型(手机返回true,反之) // 检测设备类型(手机返回true,反之)
export const deviceDetection = () => { export const deviceDetection = () => {
let sUserAgent: deviceInter = navigator.userAgent.toLowerCase() let sUserAgent: deviceInter = navigator.userAgent.toLowerCase();
let bIsIpad = sUserAgent.match(/ipad/i) == "ipad" let bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
let bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os" let bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
let bIsMidp = sUserAgent.match(/midp/i) == "midp" let bIsMidp = sUserAgent.match(/midp/i) == "midp";
let bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4" let bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
let bIsUc = sUserAgent.match(/ucweb/i) == "ucweb" let bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
let bIsAndroid = sUserAgent.match(/android/i) == "android" let bIsAndroid = sUserAgent.match(/android/i) == "android";
let bIsCE = sUserAgent.match(/windows ce/i) == "windows ce" let bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
let bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile" let bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
return bIsIphoneOs || return bIsIphoneOs ||
bIsMidp || bIsMidp ||
bIsUc7 || bIsUc7 ||
@ -21,5 +21,5 @@ export const deviceDetection = () => {
bIsCE || bIsCE ||
bIsWM bIsWM
? true ? true
: false : false;
}; };

View File

@ -39,7 +39,7 @@ export default {
SeamlessScroll SeamlessScroll
}, },
setup() { setup() {
const scroll = templateRef<HTMLElement | null>("scroll", null); const scroll = templateRef<ElRef | null>("scroll", null);
let listData = ref([ let listData = ref([
{ {
@ -76,8 +76,8 @@ export default {
}); });
function changeDirection(val) { function changeDirection(val) {
scroll.value.reset(); unref(scroll).reset();
classOption.value.direction = val; unref(classOption).direction = val;
} }
return { return {

View File

@ -30,7 +30,7 @@ import demoData from "./dataTurbo.json";
export default { export default {
components: { NodePanel, Control, DataDialog }, components: { NodePanel, Control, DataDialog },
setup() { setup() {
let lf = ref(null); let lf = ref<ElRef>(null);
let graphData = ref(null); let graphData = ref(null);
let dataVisible = ref(false); let dataVisible = ref(false);
let config = ref({ let config = ref({