mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): 添加百度地图插件
This commit is contained in:
@ -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
|
||||
};
|
||||
|
@ -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 }
|
||||
|
45
src/hooks/common/useScript.ts
Normal file
45
src/hooks/common/useScript.ts
Normal 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
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user