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
};
}