feat(projects): 添加百度地图插件

This commit is contained in:
Soybean
2021-11-09 23:22:40 +08:00
parent f82a4f0aed
commit 6abe094ff2
15 changed files with 568 additions and 499 deletions

View File

@ -7,6 +7,7 @@ import useRouteProps from './useRouteProps';
import useBoolean from './useBoolean';
import useLoading from './useLoading';
import useScrollBehavior from './useScrollBehavior';
import useScript from './useScript';
export {
useAppTitle,
@ -17,5 +18,6 @@ export {
useRouteProps,
useBoolean,
useLoading,
useScrollBehavior
useScrollBehavior,
useScript
};

View File

@ -28,7 +28,7 @@ export default function useRouterChange(inSetup: boolean = true) {
* @param module - 展示的登录模块
* @param redirectUrl - 重定向地址
*/
function toLogin(module: LoginModuleType = 'pwd-login', redirectUrl?: LoginRedirect) {
function toLogin(module: LoginModuleType = 'pwd-login', redirectUrl: LoginRedirect = 'current') {
const routeLocation: RouteLocationRaw = {
path: EnumRoutePath.login,
query: { module }

View File

@ -0,0 +1,45 @@
import { onUnmounted } from 'vue';
import useLoading from './useLoading';
import useBoolean from './useBoolean';
export default function useScript(src: string) {
const { loading, startLoading, endLoading } = useLoading();
const { bool: isSuccess, setTrue: setIsSuccess, setFalse: setNotSuccess } = useBoolean();
let script: HTMLScriptElement;
function removeScript() {
if (script) {
script.remove();
}
}
function load() {
startLoading();
return new Promise((resolve, reject) => {
script = document.createElement('script');
script.type = 'text/javascript';
script.onload = () => {
endLoading();
setIsSuccess();
resolve('');
};
script.onerror = err => {
endLoading();
setNotSuccess();
reject(err);
};
script.src = src;
document.head.appendChild(script);
});
}
onUnmounted(() => {
removeScript();
});
return {
loading,
isSuccess,
load
};
}

2
src/settings/constant.ts Normal file
View File

@ -0,0 +1,2 @@
/** 百度地图sdk地址 */
export const BAIDU_MAP_SDK_URL = 'https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=KSezYymXPth1DIGILRX3oYN9PxbOQQmU';

View File

@ -1 +1,2 @@
export * from './theme';
export * from './constant';

1
src/typings/bmapgl.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="bmapgl" />

View File

@ -1,12 +1,12 @@
<template>
<div>
<n-card title="富文本插件" class="shadow-sm rounded-16px">
<div ref="domRef" class="dark:bg-dark"></div>
<template #footer>
<github-link link="https://github.com/wangeditor-team/wangEditor" />
</template>
</n-card>
</div>
<div>
<n-card title="富文本插件" class="shadow-sm rounded-16px">
<div ref="domRef" class="dark:bg-dark"></div>
<template #footer>
<github-link link="https://github.com/wangeditor-team/wangEditor" />
</template>
</n-card>
</div>
</template>
<script setup lang="ts">
@ -19,24 +19,26 @@ const editor = ref<WangEditor | null>(null);
const domRef = ref<HTMLElement | null>(null);
function renderWangEditor() {
editor.value = new WangEditor(domRef.value);
setEditorConfig();
editor.value.create();
editor.value = new WangEditor(domRef.value);
setEditorConfig();
editor.value.create();
}
function setEditorConfig() {
editor.value!.config.zIndex = 10;
editor.value!.config.zIndex = 10;
}
onMounted(() => {
renderWangEditor();
renderWangEditor();
});
</script>
<style scoped>
:deep(.w-e-text-container) {
background: inherit;
}
:deep(.w-e-toolbar) {
background: inherit !important;
background: inherit !important;
border-color: #999 !important;
}
:deep(.w-e-text-container) {
background: inherit;
border-color: #999 !important;
}
</style>

View File

@ -0,0 +1,27 @@
<template>
<div ref="domRef" class="w-full h-full"></div>
</template>
<script setup lang="ts">
import { ref, onMounted, nextTick } from 'vue';
import { BAIDU_MAP_SDK_URL } from '@/settings';
import { useScript } from '@/hooks';
const { load } = useScript(BAIDU_MAP_SDK_URL);
const domRef = ref<HTMLDivElement | null>(null);
async function renderBaiduMap() {
await load();
await nextTick();
const map = new BMapGL.Map(domRef.value!);
const point = new BMapGL.Point(116.404, 39.915);
map.centerAndZoom(point, 15);
map.enableScrollWheelZoom();
}
onMounted(() => {
renderBaiduMap();
});
</script>
<style scoped></style>

View File

@ -0,0 +1,6 @@
<template>
<div>地图</div>
</template>
<script setup lang="ts"></script>
<style scoped></style>

View File

@ -0,0 +1,6 @@
<template>
<div>地图</div>
</template>
<script setup lang="ts"></script>
<style scoped></style>

View File

@ -0,0 +1,5 @@
import BaiduMap from './BaiduMap.vue';
import GaodeMap from './GaodeMap.vue';
import TencentMap from './TencentMap.vue';
export { BaiduMap, GaodeMap, TencentMap };

View File

@ -1,6 +1,30 @@
<template>
<div>地图</div>
<div>
<n-card title="地图插件" class="h-full shadow-sm rounded-16px">
<n-tabs type="line" class="flex-col-stretch h-full" pane-class="flex-1-hidden">
<n-tab-pane v-for="item in maps" :key="item.id" :name="item.id" :tab="item.label">
<component :is="item.component" />
</n-tab-pane>
</n-tabs>
</n-card>
</div>
</template>
<script setup lang="ts"></script>
<script setup lang="ts">
import type { Component } from 'vue';
import { NCard, NTabs, NTabPane } from 'naive-ui';
import { BaiduMap, GaodeMap, TencentMap } from './components';
interface Map {
id: string;
label: string;
component: Component;
}
const maps: Map[] = [
{ id: 'baidu', label: '百度地图', component: BaiduMap },
{ id: 'gaode', label: '高德地图', component: GaodeMap },
{ id: 'tencent', label: '腾讯地图', component: TencentMap }
];
</script>
<style scoped></style>