UNPKG

@fmdevui/fm-dev

Version:

Page level components developed based on Element Plus.

149 lines (144 loc) 4.42 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var vueRouter = require('vue-router'); var inpinia = require('../../stores/inpinia.js'); var pinia = require('pinia'); require('../../stores/index.js'); var index = require('../../locales/index.js'); var index$1 = require('../storage/index.js'); var toolsValidate = require('../comm/toolsValidate.js'); var themeConfig = require('../../stores/themeConfig.js'); function useTitle() { const stores = themeConfig.useThemeConfig(inpinia.pinia); const { themeConfig: themeConfig$1 } = pinia.storeToRefs(stores); const router = vueRouter.useRouter(); vue.nextTick(() => { let webTitle = ""; let globalTitle = themeConfig$1.value.globalTitle; const { path, meta } = router.currentRoute.value; if (path === "/login") { webTitle = meta.title; } else { webTitle = setTagsViewNameI18n(router.currentRoute.value); } document.title = `${webTitle} - ${globalTitle}` || globalTitle; }); } function setTagsViewNameI18n(item) { let tagsViewName = ""; const { query, params, meta } = item; const pattern = /^\{("(zh-CN|en|zh-TW)":"[^,]+",?){1,3}}$/; if (query?.tagsViewName || params?.tagsViewName) { if (pattern.test(query?.tagsViewName) || pattern.test(params?.tagsViewName)) { const urlTagsParams = query?.tagsViewName && JSON.parse(query?.tagsViewName) || params?.tagsViewName && JSON.parse(params?.tagsViewName); tagsViewName = urlTagsParams[index.i18n.global.locale.value]; } else { tagsViewName = query?.tagsViewName || params?.tagsViewName; } } else { tagsViewName = index.i18n.global.t(`message.menu.${meta.title}`); } return tagsViewName; } const lazyImg = (el, arr) => { const io = new IntersectionObserver((res) => { res.forEach((v) => { if (v.isIntersecting) { const { img, key } = v.target.dataset; v.target.src = img; v.target.onload = () => { io.unobserve(v.target); arr[key]["loading"] = false; }; } }); }); vue.nextTick(() => { document.querySelectorAll(el).forEach((img) => io.observe(img)); }); }; const globalComponentSize = () => { const stores = themeConfig.useThemeConfig(inpinia.pinia); const { themeConfig: themeConfig$1 } = pinia.storeToRefs(stores); return index$1.Local.get("themeConfig")?.globalComponentSize || themeConfig$1.value?.globalComponentSize; }; function deepClone(obj) { let newObj; try { newObj = obj.push ? [] : {}; } catch (error) { newObj = {}; } for (let attr in obj) { if (obj[attr] && typeof obj[attr] === "object") { newObj[attr] = deepClone(obj[attr]); } else { newObj[attr] = obj[attr]; } } return newObj; } function isMobile() { if (navigator.userAgent.match(/('phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone')/i)) { return true; } else { return false; } } function handleEmpty(list) { const arr = []; for (const i in list) { const d = []; for (const j in list[i]) { d.push(list[i][j]); } const leng = d.filter((item) => item === "").length; if (leng !== d.length) { arr.push(list[i]); } } return arr; } function handleOpenLink(val) { const { origin, pathname } = window.location; const router = vueRouter.useRouter(); router.push(val.path); if (toolsValidate.verifyUrl(val.meta?.isLink)) window.open(val.meta?.isLink); else window.open(`${origin}${pathname}#${val.meta?.isLink}`); } const other = { useTitle: () => { useTitle(); }, setTagsViewNameI18n(route) { return setTagsViewNameI18n(route); }, lazyImg: (el, arr) => { lazyImg(el, arr); }, globalComponentSize: () => { return globalComponentSize(); }, deepClone: (obj) => { return deepClone(obj); }, isMobile: () => { return isMobile(); }, handleEmpty: (list) => { return handleEmpty(list); }, handleOpenLink: (val) => { handleOpenLink(val); } }; exports.deepClone = deepClone; exports.default = other; exports.globalComponentSize = globalComponentSize; exports.handleEmpty = handleEmpty; exports.handleOpenLink = handleOpenLink; exports.isMobile = isMobile; exports.lazyImg = lazyImg; exports.setTagsViewNameI18n = setTagsViewNameI18n; exports.useTitle = useTitle;