提交 a9462f0d 编写于 作者: V Vben

feat(map): added AMap/Baidu/Google Map example close #81

上级 a89eeef6
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
- 图标选择器新增 svg 模式 - 图标选择器新增 svg 模式
- 新增时间组件 - 新增时间组件
- 新增高德/百度/谷歌地图示例
### ✨ Refactor ### ✨ Refactor
......
import { resolve } from 'path';
import type { Alias } from 'vite';
function pathResolve(dir: string) {
return resolve(__dirname, '.', dir);
}
export function createAlias(alias: [string, string][]): Alias[] {
return alias.map((item) => {
const [alia, src] = item;
return {
find: new RegExp(alia),
replacement: pathResolve(src) + '/',
};
});
}
...@@ -47,7 +47,7 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { ...@@ -47,7 +47,7 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
vitePlugins.push(PurgeIcons()); vitePlugins.push(PurgeIcons());
// vite-plugin-style-import // vite-plugin-style-import
vitePlugins.push(configStyleImportPlugin()); vitePlugins.push(configStyleImportPlugin(isBuild));
// rollup-plugin-visualizer // rollup-plugin-visualizer
vitePlugins.push(configVisualizerConfig()); vitePlugins.push(configVisualizerConfig());
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
import styleImport from 'vite-plugin-style-import'; import styleImport from 'vite-plugin-style-import';
export function configStyleImportPlugin() { export function configStyleImportPlugin(isBuild: boolean) {
// if (!isBuild) return []; if (!isBuild) return [];
const pwaPlugin = styleImport({ const pwaPlugin = styleImport({
libs: [ libs: [
{ {
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated'; import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated';
import ImgUpload from './ImgUpload.vue'; import ImgUpload from './ImgUpload.vue';
import { useDesign } from '/@/hooks/web/useDesign'; import { useDesign } from '/@/hooks/web/useDesign';
import { isNumber } from '/@/utils/is';
const CDN_URL = 'https://cdn.bootcdn.net/ajax/libs/tinymce/5.5.1'; const CDN_URL = 'https://cdn.bootcdn.net/ajax/libs/tinymce/5.5.1';
...@@ -56,7 +57,7 @@ ...@@ -56,7 +57,7 @@
const containerWidth = computed(() => { const containerWidth = computed(() => {
const width = props.width; const width = props.width;
if (/^[\d]+(\.[\d]+)?$/.test(width.toString())) { if (isNumber(width)) {
return `${width}px`; return `${width}px`;
} }
return width; return width;
......
...@@ -12,6 +12,7 @@ export function useScript(opts: ScriptOptions) { ...@@ -12,6 +12,7 @@ export function useScript(opts: ScriptOptions) {
const promise = new Promise((resolve, reject) => { const promise = new Promise((resolve, reject) => {
onMounted(() => { onMounted(() => {
const script = document.createElement('script'); const script = document.createElement('script');
script.type = 'text/javascript';
script.onload = function () { script.onload = function () {
isLoading.value = false; isLoading.value = false;
success.value = true; success.value = true;
......
export default { export default {
baiduMap: 'Baidu map',
aMap: 'A map',
googleMap: 'Google map',
charts: 'Chart', charts: 'Chart',
map: 'Map', map: 'Map',
line: 'Line', line: 'Line',
......
export default { export default {
baiduMap: '百度地图',
aMap: '高德地图',
googleMap: '谷歌地图',
charts: '图表', charts: '图表',
map: '地图', map: '地图',
line: '折线图', line: '折线图',
......
import '/@/design/index.less'; import '/@/design/index.less';
import '@virtual/windi.css'; import '@virtual/windi.css';
// Do not introduce on-demand in local development?
// In the local development for on-demand introduction, the number of browser requests will increase by about 20%.
// Which may slow down the browser refresh.
// Therefore, all are introduced in local development, and only introduced on demand in the production environment
if (import.meta.env.DEV) {
import('ant-design-vue/dist/antd.less');
}
import { createApp } from 'vue'; import { createApp } from 'vue';
import App from './App.vue'; import App from './App.vue';
......
...@@ -6,11 +6,37 @@ const menu: MenuModule = { ...@@ -6,11 +6,37 @@ const menu: MenuModule = {
menu: { menu: {
name: t('routes.demo.charts.charts'), name: t('routes.demo.charts.charts'),
path: '/charts', path: '/charts',
tag: {
content: 'new',
},
children: [ children: [
{
path: 'aMap',
name: t('routes.demo.charts.aMap'),
tag: {
dot: true,
},
},
{
path: 'baiduMap',
name: t('routes.demo.charts.baiduMap'),
tag: {
dot: true,
},
},
{
path: 'googleMap',
name: t('routes.demo.charts.googleMap'),
tag: {
dot: true,
},
},
{ {
path: 'apexChart', path: 'apexChart',
name: t('routes.demo.charts.apexChart'), name: t('routes.demo.charts.apexChart'),
}, },
{ {
path: 'echarts', path: 'echarts',
name: 'Echarts', name: 'Echarts',
......
...@@ -13,13 +13,38 @@ const charts: AppRouteModule = { ...@@ -13,13 +13,38 @@ const charts: AppRouteModule = {
title: t('routes.demo.charts.charts'), title: t('routes.demo.charts.charts'),
}, },
children: [ children: [
{
path: 'baiduMap',
name: 'BaiduMap',
meta: {
title: t('routes.demo.charts.baiduMap'),
},
component: () => import('/@/views/demo/charts/map/Baidu.vue'),
},
{
path: 'aMap',
name: 'AMap',
meta: {
title: t('routes.demo.charts.aMap'),
},
component: () => import('/@/views/demo/charts/map/Amap.vue'),
},
{
path: 'googleMap',
name: 'GoogleMap',
meta: {
title: t('routes.demo.charts.googleMap'),
},
component: () => import('/@/views/demo/charts/map/Google.vue'),
},
{ {
path: 'apexChart', path: 'apexChart',
name: 'ApexChart', name: 'ApexChart',
meta: { meta: {
title: t('routes.demo.charts.apexChart'), title: t('routes.demo.charts.apexChart'),
}, },
component: () => import('/@/views/demo/echarts/apex/index.vue'), component: () => import('/@/views/demo/charts/apex/index.vue'),
}, },
{ {
path: 'echarts', path: 'echarts',
...@@ -33,7 +58,7 @@ const charts: AppRouteModule = { ...@@ -33,7 +58,7 @@ const charts: AppRouteModule = {
{ {
path: 'map', path: 'map',
name: 'Map', name: 'Map',
component: () => import('/@/views/demo/echarts/Map.vue'), component: () => import('/@/views/demo/charts/Map.vue'),
meta: { meta: {
title: t('routes.demo.charts.map'), title: t('routes.demo.charts.map'),
}, },
...@@ -41,7 +66,7 @@ const charts: AppRouteModule = { ...@@ -41,7 +66,7 @@ const charts: AppRouteModule = {
{ {
path: 'line', path: 'line',
name: 'Line', name: 'Line',
component: () => import('/@/views/demo/echarts/Line.vue'), component: () => import('/@/views/demo/charts/Line.vue'),
meta: { meta: {
title: t('routes.demo.charts.line'), title: t('routes.demo.charts.line'),
}, },
...@@ -49,7 +74,7 @@ const charts: AppRouteModule = { ...@@ -49,7 +74,7 @@ const charts: AppRouteModule = {
{ {
path: 'pie', path: 'pie',
name: 'Pie', name: 'Pie',
component: () => import('/@/views/demo/echarts/Pie.vue'), component: () => import('/@/views/demo/charts/Pie.vue'),
meta: { meta: {
title: t('routes.demo.charts.pie'), title: t('routes.demo.charts.pie'),
}, },
......
<template>
<div ref="wrapRef" :style="{ height, width }"></div>
</template>
<script lang="ts">
import { defineComponent, ref, nextTick, unref, onMounted } from 'vue';
import { useScript } from '/@/hooks/web/useScript';
const A_MAP_URL = 'https://webapi.amap.com/maps?v=2.0&key=d7bb98e7185300250dd5f918c12f484b';
export default defineComponent({
name: 'AMap',
props: {
width: {
type: String,
default: '100%',
},
height: {
type: String,
default: 'calc(100vh - 78px)',
},
},
setup() {
const wrapRef = ref<HTMLDivElement | null>(null);
const { toPromise } = useScript({ src: A_MAP_URL });
async function initMap() {
await toPromise();
await nextTick();
const wrapEl = unref(wrapRef);
if (!wrapEl) return;
const AMap = (window as any).AMap;
new AMap.Map(wrapEl, {
zoom: 11,
center: [116.397428, 39.90923],
viewMode: '3D',
});
}
onMounted(() => {
initMap();
});
return { wrapRef };
},
});
</script>
<template>
<div ref="wrapRef" :style="{ height, width }"></div>
</template>
<script lang="ts">
import { defineComponent, ref, nextTick, unref, onMounted } from 'vue';
import { useScript } from '/@/hooks/web/useScript';
const BAI_DU_MAP_URL =
'https://api.map.baidu.com/getscript?v=3.0&ak=OaBvYmKX3pjF7YFUFeeBCeGdy9Zp7xB2&services=&t=20210201100830';
export default defineComponent({
name: 'BaiduMap',
props: {
width: {
type: String,
default: '100%',
},
height: {
type: String,
default: 'calc(100vh - 78px)',
},
},
setup() {
const wrapRef = ref<HTMLDivElement | null>(null);
const { toPromise } = useScript({ src: BAI_DU_MAP_URL });
async function initMap() {
await toPromise();
await nextTick();
const wrapEl = unref(wrapRef);
if (!wrapEl) return;
const BMap = (window as any).BMap;
const map = new BMap.Map(wrapEl);
const point = new BMap.Point(116.404, 39.915);
map.centerAndZoom(point, 15);
map.enableScrollWheelZoom(true);
}
onMounted(() => {
initMap();
});
return { wrapRef };
},
});
</script>
<template>
<div ref="wrapRef" :style="{ height, width }"></div>
</template>
<script lang="ts">
import { defineComponent, ref, nextTick, unref, onMounted } from 'vue';
import { useScript } from '/@/hooks/web/useScript';
const MAP_URL =
'https://maps.googleapis.com/maps/api/js?key=AIzaSyBQWrrGwj4gAzKndcbwD5favT9K0wgty_0&signed_in=true';
export default defineComponent({
name: 'GoogleMap',
props: {
width: {
type: String,
default: '100%',
},
height: {
type: String,
default: 'calc(100vh - 78px)',
},
},
setup() {
const wrapRef = ref<HTMLDivElement | null>(null);
const { toPromise } = useScript({ src: MAP_URL });
async function initMap() {
await toPromise();
await nextTick();
const wrapEl = unref(wrapRef);
if (!wrapEl) return;
const google = (window as any).google;
const latLng = { lat: 116.404, lng: 39.915 };
const map = new google.maps.Map(wrapEl, {
zoom: 4,
center: latLng,
});
new google.maps.Marker({
position: latLng,
map: map,
title: 'Hello World!',
});
}
onMounted(() => {
initMap();
});
return { wrapRef };
},
});
</script>
...@@ -5,14 +5,11 @@ import { resolve } from 'path'; ...@@ -5,14 +5,11 @@ import { resolve } from 'path';
import { generateModifyVars } from './build/config/themeConfig'; import { generateModifyVars } from './build/config/themeConfig';
import { createProxy } from './build/vite/proxy'; import { createProxy } from './build/vite/proxy';
import { createAlias } from './build/vite/alias';
import { wrapperEnv } from './build/utils'; import { wrapperEnv } from './build/utils';
import { createVitePlugins } from './build/vite/plugin'; import { createVitePlugins } from './build/vite/plugin';
import { OUTPUT_DIR } from './build/constant'; import { OUTPUT_DIR } from './build/constant';
function pathResolve(dir: string) {
return resolve(__dirname, '.', dir);
}
export default ({ command, mode }: ConfigEnv): UserConfig => { export default ({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd(); const root = process.cwd();
...@@ -29,18 +26,12 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { ...@@ -29,18 +26,12 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
base: VITE_PUBLIC_PATH, base: VITE_PUBLIC_PATH,
root, root,
resolve: { resolve: {
alias: [ alias: createAlias([
{ // /@/xxxx => src/xxxx
// /@/xxxx => src/xxx ['/@/', 'src'],
find: /^\/@\//, // /#/xxxx => types/xxxx
replacement: pathResolve('src') + '/', ['/#/', 'types'],
}, ]),
{
// /#/xxxx => types/xxx
find: /^\/#\//,
replacement: pathResolve('types') + '/',
},
],
}, },
server: { server: {
port: VITE_PORT, port: VITE_PORT,
...@@ -52,7 +43,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { ...@@ -52,7 +43,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
}, },
build: { build: {
// minify: 'esbuild', minify: 'esbuild',
outDir: OUTPUT_DIR, outDir: OUTPUT_DIR,
polyfillDynamicImport: VITE_LEGACY, polyfillDynamicImport: VITE_LEGACY,
terserOptions: { terserOptions: {
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册