fix:修改utils
This commit is contained in:
parent
8dc4769b64
commit
d388bea7bd
@ -1,7 +1,7 @@
|
|||||||
import axios, { AxiosResponse, AxiosRequestConfig } from 'axios'
|
import axios, { AxiosResponse, AxiosRequestConfig } from 'axios'
|
||||||
import { ResultEnum } from "@/enums/httpEnum"
|
import { ResultEnum } from "@/enums/httpEnum"
|
||||||
import { ErrorPageNameMap } from "@/enums/pageEnum"
|
import { ErrorPageNameMap } from "@/enums/pageEnum"
|
||||||
import { redirectErrorPage } from '@/utils/page'
|
import { redirectErrorPage } from '@/utils'
|
||||||
|
|
||||||
const axiosInstance = axios.create({
|
const axiosInstance = axios.create({
|
||||||
baseURL: import.meta.env.DEV ? import.meta.env.VITE_DEV_PATH : import.meta.env.VITE_PRO_PATH,
|
baseURL: import.meta.env.DEV ? import.meta.env.VITE_DEV_PATH : import.meta.env.VITE_PRO_PATH,
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { openDoc } from '@/utils/page'
|
import { openDoc } from '@/utils'
|
||||||
import { DocumentText as DocumentTextIcon } from '@vicons/ionicons5'
|
import { DocumentText as DocumentTextIcon } from '@vicons/ionicons5'
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useDesignStore } from '@/store/modules/designStore/designStore'
|
import { useDesignStore } from '@/store/modules/designStore/designStore'
|
||||||
import { setHtmlTheme } from '@/utils/style'
|
import { setHtmlTheme } from '@/utils'
|
||||||
import { Moon as MoonIcon, Sunny as SunnyIcon } from '@vicons/ionicons5'
|
import { Moon as MoonIcon, Sunny as SunnyIcon } from '@vicons/ionicons5'
|
||||||
|
|
||||||
const designStore = useDesignStore()
|
const designStore = useDesignStore()
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { h, ref } from 'vue'
|
import { h, ref } from 'vue'
|
||||||
import { NAvatar, NText } from 'naive-ui'
|
import { NAvatar, NText } from 'naive-ui'
|
||||||
import { renderIcon } from '@/utils/index'
|
import { renderIcon } from '@/utils'
|
||||||
import { openDoc, logout } from '@/utils/page'
|
import { openDoc, logout } from '@/utils'
|
||||||
import {
|
import {
|
||||||
Person as PersonIcon,
|
Person as PersonIcon,
|
||||||
LogOutOutline as LogOutOutlineIcon,
|
LogOutOutline as LogOutOutlineIcon,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//语言
|
//语言
|
||||||
import { lang } from '@/settings/designSetting'
|
import { lang } from '@/settings/designSetting'
|
||||||
import { createI18n } from 'vue-i18n' //引入vue-i18n组件
|
import { createI18n } from 'vue-i18n' //引入vue-i18n组件
|
||||||
import { getLocalStorage } from '@/utils/storage'
|
import { getLocalStorage } from '@/utils'
|
||||||
import { GO_LANG_SELECT } from '@/settings/storageConst'
|
import { GO_LANG_SELECT } from '@/settings/storageConst'
|
||||||
import zh from './zh/index'
|
import zh from './zh/index'
|
||||||
import en from './en/index'
|
import en from './en/index'
|
||||||
|
@ -5,7 +5,7 @@ import i18n from '@/i18n/index'
|
|||||||
import { setupStore } from '@/store'
|
import { setupStore } from '@/store'
|
||||||
import { setupNaive, setupDirectives, setupCustomComponents } from '@/plugins'
|
import { setupNaive, setupDirectives, setupCustomComponents } from '@/plugins'
|
||||||
import { AppProvider } from '@/components/Application'
|
import { AppProvider } from '@/components/Application'
|
||||||
import { setHtmlTheme } from '@/utils/style'
|
import { setHtmlTheme } from '@/utils'
|
||||||
|
|
||||||
async function appInit() {
|
async function appInit() {
|
||||||
const appProvider = createApp(AppProvider)
|
const appProvider = createApp(AppProvider)
|
||||||
|
@ -10,7 +10,8 @@ import {
|
|||||||
ApertureSharp as ApertureSharpIcon,
|
ApertureSharp as ApertureSharpIcon,
|
||||||
DownloadOutline as DownloadIcon,
|
DownloadOutline as DownloadIcon,
|
||||||
Open as OpenIcon,
|
Open as OpenIcon,
|
||||||
Send as SendIcon
|
Send as SendIcon,
|
||||||
|
InformationCircleOutline as InformationCircleIcon
|
||||||
} from '@vicons/ionicons5'
|
} from '@vicons/ionicons5'
|
||||||
|
|
||||||
// ionicons5 在这里
|
// ionicons5 在这里
|
||||||
@ -39,6 +40,8 @@ const ionicons5 = {
|
|||||||
OpenIcon,
|
OpenIcon,
|
||||||
// 导出
|
// 导出
|
||||||
SendIcon,
|
SendIcon,
|
||||||
|
// 信息
|
||||||
|
InformationCircleIcon
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.xicons.org/#/ 还有很多
|
// https://www.xicons.org/#/ 还有很多
|
||||||
|
@ -46,6 +46,12 @@ export const theme = {
|
|||||||
appThemeList
|
appThemeList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dialog 图标的大小
|
||||||
|
export const dialogIconSize = '20'
|
||||||
|
|
||||||
|
// 弹窗是否可以通过点击遮罩关闭
|
||||||
|
export const maskClosable = false
|
||||||
|
|
||||||
// 侧边栏宽度
|
// 侧边栏宽度
|
||||||
export const asideWidth = '270'
|
export const asideWidth = '270'
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { defineStore } from 'pinia'
|
|||||||
import { store } from '@/store'
|
import { store } from '@/store'
|
||||||
import { theme } from '@/settings/designSetting'
|
import { theme } from '@/settings/designSetting'
|
||||||
import { DesignStateType } from './designStore.d'
|
import { DesignStateType } from './designStore.d'
|
||||||
import { setLocalStorage, getLocalStorage } from '@/utils/storage'
|
import { setLocalStorage, getLocalStorage } from '@/utils'
|
||||||
import { GO_Theme_SELECT } from '@/settings/storageConst'
|
import { GO_Theme_SELECT } from '@/settings/storageConst'
|
||||||
import { ThemeEnum } from '@/enums/styleEnum'
|
import { ThemeEnum } from '@/enums/styleEnum'
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { lang } from '@/settings/designSetting'
|
|||||||
import { LangStateType } from './langStore.d'
|
import { LangStateType } from './langStore.d'
|
||||||
import { LangEnum } from '@/enums/styleEnum'
|
import { LangEnum } from '@/enums/styleEnum'
|
||||||
import i18n from '@/i18n/index'
|
import i18n from '@/i18n/index'
|
||||||
import { setLocalStorage } from '@/utils/storage'
|
import { setLocalStorage } from '@/utils'
|
||||||
import { GO_LANG_SELECT } from '@/settings/storageConst'
|
import { GO_LANG_SELECT } from '@/settings/storageConst'
|
||||||
|
|
||||||
export const useLangStore = defineStore({
|
export const useLangStore = defineStore({
|
||||||
|
@ -1,80 +1,5 @@
|
|||||||
import { h } from 'vue'
|
export * from '@/utils/utils'
|
||||||
import { NIcon } from 'naive-ui'
|
export * from '@/utils/page'
|
||||||
import screenfull from 'screenfull'
|
export * from '@/utils/storage'
|
||||||
/**
|
export * from '@/utils/style'
|
||||||
* * 生成一个用不重复的ID
|
export * from '@/utils/plugin'
|
||||||
* @param { Number } randomLength
|
|
||||||
*/
|
|
||||||
export function getUUID(randomLength: number) {
|
|
||||||
return Number(
|
|
||||||
Math.random().toString().substr(2, randomLength) + Date.now()
|
|
||||||
).toString(36)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* * render 图标
|
|
||||||
*/
|
|
||||||
export const renderIcon = (icon: any) => {
|
|
||||||
return () => h(NIcon, null, { default: () => h(icon) })
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* * render 弹出确认框
|
|
||||||
* @param { Function } dialogFn dialog函数,暂时必须从页面传过来
|
|
||||||
* @param { Object} params 配置参数
|
|
||||||
*/
|
|
||||||
export const goDialog = (
|
|
||||||
dialogFn: Function,
|
|
||||||
params: {
|
|
||||||
// 基本
|
|
||||||
type: 'delete'
|
|
||||||
message?: string
|
|
||||||
onPositiveCallback?: Function
|
|
||||||
onNegativeCallback?: Function
|
|
||||||
// 渲染函数
|
|
||||||
render?: boolean
|
|
||||||
contentFn?: Function
|
|
||||||
actionFn?: Function
|
|
||||||
}
|
|
||||||
) => {
|
|
||||||
const { type, message, onPositiveCallback, onNegativeCallback } = params
|
|
||||||
const tip = {
|
|
||||||
delete: '是否删除此数据'
|
|
||||||
}
|
|
||||||
dialogFn({
|
|
||||||
title: '提示',
|
|
||||||
content: message || tip[type] || '',
|
|
||||||
positiveText: '确定',
|
|
||||||
negativeText: '取消',
|
|
||||||
onPositiveClick: () => {
|
|
||||||
onPositiveCallback && onPositiveCallback()
|
|
||||||
},
|
|
||||||
onNegativeClick: () => {
|
|
||||||
onNegativeCallback && onNegativeCallback()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* * 处理 vite 中无法使用 require 的问题
|
|
||||||
* @param name
|
|
||||||
* @returns url
|
|
||||||
*/
|
|
||||||
export const requireUrl = (path: string, name: string) => {
|
|
||||||
return new URL(`${path}/${name}`, import.meta.url).href
|
|
||||||
}
|
|
||||||
|
|
||||||
export const screenfullFn = (isFullscreen?: boolean, isEnabled?: boolean) => {
|
|
||||||
// 是否是全屏
|
|
||||||
if (isFullscreen) return screenfull.isFullscreen
|
|
||||||
|
|
||||||
// 是否支持全屏
|
|
||||||
if (isEnabled) return screenfull.isEnabled
|
|
||||||
|
|
||||||
if (screenfull.isEnabled) {
|
|
||||||
screenfull.toggle()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// TODO lang
|
|
||||||
window['$message'].warning('您的浏览器不支持全屏功能!')
|
|
||||||
}
|
|
43
src/utils/plugin.ts
Normal file
43
src/utils/plugin.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import { icon } from '@/plugins'
|
||||||
|
import { dialogIconSize, maskClosable } from '@/settings/designSetting'
|
||||||
|
const { InformationCircleIcon } = icon.ionicons5
|
||||||
|
import { renderIcon } from '@/utils'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * render 弹出确认框
|
||||||
|
* @param { Function } dialogFn dialog函数,暂时必须从页面传过来
|
||||||
|
* @param { Object} params 配置参数
|
||||||
|
*/
|
||||||
|
export const goDialog = (
|
||||||
|
dialogFn: Function,
|
||||||
|
params: {
|
||||||
|
// 基本
|
||||||
|
type: 'delete'
|
||||||
|
message?: string
|
||||||
|
onPositiveCallback?: Function
|
||||||
|
onNegativeCallback?: Function
|
||||||
|
// 渲染函数
|
||||||
|
render?: boolean
|
||||||
|
contentFn?: Function
|
||||||
|
actionFn?: Function
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
const { type, message, onPositiveCallback, onNegativeCallback } = params
|
||||||
|
const tip = {
|
||||||
|
delete: '是否删除此数据'
|
||||||
|
}
|
||||||
|
dialogFn({
|
||||||
|
title: '提示',
|
||||||
|
icon: renderIcon(InformationCircleIcon, { size: dialogIconSize }),
|
||||||
|
content: message || tip[type] || '',
|
||||||
|
positiveText: '确定',
|
||||||
|
negativeText: '取消',
|
||||||
|
maskClosable: maskClosable,
|
||||||
|
onPositiveClick: () => {
|
||||||
|
onPositiveCallback && onPositiveCallback()
|
||||||
|
},
|
||||||
|
onNegativeClick: () => {
|
||||||
|
onNegativeCallback && onNegativeCallback()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
44
src/utils/utils.ts
Normal file
44
src/utils/utils.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { h } from 'vue'
|
||||||
|
import { NIcon } from 'naive-ui'
|
||||||
|
import screenfull from 'screenfull'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 生成一个用不重复的ID
|
||||||
|
* @param { Number } randomLength
|
||||||
|
*/
|
||||||
|
export function getUUID(randomLength: number) {
|
||||||
|
return Number(
|
||||||
|
Math.random().toString().substr(2, randomLength) + Date.now()
|
||||||
|
).toString(36)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * render 图标
|
||||||
|
*/
|
||||||
|
export const renderIcon = (icon: any, set = {}) => {
|
||||||
|
return () => h(NIcon, set, { default: () => h(icon) })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 处理 vite 中无法使用 require 的问题
|
||||||
|
* @param name
|
||||||
|
* @returns url
|
||||||
|
*/
|
||||||
|
export const requireUrl = (path: string, name: string) => {
|
||||||
|
return new URL(`${path}/${name}`, import.meta.url).href
|
||||||
|
}
|
||||||
|
|
||||||
|
export const screenfullFn = (isFullscreen?: boolean, isEnabled?: boolean) => {
|
||||||
|
// 是否是全屏
|
||||||
|
if (isFullscreen) return screenfull.isFullscreen
|
||||||
|
|
||||||
|
// 是否支持全屏
|
||||||
|
if (isEnabled) return screenfull.isEnabled
|
||||||
|
|
||||||
|
if (screenfull.isEnabled) {
|
||||||
|
screenfull.toggle()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// TODO lang
|
||||||
|
window['$message'].warning('您的浏览器不支持全屏功能!')
|
||||||
|
}
|
@ -13,7 +13,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { PageEnum } from '@/enums/pageEnum'
|
import { PageEnum } from '@/enums/pageEnum'
|
||||||
import { routerTurnByName } from '@/utils/page'
|
import { routerTurnByName } from '@/utils'
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
function goHome() {
|
function goHome() {
|
||||||
routerTurnByName(PageEnum.BASE_HOME_NAME)
|
routerTurnByName(PageEnum.BASE_HOME_NAME)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { PageEnum } from '@/enums/pageEnum'
|
import { PageEnum } from '@/enums/pageEnum'
|
||||||
import { routerTurnByName } from '@/utils/page'
|
import { routerTurnByName } from '@/utils'
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
function goHome() {
|
function goHome() {
|
||||||
routerTurnByName(PageEnum.BASE_HOME_NAME)
|
routerTurnByName(PageEnum.BASE_HOME_NAME)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { PageEnum } from '@/enums/pageEnum'
|
import { PageEnum } from '@/enums/pageEnum'
|
||||||
import { routerTurnByName } from '@/utils/page'
|
import { routerTurnByName } from '@/utils'
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
function goHome() {
|
function goHome() {
|
||||||
routerTurnByName(PageEnum.BASE_HOME_NAME)
|
routerTurnByName(PageEnum.BASE_HOME_NAME)
|
||||||
|
@ -115,8 +115,8 @@ import { reactive, ref, onMounted } from 'vue'
|
|||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useMessage } from 'naive-ui'
|
import { useMessage } from 'naive-ui'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { requireUrl } from '@/utils/index'
|
import { requireUrl } from '@/utils'
|
||||||
import { routerTurnByName } from '@/utils/page'
|
import { routerTurnByName } from '@/utils'
|
||||||
import shuffle from 'lodash/shuffle'
|
import shuffle from 'lodash/shuffle'
|
||||||
import { carouselInterval } from '@/settings/designSetting'
|
import { carouselInterval } from '@/settings/designSetting'
|
||||||
import { useDesignStore } from '@/store/modules/designStore/designStore'
|
import { useDesignStore } from '@/store/modules/designStore/designStore'
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<div class="list-content">
|
<div class="list-content">
|
||||||
<!-- 顶部按钮 -->
|
<!-- 顶部按钮 -->
|
||||||
<n-space class="list-content-top">
|
<n-space class="list-content-top">
|
||||||
<AppleControlBtn @close="deleteHanlde" @resize="resizeHandle" />
|
<AppleControlBtn :hidden="['remove']" @close="deleteHanlde" @resize="resizeHandle" />
|
||||||
</n-space>
|
</n-space>
|
||||||
<!-- 中间 -->
|
<!-- 中间 -->
|
||||||
<div class="list-content-img">
|
<div class="list-content-img">
|
||||||
@ -72,7 +72,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { renderIcon, goDialog } from '@/utils/index'
|
import { renderIcon, goDialog } from '@/utils'
|
||||||
import { icon } from '@/plugins'
|
import { icon } from '@/plugins'
|
||||||
import { AppleControlBtn } from '@/components/AppleControlBtn'
|
import { AppleControlBtn } from '@/components/AppleControlBtn'
|
||||||
import { useMessage, useDialog } from 'naive-ui'
|
import { useMessage, useDialog } from 'naive-ui'
|
||||||
@ -163,7 +163,7 @@ const deleteHanlde = () => {
|
|||||||
goDialog(dialog.warning, {
|
goDialog(dialog.warning, {
|
||||||
type: 'delete',
|
type: 'delete',
|
||||||
onPositiveCallback: () => {
|
onPositiveCallback: () => {
|
||||||
message.success('确定')
|
message.success('删除成功')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { renderIcon } from '@/utils/index'
|
import { renderIcon } from '@/utils'
|
||||||
import { icon } from '@/plugins'
|
import { icon } from '@/plugins'
|
||||||
import { AppleControlBtn } from '@/components/AppleControlBtn'
|
import { AppleControlBtn } from '@/components/AppleControlBtn'
|
||||||
const { HammerIcon } = icon.ionicons5
|
const { HammerIcon } = icon.ionicons5
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { openDoc, openGiteeSourceCode } from '@/utils/page'
|
import { openDoc, openGiteeSourceCode } from '@/utils'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
HelpCircleOutline as HelpOutlineIcon,
|
HelpCircleOutline as HelpOutlineIcon,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user