修改打包报错问题
@@ -48,10 +48,14 @@
|
|||||||
"vxe-table-plugin-export-xlsx": "^4.0.7",
|
"vxe-table-plugin-export-xlsx": "^4.0.7",
|
||||||
"grid-layout-plus": "^1.1.0",
|
"grid-layout-plus": "^1.1.0",
|
||||||
"vue-i18n": "9.10.2",
|
"vue-i18n": "9.10.2",
|
||||||
|
"qs": "^6.12.0",
|
||||||
|
"vue-types": "^5.1.1",
|
||||||
|
"web-storage-cache": "^1.1.1",
|
||||||
|
"jsencrypt": "^3.3.2",
|
||||||
"xe-utils": "^3.5.14"
|
"xe-utils": "^3.5.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@purge-icons/generated": "^0.9.0",
|
"@purge-icons/generated": "^0.9.0",
|
||||||
"@types/lodash-es": "^4.17.12",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@types/node": "^20.10.5",
|
"@types/node": "^20.10.5",
|
||||||
"@types/splitpanes": "2.2.6",
|
"@types/splitpanes": "2.2.6",
|
||||||
|
|||||||
6231
pnpm-lock.yaml
generated
@@ -69,3 +69,11 @@ export const queryById = (params: any) => {
|
|||||||
params
|
params
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// 更具id 查询驾驶舱页面
|
||||||
|
export const queryByPagePath = (params: any) => {
|
||||||
|
return createAxios({
|
||||||
|
url: '/system-boot/dashboard/queryByPagePath',
|
||||||
|
method: 'post',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
BIN
src/assets/imgs/1x1.png
Normal file
|
After Width: | Height: | Size: 118 B |
BIN
src/assets/imgs/2x2.png
Normal file
|
After Width: | Height: | Size: 137 B |
BIN
src/assets/imgs/2x3.png
Normal file
|
After Width: | Height: | Size: 160 B |
BIN
src/assets/imgs/3x3.png
Normal file
|
After Width: | Height: | Size: 179 B |
BIN
src/assets/imgs/amplify.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
src/assets/imgs/avatar.gif
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
BIN
src/assets/imgs/avatar.jpg
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
src/assets/imgs/bg02.png
Normal file
|
After Width: | Height: | Size: 697 B |
BIN
src/assets/imgs/bg1.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
src/assets/imgs/ditu.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
src/assets/imgs/ditu1.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
src/assets/imgs/diy/app-nav-bar-mp.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
src/assets/imgs/diy/statusBar.png
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
src/assets/imgs/logo.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/assets/imgs/profile.jpg
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
src/assets/imgs/reduce.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
src/assets/imgs/t_1.png
Normal file
|
After Width: | Height: | Size: 506 B |
BIN
src/assets/imgs/t_3.png
Normal file
|
After Width: | Height: | Size: 472 B |
BIN
src/assets/imgs/t_7.png
Normal file
|
After Width: | Height: | Size: 290 B |
BIN
src/assets/imgs/wechat.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
3
src/components/Backtop/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import Backtop from './src/Backtop.vue'
|
||||||
|
|
||||||
|
export { Backtop }
|
||||||
17
src/components/Backtop/src/Backtop.vue
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { ElBacktop } from 'element-plus'
|
||||||
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
|
|
||||||
|
defineOptions({ name: 'BackTop' })
|
||||||
|
|
||||||
|
const { getPrefixCls, variables } = useDesign()
|
||||||
|
|
||||||
|
const prefixCls = getPrefixCls('backtop')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ElBacktop
|
||||||
|
:class="`${prefixCls}-backtop`"
|
||||||
|
:target="`.${variables.namespace}-layout-content-scrollbar .${variables.elNamespace}-scrollbar__wrap`"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
111
src/components/RouterSearch/index.vue
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
<template>
|
||||||
|
<ElDialog v-if="isModal" v-model="showSearch" :show-close="false" title="菜单搜索">
|
||||||
|
<el-select
|
||||||
|
filterable
|
||||||
|
:reserve-keyword="false"
|
||||||
|
remote
|
||||||
|
placeholder="请输入菜单内容"
|
||||||
|
:remote-method="remoteMethod"
|
||||||
|
style="width: 100%"
|
||||||
|
@change="handleChange"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in options"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</ElDialog>
|
||||||
|
<div v-else class="custom-hover" @click.stop="showTopSearch = !showTopSearch">
|
||||||
|
<Icon icon="ep:search" />
|
||||||
|
<el-select
|
||||||
|
filterable
|
||||||
|
:reserve-keyword="false"
|
||||||
|
remote
|
||||||
|
placeholder="请输入菜单内容"
|
||||||
|
:remote-method="remoteMethod"
|
||||||
|
class="overflow-hidden transition-all-600"
|
||||||
|
:class="showTopSearch ? '!w-220px ml2' : '!w-0'"
|
||||||
|
@change="handleChange"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in options"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
defineProps({
|
||||||
|
isModal: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const router = useRouter() // 路由对象
|
||||||
|
const showSearch = ref(false) // 是否显示弹框
|
||||||
|
const showTopSearch = ref(false) // 是否显示顶部搜索框
|
||||||
|
const value: Ref = ref('') // 用户输入的值
|
||||||
|
|
||||||
|
const routers = router.getRoutes() // 路由对象
|
||||||
|
const options = computed(() => {
|
||||||
|
// 提示选项
|
||||||
|
if (!value.value) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
const list = routers.filter((item: any) => {
|
||||||
|
if (item.meta.title?.indexOf(value.value) > -1 || item.path.indexOf(value.value) > -1) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return list.map((item) => {
|
||||||
|
return {
|
||||||
|
label: `${item.meta.title}${item.path}`,
|
||||||
|
value: item.path
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function remoteMethod(data) {
|
||||||
|
// 这里可以执行相应的操作(例如打开搜索框等)
|
||||||
|
value.value = data
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleChange(path) {
|
||||||
|
router.push({ path })
|
||||||
|
hiddenTopSearch()
|
||||||
|
}
|
||||||
|
|
||||||
|
function hiddenTopSearch() {
|
||||||
|
showTopSearch.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
window.addEventListener('keydown', listenKey)
|
||||||
|
window.addEventListener('click', hiddenTopSearch)
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
window.removeEventListener('keydown', listenKey)
|
||||||
|
window.removeEventListener('click', hiddenTopSearch)
|
||||||
|
})
|
||||||
|
|
||||||
|
// 监听 ctrl + k
|
||||||
|
function listenKey(event) {
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
|
||||||
|
showSearch.value = !showSearch.value
|
||||||
|
// 这里可以执行相应的操作(例如打开搜索框等)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
openSearch: () => {
|
||||||
|
showSearch.value = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -1,282 +1,282 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="w100">
|
<div class="w100">
|
||||||
<!-- el-select 的远程下拉只在有搜索词时,才会加载数据(显示出 option 列表) -->
|
<!-- el-select 的远程下拉只在有搜索词时,才会加载数据(显示出 option 列表) -->
|
||||||
<!-- 使用 el-popover 在无数据/无搜索词时,显示一个无数据的提醒 -->
|
<!-- 使用 el-popover 在无数据/无搜索词时,显示一个无数据的提醒 -->
|
||||||
<el-popover width="100%" placement="bottom" popper-class="remote-select-popper"
|
<el-popover width="100%" placement="bottom" popper-class="remote-select-popper"
|
||||||
:visible="state.focusStatus && !state.loading && !state.keyword && !state.options.length"
|
:visible="state.focusStatus && !state.loading && !state.keyword && !state.options.length"
|
||||||
:teleported="false" :content="$t('utils.No data')">
|
:teleported="false" :content="$t('utils.No data')">
|
||||||
<template #reference>
|
<template #reference>
|
||||||
<el-select ref="selectRef" class="w100" @focus="onFocus" @blur="onBlur"
|
<el-select ref="selectRef" class="w100" @focus="onFocus" @blur="onBlur"
|
||||||
:loading="state.loading || state.accidentBlur" :filterable="true" :remote="true" clearable
|
:loading="state.loading || state.accidentBlur" :filterable="true" :remote="true" clearable
|
||||||
remote-show-suffix :remote-method="onLogKeyword" v-model.trim="state.value" @change="onChangeSelect"
|
remote-show-suffix :remote-method="onLogKeyword" v-model.trim="state.value" @change="onChangeSelect"
|
||||||
:multiple="multiple" :key="state.selectKey" @clear="onClear" @visible-change="onVisibleChange"
|
:multiple="multiple" :key="state.selectKey" @clear="onClear" @visible-change="onVisibleChange"
|
||||||
v-bind="$attrs">
|
v-bind="$attrs">
|
||||||
<el-option class="remote-select-option" v-for="item in state.options" :label="item[field]"
|
<el-option class="remote-select-option" v-for="item in state.options" :label="item[field]"
|
||||||
:value="item[state.primaryKey].toString()" :key="item[state.primaryKey]">
|
:value="item[state.primaryKey].toString()" :key="item[state.primaryKey]">
|
||||||
<el-tooltip placement="right" effect="light" v-if="!isEmpty(tooltipParams)">
|
<el-tooltip placement="right" effect="light" v-if="!isEmpty(tooltipParams)">
|
||||||
<template #content>
|
<template #content>
|
||||||
<p v-for="(tooltipParam, key) in tooltipParams" :key="key">{{ key }}: {{
|
<p v-for="(tooltipParam, key) in tooltipParams" :key="key">{{ key }}: {{
|
||||||
item[tooltipParam] }}</p>
|
item[tooltipParam] }}</p>
|
||||||
</template>
|
</template>
|
||||||
<div>{{ item[field] }}</div>
|
<div>{{ item[field] }}</div>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</el-option>
|
</el-option>
|
||||||
<el-pagination v-if="state.total" :currentPage="state.currentPage" :page-size="state.pageSize"
|
<el-pagination v-if="state.total" :currentPage="state.currentPage" :page-size="state.pageSize"
|
||||||
class="select-pagination" layout="->, prev, next" :total="state.total"
|
class="select-pagination" layout="->, prev, next" :total="state.total"
|
||||||
@current-change="onSelectCurrentPageChange" />
|
@current-change="onSelectCurrentPageChange" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</template>
|
</template>
|
||||||
</el-popover>
|
</el-popover>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, watch, onMounted, onUnmounted, ref, nextTick, getCurrentInstance, toRaw } from 'vue'
|
import { reactive, watch, onMounted, onUnmounted, ref, nextTick, getCurrentInstance, toRaw } from 'vue'
|
||||||
import { getSelectData } from '@/api/common'
|
// import { getSelectData } from '@/api/common'
|
||||||
import { uuid } from '@/utils/random'
|
import { uuid } from '@/utils/random'
|
||||||
import type { ElSelect } from 'element-plus'
|
import type { ElSelect } from 'element-plus'
|
||||||
import { isEmpty } from 'lodash-es'
|
import { isEmpty } from 'lodash-es'
|
||||||
import { getArrayKey } from '@/utils/common'
|
// import { getArrayKey } from '@/utils/common'
|
||||||
|
|
||||||
const selectRef = ref<InstanceType<typeof ElSelect> | undefined>()
|
const selectRef = ref<InstanceType<typeof ElSelect> | undefined>()
|
||||||
type ElSelectProps = Partial<InstanceType<typeof ElSelect>['$props']>
|
type ElSelectProps = Partial<InstanceType<typeof ElSelect>['$props']>
|
||||||
type valType = string | number | string[] | number[]
|
type valType = string | number | string[] | number[]
|
||||||
|
|
||||||
interface Props extends /* @vue-ignore */ ElSelectProps {
|
interface Props extends /* @vue-ignore */ ElSelectProps {
|
||||||
pk?: string
|
pk?: string
|
||||||
field?: string
|
field?: string
|
||||||
params?: anyObj
|
params?: anyObj
|
||||||
multiple?: boolean
|
multiple?: boolean
|
||||||
remoteUrl: string
|
remoteUrl: string
|
||||||
modelValue: valType
|
modelValue: valType
|
||||||
labelFormatter?: (optionData: anyObj, optionKey: string) => string
|
labelFormatter?: (optionData: anyObj, optionKey: string) => string
|
||||||
tooltipParams?: anyObj
|
tooltipParams?: anyObj
|
||||||
}
|
}
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
pk: 'id',
|
pk: 'id',
|
||||||
field: 'name',
|
field: 'name',
|
||||||
params: () => {
|
params: () => {
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
remoteUrl: '',
|
remoteUrl: '',
|
||||||
modelValue: '',
|
modelValue: '',
|
||||||
multiple: false,
|
multiple: false,
|
||||||
tooltipParams: () => {
|
tooltipParams: () => {
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const state: {
|
const state: {
|
||||||
// 主表字段名(不带表别名)
|
// 主表字段名(不带表别名)
|
||||||
primaryKey: string
|
primaryKey: string
|
||||||
options: anyObj[]
|
options: anyObj[]
|
||||||
loading: boolean
|
loading: boolean
|
||||||
total: number
|
total: number
|
||||||
currentPage: number
|
currentPage: number
|
||||||
pageSize: number
|
pageSize: number
|
||||||
params: anyObj
|
params: anyObj
|
||||||
keyword: string
|
keyword: string
|
||||||
value: valType
|
value: valType
|
||||||
selectKey: string
|
selectKey: string
|
||||||
initializeData: boolean
|
initializeData: boolean
|
||||||
accidentBlur: boolean
|
accidentBlur: boolean
|
||||||
focusStatus: boolean
|
focusStatus: boolean
|
||||||
} = reactive({
|
} = reactive({
|
||||||
primaryKey: props.pk,
|
primaryKey: props.pk,
|
||||||
options: [],
|
options: [],
|
||||||
loading: false,
|
loading: false,
|
||||||
total: 0,
|
total: 0,
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
params: props.params,
|
params: props.params,
|
||||||
keyword: '',
|
keyword: '',
|
||||||
value: props.modelValue ? props.modelValue : '',
|
value: props.modelValue ? props.modelValue : '',
|
||||||
selectKey: uuid(),
|
selectKey: uuid(),
|
||||||
initializeData: false,
|
initializeData: false,
|
||||||
accidentBlur: false,
|
accidentBlur: false,
|
||||||
focusStatus: false,
|
focusStatus: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
let io: null | IntersectionObserver = null
|
let io: null | IntersectionObserver = null
|
||||||
const instance = getCurrentInstance()
|
const instance = getCurrentInstance()
|
||||||
|
|
||||||
const emits = defineEmits<{
|
const emits = defineEmits<{
|
||||||
(e: 'update:modelValue', value: valType): void
|
(e: 'update:modelValue', value: valType): void
|
||||||
(e: 'row', value: any): void
|
(e: 'row', value: any): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const onChangeSelect = (val: valType) => {
|
const onChangeSelect = (val: valType) => {
|
||||||
emits('update:modelValue', val)
|
emits('update:modelValue', val)
|
||||||
if (typeof instance?.vnode.props?.onRow == 'function') {
|
if (typeof instance?.vnode.props?.onRow == 'function') {
|
||||||
let pkArr = props.pk.split('.')
|
let pkArr = props.pk.split('.')
|
||||||
let pk = pkArr[pkArr.length - 1]
|
let pk = pkArr[pkArr.length - 1]
|
||||||
if (typeof val == 'number' || typeof val == 'string') {
|
if (typeof val == 'number' || typeof val == 'string') {
|
||||||
const dataKey = getArrayKey(state.options, pk, val.toString())
|
// const dataKey = getArrayKey(state.options, pk, val.toString())
|
||||||
emits('row', dataKey ? toRaw(state.options[dataKey]) : {})
|
// emits('row', dataKey ? toRaw(state.options[dataKey]) : {})
|
||||||
} else {
|
} else {
|
||||||
const valueArr = []
|
// const valueArr = []
|
||||||
for (const key in val) {
|
// for (const key in val) {
|
||||||
let dataKey = getArrayKey(state.options, pk, val[key].toString())
|
// let dataKey = getArrayKey(state.options, pk, val[key].toString())
|
||||||
if (dataKey) valueArr.push(toRaw(state.options[dataKey]))
|
// if (dataKey) valueArr.push(toRaw(state.options[dataKey]))
|
||||||
}
|
// }
|
||||||
emits('row', valueArr)
|
// emits('row', valueArr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onVisibleChange = (val: boolean) => {
|
const onVisibleChange = (val: boolean) => {
|
||||||
// 保持面板状态和焦点状态一致
|
// 保持面板状态和焦点状态一致
|
||||||
if (!val) {
|
if (!val) {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
selectRef.value?.blur()
|
selectRef.value?.blur()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onFocus = () => {
|
const onFocus = () => {
|
||||||
state.focusStatus = true
|
state.focusStatus = true
|
||||||
if (selectRef.value?.query != state.keyword) {
|
if (selectRef.value?.query != state.keyword) {
|
||||||
state.keyword = ''
|
state.keyword = ''
|
||||||
state.initializeData = false
|
state.initializeData = false
|
||||||
// el-select 自动清理搜索词会产生意外的脱焦
|
// el-select 自动清理搜索词会产生意外的脱焦
|
||||||
state.accidentBlur = true
|
state.accidentBlur = true
|
||||||
}
|
}
|
||||||
if (!state.initializeData) {
|
if (!state.initializeData) {
|
||||||
getData()
|
getData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onBlur = () => {
|
const onBlur = () => {
|
||||||
state.focusStatus = false
|
state.focusStatus = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const onClear = () => {
|
const onClear = () => {
|
||||||
state.keyword = ''
|
state.keyword = ''
|
||||||
state.initializeData = false
|
state.initializeData = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const onLogKeyword = (q: string) => {
|
const onLogKeyword = (q: string) => {
|
||||||
if (state.keyword != q) {
|
if (state.keyword != q) {
|
||||||
state.keyword = q
|
state.keyword = q
|
||||||
getData()
|
getData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getData = (initValue: valType = '') => {
|
const getData = (initValue: valType = '') => {
|
||||||
state.loading = true
|
state.loading = true
|
||||||
state.params.page = state.currentPage
|
state.params.page = state.currentPage
|
||||||
state.params.initKey = props.pk
|
state.params.initKey = props.pk
|
||||||
state.params.initValue = initValue
|
state.params.initValue = initValue
|
||||||
getSelectData(props.remoteUrl, state.keyword, state.params)
|
getSelectData(props.remoteUrl, state.keyword, state.params)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
let initializeData = true
|
let initializeData = true
|
||||||
let opts = res.data.options ? res.data.options : res.data.list
|
let opts = res.data.options ? res.data.options : res.data.list
|
||||||
if (typeof props.labelFormatter == 'function') {
|
if (typeof props.labelFormatter == 'function') {
|
||||||
for (const key in opts) {
|
for (const key in opts) {
|
||||||
opts[key][props.field] = props.labelFormatter(opts[key], key)
|
opts[key][props.field] = props.labelFormatter(opts[key], key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.options = opts
|
state.options = opts
|
||||||
state.total = res.data.total ?? 0
|
state.total = res.data.total ?? 0
|
||||||
if (initValue) {
|
if (initValue) {
|
||||||
// 重新渲染组件,确保在赋值前,opts已加载到-兼容 modelValue 更新
|
// 重新渲染组件,确保在赋值前,opts已加载到-兼容 modelValue 更新
|
||||||
state.selectKey = uuid()
|
state.selectKey = uuid()
|
||||||
initializeData = false
|
initializeData = false
|
||||||
}
|
}
|
||||||
state.loading = false
|
state.loading = false
|
||||||
state.initializeData = initializeData
|
state.initializeData = initializeData
|
||||||
if (state.accidentBlur) {
|
if (state.accidentBlur) {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
const inputEl = selectRef.value?.$el.querySelector('.el-select__tags .el-select__input')
|
const inputEl = selectRef.value?.$el.querySelector('.el-select__tags .el-select__input')
|
||||||
inputEl && inputEl.focus()
|
inputEl && inputEl.focus()
|
||||||
state.accidentBlur = false
|
state.accidentBlur = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
state.loading = false
|
state.loading = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const onSelectCurrentPageChange = (val: number) => {
|
const onSelectCurrentPageChange = (val: number) => {
|
||||||
state.currentPage = val
|
state.currentPage = val
|
||||||
getData()
|
getData()
|
||||||
}
|
}
|
||||||
|
|
||||||
const initDefaultValue = () => {
|
const initDefaultValue = () => {
|
||||||
if (state.value) {
|
if (state.value) {
|
||||||
// number[]转string[]确保默认值能够选中
|
// number[]转string[]确保默认值能够选中
|
||||||
if (typeof state.value === 'object') {
|
if (typeof state.value === 'object') {
|
||||||
for (const key in state.value as string[]) {
|
for (const key in state.value as string[]) {
|
||||||
state.value[key] = state.value[key].toString()
|
state.value[key] = state.value[key].toString()
|
||||||
}
|
}
|
||||||
} else if (typeof state.value === 'number') {
|
} else if (typeof state.value === 'number') {
|
||||||
state.value = state.value.toString()
|
state.value = state.value.toString()
|
||||||
}
|
}
|
||||||
getData(state.value)
|
getData(state.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.pk.indexOf('.') > 0) {
|
if (props.pk.indexOf('.') > 0) {
|
||||||
let pk = props.pk.split('.')
|
let pk = props.pk.split('.')
|
||||||
state.primaryKey = pk[1] ? pk[1] : pk[0]
|
state.primaryKey = pk[1] ? pk[1] : pk[0]
|
||||||
}
|
}
|
||||||
initDefaultValue()
|
initDefaultValue()
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (window?.IntersectionObserver) {
|
if (window?.IntersectionObserver) {
|
||||||
io = new IntersectionObserver((entries) => {
|
io = new IntersectionObserver((entries) => {
|
||||||
for (const key in entries) {
|
for (const key in entries) {
|
||||||
if (!entries[key].isIntersecting) selectRef.value?.blur()
|
if (!entries[key].isIntersecting) selectRef.value?.blur()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (selectRef.value?.$el instanceof Element) {
|
if (selectRef.value?.$el instanceof Element) {
|
||||||
io.observe(selectRef.value.$el)
|
io.observe(selectRef.value.$el)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 500)
|
}, 500)
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
io?.disconnect()
|
io?.disconnect()
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.modelValue,
|
() => props.modelValue,
|
||||||
(newVal) => {
|
(newVal) => {
|
||||||
if (String(state.value) != String(newVal)) {
|
if (String(state.value) != String(newVal)) {
|
||||||
state.value = newVal ? newVal : ''
|
state.value = newVal ? newVal : ''
|
||||||
initDefaultValue()
|
initDefaultValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const getSelectRef = () => {
|
const getSelectRef = () => {
|
||||||
return selectRef.value
|
return selectRef.value
|
||||||
}
|
}
|
||||||
|
|
||||||
const focus = () => {
|
const focus = () => {
|
||||||
selectRef.value?.focus()
|
selectRef.value?.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
const blur = () => {
|
const blur = () => {
|
||||||
selectRef.value?.blur()
|
selectRef.value?.blur()
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
blur,
|
blur,
|
||||||
focus,
|
focus,
|
||||||
getSelectRef,
|
getSelectRef,
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
:deep(.remote-select-popper) {
|
:deep(.remote-select-popper) {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.remote-select-option {
|
.remote-select-option {
|
||||||
white-space: pre;
|
white-space: pre;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,414 +1,414 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PropType, VNode } from 'vue'
|
import type { PropType, VNode } from 'vue'
|
||||||
import type { modelValueTypes, InputAttr, InputData } from '@/components/baInput'
|
import type { modelValueTypes, InputAttr, InputData } from '@/components/baInput'
|
||||||
import { createVNode, resolveComponent, defineComponent, computed, reactive } from 'vue'
|
import { createVNode, resolveComponent, defineComponent, computed, reactive } from 'vue'
|
||||||
import { inputTypes } from '@/components/baInput'
|
import { inputTypes } from '@/components/baInput'
|
||||||
import Array from '@/components/baInput/components/array.vue'
|
import Array from '@/components/baInput/components/array.vue'
|
||||||
import RemoteSelect from '@/components/baInput/components/remoteSelect.vue'
|
import RemoteSelect from '@/components/baInput/components/remoteSelect.vue'
|
||||||
import IconSelector from '@/components/baInput/components/iconSelector.vue'
|
import IconSelector from '@/components/baInput/components/iconSelector.vue'
|
||||||
import Editor from '@/components/baInput/components/editor.vue'
|
import Editor from '@/components/baInput/components/editor.vue'
|
||||||
import { getArea } from '@/api/common'
|
// import { getArea } from '@/api/common'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'baInput',
|
name: 'baInput',
|
||||||
props: {
|
props: {
|
||||||
// 输入框类型,支持的输入框见 inputTypes
|
// 输入框类型,支持的输入框见 inputTypes
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
validator: (value: string) => {
|
validator: (value: string) => {
|
||||||
return inputTypes.includes(value)
|
return inputTypes.includes(value)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// 双向绑定值
|
// 双向绑定值
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: null,
|
type: null,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
// 输入框的附加属性
|
// 输入框的附加属性
|
||||||
attr: {
|
attr: {
|
||||||
type: Object as PropType<InputAttr>,
|
type: Object as PropType<InputAttr>,
|
||||||
default: () => {},
|
default: () => {},
|
||||||
},
|
},
|
||||||
// 额外数据,radio、checkbox的选项等数据
|
// 额外数据,radio、checkbox的选项等数据
|
||||||
data: {
|
data: {
|
||||||
type: Object as PropType<InputData>,
|
type: Object as PropType<InputData>,
|
||||||
default: () => {},
|
default: () => {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
emits: ['update:modelValue'],
|
emits: ['update:modelValue'],
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const onValueUpdate = (value: modelValueTypes) => {
|
const onValueUpdate = (value: modelValueTypes) => {
|
||||||
emit('update:modelValue', value)
|
emit('update:modelValue', value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 子级元素属性
|
// 子级元素属性
|
||||||
let childrenAttr = props.data && props.data.childrenAttr ? props.data.childrenAttr : {}
|
let childrenAttr = props.data && props.data.childrenAttr ? props.data.childrenAttr : {}
|
||||||
|
|
||||||
// string number textarea password
|
// string number textarea password
|
||||||
const sntp = () => {
|
const sntp = () => {
|
||||||
return () =>
|
return () =>
|
||||||
createVNode(resolveComponent('el-input'), {
|
createVNode(resolveComponent('el-input'), {
|
||||||
type: props.type == 'string' ? 'text' : props.type,
|
type: props.type == 'string' ? 'text' : props.type,
|
||||||
...props.attr,
|
...props.attr,
|
||||||
modelValue: props.modelValue,
|
modelValue: props.modelValue,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// radio checkbox
|
// radio checkbox
|
||||||
const rc = () => {
|
const rc = () => {
|
||||||
if (!props.data || !props.data.content) {
|
if (!props.data || !props.data.content) {
|
||||||
console.warn('请传递 ' + props.type + '的 content')
|
console.warn('请传递 ' + props.type + '的 content')
|
||||||
}
|
}
|
||||||
let vNode: VNode[] = []
|
let vNode: VNode[] = []
|
||||||
for (const key in props.data.content) {
|
for (const key in props.data.content) {
|
||||||
vNode.push(
|
vNode.push(
|
||||||
createVNode(
|
createVNode(
|
||||||
resolveComponent('el-' + props.type),
|
resolveComponent('el-' + props.type),
|
||||||
{
|
{
|
||||||
label: key,
|
label: key,
|
||||||
...childrenAttr,
|
...childrenAttr,
|
||||||
},
|
},
|
||||||
() => props.data.content[key]
|
() => props.data.content[key]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return () => {
|
return () => {
|
||||||
const valueComputed = computed(() => {
|
const valueComputed = computed(() => {
|
||||||
if (props.type == 'radio') {
|
if (props.type == 'radio') {
|
||||||
if (props.modelValue == undefined) return ''
|
if (props.modelValue == undefined) return ''
|
||||||
return '' + props.modelValue
|
return '' + props.modelValue
|
||||||
} else {
|
} else {
|
||||||
let modelValueArr: anyObj = []
|
let modelValueArr: anyObj = []
|
||||||
for (const key in props.modelValue) {
|
for (const key in props.modelValue) {
|
||||||
modelValueArr[key] = '' + props.modelValue[key]
|
modelValueArr[key] = '' + props.modelValue[key]
|
||||||
}
|
}
|
||||||
return modelValueArr
|
return modelValueArr
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return createVNode(
|
return createVNode(
|
||||||
resolveComponent('el-' + props.type + '-group'),
|
resolveComponent('el-' + props.type + '-group'),
|
||||||
{
|
{
|
||||||
...props.attr,
|
...props.attr,
|
||||||
modelValue: valueComputed.value,
|
modelValue: valueComputed.value,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
},
|
},
|
||||||
() => vNode
|
() => vNode
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// select selects
|
// select selects
|
||||||
const select = () => {
|
const select = () => {
|
||||||
let vNode: VNode[] = []
|
let vNode: VNode[] = []
|
||||||
if (!props.data || !props.data.content) {
|
if (!props.data || !props.data.content) {
|
||||||
console.warn('请传递 ' + props.type + '的 content')
|
console.warn('请传递 ' + props.type + '的 content')
|
||||||
}
|
}
|
||||||
for (const key in props.data.content) {
|
for (const key in props.data.content) {
|
||||||
vNode.push(
|
vNode.push(
|
||||||
createVNode(resolveComponent('el-option'), {
|
createVNode(resolveComponent('el-option'), {
|
||||||
key: key,
|
key: key,
|
||||||
label: props.data.content[key],
|
label: props.data.content[key],
|
||||||
value: key,
|
value: key,
|
||||||
...childrenAttr,
|
...childrenAttr,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return () => {
|
return () => {
|
||||||
const valueComputed = computed(() => {
|
const valueComputed = computed(() => {
|
||||||
if (props.type == 'select') {
|
if (props.type == 'select') {
|
||||||
if (props.modelValue == undefined) return ''
|
if (props.modelValue == undefined) return ''
|
||||||
return '' + props.modelValue
|
return '' + props.modelValue
|
||||||
} else {
|
} else {
|
||||||
let modelValueArr: anyObj = []
|
let modelValueArr: anyObj = []
|
||||||
for (const key in props.modelValue) {
|
for (const key in props.modelValue) {
|
||||||
modelValueArr[key] = '' + props.modelValue[key]
|
modelValueArr[key] = '' + props.modelValue[key]
|
||||||
}
|
}
|
||||||
return modelValueArr
|
return modelValueArr
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return createVNode(
|
return createVNode(
|
||||||
resolveComponent('el-select'),
|
resolveComponent('el-select'),
|
||||||
{
|
{
|
||||||
class: 'w100',
|
class: 'w100',
|
||||||
multiple: props.type == 'select' ? false : true,
|
multiple: props.type == 'select' ? false : true,
|
||||||
clearable: true,
|
clearable: true,
|
||||||
...props.attr,
|
...props.attr,
|
||||||
modelValue: valueComputed.value,
|
modelValue: valueComputed.value,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
},
|
},
|
||||||
() => vNode
|
() => vNode
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// datetime
|
// datetime
|
||||||
const datetime = () => {
|
const datetime = () => {
|
||||||
let valueFormat = 'YYYY-MM-DD HH:mm:ss'
|
let valueFormat = 'YYYY-MM-DD HH:mm:ss'
|
||||||
switch (props.type) {
|
switch (props.type) {
|
||||||
case 'date':
|
case 'date':
|
||||||
valueFormat = 'YYYY-MM-DD'
|
valueFormat = 'YYYY-MM-DD'
|
||||||
break
|
break
|
||||||
case 'year':
|
case 'year':
|
||||||
valueFormat = 'YYYY'
|
valueFormat = 'YYYY'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return () =>
|
return () =>
|
||||||
createVNode(resolveComponent('el-date-picker'), {
|
createVNode(resolveComponent('el-date-picker'), {
|
||||||
class: 'w100',
|
class: 'w100',
|
||||||
type: props.type,
|
type: props.type,
|
||||||
'value-format': valueFormat,
|
'value-format': valueFormat,
|
||||||
...props.attr,
|
...props.attr,
|
||||||
modelValue: props.modelValue,
|
modelValue: props.modelValue,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// remoteSelect remoteSelects
|
// remoteSelect remoteSelects
|
||||||
const remoteSelect = () => {
|
const remoteSelect = () => {
|
||||||
return () =>
|
return () =>
|
||||||
createVNode(RemoteSelect, {
|
createVNode(RemoteSelect, {
|
||||||
modelValue: props.modelValue,
|
modelValue: props.modelValue,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
multiple: props.type == 'remoteSelect' ? false : true,
|
multiple: props.type == 'remoteSelect' ? false : true,
|
||||||
...props.attr,
|
...props.attr,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildFun = new Map([
|
const buildFun = new Map([
|
||||||
['string', sntp],
|
['string', sntp],
|
||||||
['number', sntp],
|
['number', sntp],
|
||||||
['textarea', sntp],
|
['textarea', sntp],
|
||||||
['password', sntp],
|
['password', sntp],
|
||||||
['radio', rc],
|
['radio', rc],
|
||||||
['checkbox', rc],
|
['checkbox', rc],
|
||||||
[
|
[
|
||||||
'switch',
|
'switch',
|
||||||
() => {
|
() => {
|
||||||
const valueType = computed(() => typeof props.modelValue)
|
const valueType = computed(() => typeof props.modelValue)
|
||||||
const valueComputed = computed(() => {
|
const valueComputed = computed(() => {
|
||||||
if (valueType.value === 'boolean') {
|
if (valueType.value === 'boolean') {
|
||||||
return props.modelValue
|
return props.modelValue
|
||||||
} else {
|
} else {
|
||||||
let valueTmp = parseInt(props.modelValue as string)
|
let valueTmp = parseInt(props.modelValue as string)
|
||||||
return isNaN(valueTmp) || valueTmp <= 0 ? false : true
|
return isNaN(valueTmp) || valueTmp <= 0 ? false : true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return () =>
|
return () =>
|
||||||
createVNode(resolveComponent('el-switch'), {
|
createVNode(resolveComponent('el-switch'), {
|
||||||
...props.attr,
|
...props.attr,
|
||||||
modelValue: valueComputed.value,
|
modelValue: valueComputed.value,
|
||||||
'onUpdate:modelValue': (value: boolean) => {
|
'onUpdate:modelValue': (value: boolean) => {
|
||||||
let newValue: boolean | string | number = value
|
let newValue: boolean | string | number = value
|
||||||
switch (valueType.value) {
|
switch (valueType.value) {
|
||||||
case 'string':
|
case 'string':
|
||||||
newValue = value ? '1' : '0'
|
newValue = value ? '1' : '0'
|
||||||
break
|
break
|
||||||
case 'number':
|
case 'number':
|
||||||
newValue = value ? 1 : 0
|
newValue = value ? 1 : 0
|
||||||
}
|
}
|
||||||
emit('update:modelValue', newValue)
|
emit('update:modelValue', newValue)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
['datetime', datetime],
|
['datetime', datetime],
|
||||||
[
|
[
|
||||||
'year',
|
'year',
|
||||||
() => {
|
() => {
|
||||||
return () => {
|
return () => {
|
||||||
const valueComputed = computed(() => (!props.modelValue ? null : '' + props.modelValue))
|
const valueComputed = computed(() => (!props.modelValue ? null : '' + props.modelValue))
|
||||||
return createVNode(resolveComponent('el-date-picker'), {
|
return createVNode(resolveComponent('el-date-picker'), {
|
||||||
class: 'w100',
|
class: 'w100',
|
||||||
type: props.type,
|
type: props.type,
|
||||||
'value-format': 'YYYY',
|
'value-format': 'YYYY',
|
||||||
...props.attr,
|
...props.attr,
|
||||||
modelValue: valueComputed.value,
|
modelValue: valueComputed.value,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
['date', datetime],
|
['date', datetime],
|
||||||
[
|
[
|
||||||
'time',
|
'time',
|
||||||
() => {
|
() => {
|
||||||
const valueComputed = computed(() => {
|
const valueComputed = computed(() => {
|
||||||
if (props.modelValue instanceof Date) {
|
if (props.modelValue instanceof Date) {
|
||||||
return props.modelValue
|
return props.modelValue
|
||||||
} else if (!props.modelValue) {
|
} else if (!props.modelValue) {
|
||||||
return ''
|
return ''
|
||||||
} else {
|
} else {
|
||||||
let date = new Date()
|
let date = new Date()
|
||||||
return new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + props.modelValue)
|
return new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + props.modelValue)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return () =>
|
return () =>
|
||||||
createVNode(resolveComponent('el-time-picker'), {
|
createVNode(resolveComponent('el-time-picker'), {
|
||||||
class: 'w100',
|
class: 'w100',
|
||||||
clearable: true,
|
clearable: true,
|
||||||
format: 'HH:mm:ss',
|
format: 'HH:mm:ss',
|
||||||
...props.attr,
|
...props.attr,
|
||||||
modelValue: valueComputed.value,
|
modelValue: valueComputed.value,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
['select', select],
|
['select', select],
|
||||||
['selects', select],
|
['selects', select],
|
||||||
[
|
[
|
||||||
'array',
|
'array',
|
||||||
() => {
|
() => {
|
||||||
return () =>
|
return () =>
|
||||||
createVNode(Array, {
|
createVNode(Array, {
|
||||||
modelValue: props.modelValue,
|
modelValue: props.modelValue,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
...props.attr,
|
...props.attr,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
['remoteSelect', remoteSelect],
|
['remoteSelect', remoteSelect],
|
||||||
['remoteSelects', remoteSelect],
|
['remoteSelects', remoteSelect],
|
||||||
[
|
[
|
||||||
'city',
|
'city',
|
||||||
() => {
|
() => {
|
||||||
type Node = { value?: number; label?: string; leaf?: boolean }
|
type Node = { value?: number; label?: string; leaf?: boolean }
|
||||||
let maxLevel = props.data && props.data.level ? props.data.level - 1 : 2
|
let maxLevel = props.data && props.data.level ? props.data.level - 1 : 2
|
||||||
const lastLazyValue: {
|
const lastLazyValue: {
|
||||||
value: string | number[] | unknown
|
value: string | number[] | unknown
|
||||||
nodes: Node[]
|
nodes: Node[]
|
||||||
key: string
|
key: string
|
||||||
currentRequest: any
|
currentRequest: any
|
||||||
} = reactive({
|
} = reactive({
|
||||||
value: 'ready',
|
value: 'ready',
|
||||||
nodes: [],
|
nodes: [],
|
||||||
key: '',
|
key: '',
|
||||||
currentRequest: null,
|
currentRequest: null,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 请求到的node备份-s
|
// 请求到的node备份-s
|
||||||
let nodeEbak: anyObj = {}
|
let nodeEbak: anyObj = {}
|
||||||
const getNodes = (level: number, key: string) => {
|
const getNodes = (level: number, key: string) => {
|
||||||
if (nodeEbak[level] && nodeEbak[level][key]) {
|
if (nodeEbak[level] && nodeEbak[level][key]) {
|
||||||
return nodeEbak[level][key]
|
return nodeEbak[level][key]
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
const setNodes = (level: number, key: string, nodes: Node[] = []) => {
|
const setNodes = (level: number, key: string, nodes: Node[] = []) => {
|
||||||
if (!nodeEbak[level]) {
|
if (!nodeEbak[level]) {
|
||||||
nodeEbak[level] = {}
|
nodeEbak[level] = {}
|
||||||
}
|
}
|
||||||
nodeEbak[level][key] = nodes
|
nodeEbak[level][key] = nodes
|
||||||
}
|
}
|
||||||
// 请求到的node备份-e
|
// 请求到的node备份-e
|
||||||
|
|
||||||
return () =>
|
return () =>
|
||||||
createVNode(resolveComponent('el-cascader'), {
|
createVNode(resolveComponent('el-cascader'), {
|
||||||
modelValue: props.modelValue,
|
modelValue: props.modelValue,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
class: 'w100',
|
class: 'w100',
|
||||||
clearable: true,
|
clearable: true,
|
||||||
props: {
|
props: {
|
||||||
lazy: true,
|
lazy: true,
|
||||||
lazyLoad(node: any, resolve: any) {
|
lazyLoad(node: any, resolve: any) {
|
||||||
// lazyLoad会频繁触发,在本地存储请求结果,供重复触发时直接读取
|
// lazyLoad会频繁触发,在本地存储请求结果,供重复触发时直接读取
|
||||||
const { level, pathValues } = node
|
const { level, pathValues } = node
|
||||||
let key = pathValues.join(',')
|
let key = pathValues.join(',')
|
||||||
key = key ? key : 'init'
|
key = key ? key : 'init'
|
||||||
|
|
||||||
let locaNode = getNodes(level, key)
|
let locaNode = getNodes(level, key)
|
||||||
if (locaNode) {
|
if (locaNode) {
|
||||||
return resolve(locaNode)
|
return resolve(locaNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastLazyValue.key == key && lastLazyValue.value == props.modelValue) {
|
if (lastLazyValue.key == key && lastLazyValue.value == props.modelValue) {
|
||||||
if (lastLazyValue.currentRequest) {
|
if (lastLazyValue.currentRequest) {
|
||||||
return lastLazyValue.currentRequest
|
return lastLazyValue.currentRequest
|
||||||
}
|
}
|
||||||
return resolve(lastLazyValue.nodes)
|
return resolve(lastLazyValue.nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
let nodes: Node[] = []
|
let nodes: Node[] = []
|
||||||
lastLazyValue.key = key
|
lastLazyValue.key = key
|
||||||
lastLazyValue.value = props.modelValue
|
lastLazyValue.value = props.modelValue
|
||||||
lastLazyValue.currentRequest = getArea(pathValues).then((res) => {
|
// lastLazyValue.currentRequest = getArea(pathValues).then((res) => {
|
||||||
let toStr = false
|
// let toStr = false
|
||||||
if (props.modelValue && typeof (props.modelValue as anyObj)[0] === 'string') {
|
// if (props.modelValue && typeof (props.modelValue as anyObj)[0] === 'string') {
|
||||||
toStr = true
|
// toStr = true
|
||||||
}
|
// }
|
||||||
for (const key in res.data) {
|
// for (const key in res.data) {
|
||||||
if (toStr) {
|
// if (toStr) {
|
||||||
res.data[key].value = res.data[key].value.toString()
|
// res.data[key].value = res.data[key].value.toString()
|
||||||
}
|
// }
|
||||||
res.data[key].leaf = level >= maxLevel
|
// res.data[key].leaf = level >= maxLevel
|
||||||
nodes.push(res.data[key])
|
// nodes.push(res.data[key])
|
||||||
}
|
// }
|
||||||
lastLazyValue.nodes = nodes
|
// lastLazyValue.nodes = nodes
|
||||||
lastLazyValue.currentRequest = null
|
// lastLazyValue.currentRequest = null
|
||||||
setNodes(level, key, nodes)
|
// setNodes(level, key, nodes)
|
||||||
resolve(nodes)
|
// resolve(nodes)
|
||||||
})
|
// })
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
...props.attr,
|
...props.attr,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
['image', upload],
|
['image', upload],
|
||||||
['images', upload],
|
['images', upload],
|
||||||
['file', upload],
|
['file', upload],
|
||||||
['files', upload],
|
['files', upload],
|
||||||
[
|
[
|
||||||
'icon',
|
'icon',
|
||||||
() => {
|
() => {
|
||||||
return () =>
|
return () =>
|
||||||
createVNode(IconSelector, {
|
createVNode(IconSelector, {
|
||||||
modelValue: props.modelValue,
|
modelValue: props.modelValue,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
...props.attr,
|
...props.attr,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'color',
|
'color',
|
||||||
() => {
|
() => {
|
||||||
return () =>
|
return () =>
|
||||||
createVNode(resolveComponent('el-color-picker'), {
|
createVNode(resolveComponent('el-color-picker'), {
|
||||||
modelValue: props.modelValue,
|
modelValue: props.modelValue,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
...props.attr,
|
...props.attr,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'editor',
|
'editor',
|
||||||
() => {
|
() => {
|
||||||
return () =>
|
return () =>
|
||||||
createVNode(Editor, {
|
createVNode(Editor, {
|
||||||
modelValue: props.modelValue,
|
modelValue: props.modelValue,
|
||||||
'onUpdate:modelValue': onValueUpdate,
|
'onUpdate:modelValue': onValueUpdate,
|
||||||
...props.attr,
|
...props.attr,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'default',
|
'default',
|
||||||
() => {
|
() => {
|
||||||
console.warn('暂不支持' + props.type + '的输入框类型,你可以自行在 BaInput 组件内添加逻辑')
|
console.warn('暂不支持' + props.type + '的输入框类型,你可以自行在 BaInput 组件内添加逻辑')
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
|
|
||||||
let action = buildFun.get(props.type) || buildFun.get('default')
|
let action = buildFun.get(props.type) || buildFun.get('default')
|
||||||
return action!.call(this)
|
return action!.call(this)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.ba-upload-image :deep(.el-upload--picture-card) {
|
.ba-upload-image :deep(.el-upload--picture-card) {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
.ba-upload-file :deep(.el-upload-list) {
|
.ba-upload-file :deep(.el-upload-list) {
|
||||||
margin-left: -10px;
|
margin-left: -10px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
55
src/plugins/formCreate/index.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import type { App } from 'vue'
|
||||||
|
// 👇使用 form-create 需额外全局引入 element plus 组件
|
||||||
|
import {
|
||||||
|
ElAlert,
|
||||||
|
ElAside,
|
||||||
|
ElContainer,
|
||||||
|
ElDivider,
|
||||||
|
ElHeader,
|
||||||
|
ElMain,
|
||||||
|
ElPopconfirm,
|
||||||
|
ElTable,
|
||||||
|
ElTableColumn,
|
||||||
|
ElTabPane,
|
||||||
|
ElTabs,
|
||||||
|
ElTransfer
|
||||||
|
} from 'element-plus'
|
||||||
|
import FcDesigner from '@form-create/designer'
|
||||||
|
import formCreate from '@form-create/element-ui'
|
||||||
|
import install from '@form-create/element-ui/auto-import'
|
||||||
|
//======================= 自定义组件 =======================
|
||||||
|
import { UploadFile, UploadImg, UploadImgs } from '@/components/UploadFile'
|
||||||
|
import { DictSelect } from '@/components/DictSelect'
|
||||||
|
import UserSelect from '@/views/system/auth/userList/UserSelect.vue'
|
||||||
|
import { Editor } from '@/components/Editor'
|
||||||
|
|
||||||
|
const components = [
|
||||||
|
ElAside,
|
||||||
|
ElPopconfirm,
|
||||||
|
ElHeader,
|
||||||
|
ElMain,
|
||||||
|
ElContainer,
|
||||||
|
ElDivider,
|
||||||
|
ElTransfer,
|
||||||
|
ElAlert,
|
||||||
|
ElTabs,
|
||||||
|
ElTable,
|
||||||
|
ElTableColumn,
|
||||||
|
ElTabPane,
|
||||||
|
UploadImg,
|
||||||
|
UploadImgs,
|
||||||
|
UploadFile,
|
||||||
|
DictSelect,
|
||||||
|
UserSelect,
|
||||||
|
Editor
|
||||||
|
]
|
||||||
|
|
||||||
|
// 参考 http://www.form-create.com/v3/element-ui/auto-import.html 文档
|
||||||
|
export const setupFormCreate = (app: App<Element>) => {
|
||||||
|
components.forEach((component) => {
|
||||||
|
app.component(component.name, component)
|
||||||
|
})
|
||||||
|
formCreate.use(install)
|
||||||
|
app.use(formCreate)
|
||||||
|
app.use(FcDesigner)
|
||||||
|
}
|
||||||
3
src/plugins/vueI18n/helper.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const setHtmlPageLang = (locale: LocaleType) => {
|
||||||
|
document.querySelector('html')?.setAttribute('lang', locale)
|
||||||
|
}
|
||||||
42
src/plugins/vueI18n/index.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import type { App } from 'vue'
|
||||||
|
import { createI18n } from 'vue-i18n'
|
||||||
|
import { useLocaleStoreWithOut } from '@/stores/modules/locale'
|
||||||
|
import type { I18n, I18nOptions } from 'vue-i18n'
|
||||||
|
import { setHtmlPageLang } from './helper'
|
||||||
|
|
||||||
|
export let i18n: ReturnType<typeof createI18n>
|
||||||
|
|
||||||
|
const createI18nOptions = async (): Promise<I18nOptions> => {
|
||||||
|
const localeStore = useLocaleStoreWithOut()
|
||||||
|
const locale = localeStore.getCurrentLocale
|
||||||
|
const localeMap = localeStore.getLocaleMap
|
||||||
|
const defaultLocal = await import(`../../locales/${locale.lang}.ts`)
|
||||||
|
const message = defaultLocal.default ?? {}
|
||||||
|
|
||||||
|
setHtmlPageLang(locale.lang)
|
||||||
|
|
||||||
|
localeStore.setCurrentLocale({
|
||||||
|
lang: locale.lang
|
||||||
|
// elLocale: elLocal
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
legacy: false,
|
||||||
|
locale: locale.lang,
|
||||||
|
fallbackLocale: locale.lang,
|
||||||
|
messages: {
|
||||||
|
[locale.lang]: message
|
||||||
|
},
|
||||||
|
availableLocales: localeMap.map((v) => v.lang),
|
||||||
|
sync: true,
|
||||||
|
silentTranslationWarn: true,
|
||||||
|
missingWarn: false,
|
||||||
|
silentFallbackWarn: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const setupI18n = async (app: App<Element>) => {
|
||||||
|
const options = await createI18nOptions()
|
||||||
|
i18n = createI18n(options) as I18n
|
||||||
|
app.use(i18n)
|
||||||
|
}
|
||||||
12
src/stores/indexs.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import type { App } from 'vue'
|
||||||
|
import { createPinia } from 'pinia'
|
||||||
|
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||||||
|
|
||||||
|
const store = createPinia()
|
||||||
|
store.use(piniaPluginPersistedstate)
|
||||||
|
|
||||||
|
export const setupStore = (app: App<Element>) => {
|
||||||
|
app.use(store)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { store }
|
||||||
277
src/stores/modules/app.ts
Normal file
@@ -0,0 +1,277 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { store } from '../indexs'
|
||||||
|
import { setCssVar, humpToUnderline } from '@/utils'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
||||||
|
import { ElementPlusSize } from '@/types/elementPlus'
|
||||||
|
import { LayoutType } from '@/types/layout'
|
||||||
|
import { ThemeTypes } from '@/types/theme'
|
||||||
|
|
||||||
|
const { wsCache } = useCache()
|
||||||
|
|
||||||
|
interface AppState {
|
||||||
|
breadcrumb: boolean
|
||||||
|
breadcrumbIcon: boolean
|
||||||
|
collapse: boolean
|
||||||
|
uniqueOpened: boolean
|
||||||
|
hamburger: boolean
|
||||||
|
screenfull: boolean
|
||||||
|
search: boolean
|
||||||
|
size: boolean
|
||||||
|
locale: boolean
|
||||||
|
message: boolean
|
||||||
|
tagsView: boolean
|
||||||
|
tagsViewIcon: boolean
|
||||||
|
logo: boolean
|
||||||
|
fixedHeader: boolean
|
||||||
|
greyMode: boolean
|
||||||
|
pageLoading: boolean
|
||||||
|
layout: LayoutType
|
||||||
|
title: string
|
||||||
|
userInfo: string
|
||||||
|
isDark: boolean
|
||||||
|
currentSize: ElementPlusSize
|
||||||
|
sizeMap: ElementPlusSize[]
|
||||||
|
mobile: boolean
|
||||||
|
footer: boolean
|
||||||
|
theme: ThemeTypes
|
||||||
|
fixedMenu: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useAppStore = defineStore('app', {
|
||||||
|
state: (): AppState => {
|
||||||
|
return {
|
||||||
|
userInfo: 'userInfo', // 登录信息存储字段-建议每个项目换一个字段,避免与其他项目冲突
|
||||||
|
sizeMap: ['default', 'large', 'small'],
|
||||||
|
mobile: false, // 是否是移动端
|
||||||
|
title: import.meta.env.VITE_APP_TITLE, // 标题
|
||||||
|
pageLoading: false, // 路由跳转loading
|
||||||
|
|
||||||
|
breadcrumb: true, // 面包屑
|
||||||
|
breadcrumbIcon: true, // 面包屑图标
|
||||||
|
collapse: false, // 折叠菜单
|
||||||
|
uniqueOpened: true, // 是否只保持一个子菜单的展开
|
||||||
|
hamburger: true, // 折叠图标
|
||||||
|
screenfull: true, // 全屏图标
|
||||||
|
search: true, // 搜索图标
|
||||||
|
size: true, // 尺寸图标
|
||||||
|
locale: true, // 多语言图标
|
||||||
|
message: true, // 消息图标
|
||||||
|
tagsView: true, // 标签页
|
||||||
|
tagsViewIcon: true, // 是否显示标签图标
|
||||||
|
logo: true, // logo
|
||||||
|
fixedHeader: true, // 固定toolheader
|
||||||
|
footer: true, // 显示页脚
|
||||||
|
greyMode: false, // 是否开始灰色模式,用于特殊悼念日
|
||||||
|
fixedMenu: wsCache.get('fixedMenu') || false, // 是否固定菜单
|
||||||
|
|
||||||
|
layout: wsCache.get(CACHE_KEY.LAYOUT) || 'classic', // layout布局
|
||||||
|
isDark: wsCache.get(CACHE_KEY.IS_DARK) || false, // 是否是暗黑模式
|
||||||
|
currentSize: wsCache.get('default') || 'default', // 组件尺寸
|
||||||
|
theme: wsCache.get(CACHE_KEY.THEME) || {
|
||||||
|
// 主题色
|
||||||
|
elColorPrimary: '#409eff',
|
||||||
|
// 左侧菜单边框颜色
|
||||||
|
leftMenuBorderColor: 'inherit',
|
||||||
|
// 左侧菜单背景颜色
|
||||||
|
leftMenuBgColor: '#001529',
|
||||||
|
// 左侧菜单浅色背景颜色
|
||||||
|
leftMenuBgLightColor: '#0f2438',
|
||||||
|
// 左侧菜单选中背景颜色
|
||||||
|
leftMenuBgActiveColor: 'var(--el-color-primary)',
|
||||||
|
// 左侧菜单收起选中背景颜色
|
||||||
|
leftMenuCollapseBgActiveColor: 'var(--el-color-primary)',
|
||||||
|
// 左侧菜单字体颜色
|
||||||
|
leftMenuTextColor: '#bfcbd9',
|
||||||
|
// 左侧菜单选中字体颜色
|
||||||
|
leftMenuTextActiveColor: '#fff',
|
||||||
|
// logo字体颜色
|
||||||
|
logoTitleTextColor: '#fff',
|
||||||
|
// logo边框颜色
|
||||||
|
logoBorderColor: 'inherit',
|
||||||
|
// 头部背景颜色
|
||||||
|
topHeaderBgColor: '#fff',
|
||||||
|
// 头部字体颜色
|
||||||
|
topHeaderTextColor: 'inherit',
|
||||||
|
// 头部悬停颜色
|
||||||
|
topHeaderHoverColor: '#f6f6f6',
|
||||||
|
// 头部边框颜色
|
||||||
|
topToolBorderColor: '#eee'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getters: {
|
||||||
|
getBreadcrumb(): boolean {
|
||||||
|
return this.breadcrumb
|
||||||
|
},
|
||||||
|
getBreadcrumbIcon(): boolean {
|
||||||
|
return this.breadcrumbIcon
|
||||||
|
},
|
||||||
|
getCollapse(): boolean {
|
||||||
|
return this.collapse
|
||||||
|
},
|
||||||
|
getUniqueOpened(): boolean {
|
||||||
|
return this.uniqueOpened
|
||||||
|
},
|
||||||
|
getHamburger(): boolean {
|
||||||
|
return this.hamburger
|
||||||
|
},
|
||||||
|
getScreenfull(): boolean {
|
||||||
|
return this.screenfull
|
||||||
|
},
|
||||||
|
getSize(): boolean {
|
||||||
|
return this.size
|
||||||
|
},
|
||||||
|
getLocale(): boolean {
|
||||||
|
return this.locale
|
||||||
|
},
|
||||||
|
getMessage(): boolean {
|
||||||
|
return this.message
|
||||||
|
},
|
||||||
|
getTagsView(): boolean {
|
||||||
|
return this.tagsView
|
||||||
|
},
|
||||||
|
getTagsViewIcon(): boolean {
|
||||||
|
return this.tagsViewIcon
|
||||||
|
},
|
||||||
|
getLogo(): boolean {
|
||||||
|
return this.logo
|
||||||
|
},
|
||||||
|
getFixedHeader(): boolean {
|
||||||
|
return this.fixedHeader
|
||||||
|
},
|
||||||
|
getGreyMode(): boolean {
|
||||||
|
return this.greyMode
|
||||||
|
},
|
||||||
|
getFixedMenu(): boolean {
|
||||||
|
return this.fixedMenu
|
||||||
|
},
|
||||||
|
getPageLoading(): boolean {
|
||||||
|
return this.pageLoading
|
||||||
|
},
|
||||||
|
getLayout(): LayoutType {
|
||||||
|
return this.layout
|
||||||
|
},
|
||||||
|
getTitle(): string {
|
||||||
|
return this.title
|
||||||
|
},
|
||||||
|
getUserInfo(): string {
|
||||||
|
return this.userInfo
|
||||||
|
},
|
||||||
|
getIsDark(): boolean {
|
||||||
|
return this.isDark
|
||||||
|
},
|
||||||
|
getCurrentSize(): ElementPlusSize {
|
||||||
|
return this.currentSize
|
||||||
|
},
|
||||||
|
getSizeMap(): ElementPlusSize[] {
|
||||||
|
return this.sizeMap
|
||||||
|
},
|
||||||
|
getMobile(): boolean {
|
||||||
|
return this.mobile
|
||||||
|
},
|
||||||
|
getTheme(): ThemeTypes {
|
||||||
|
return this.theme
|
||||||
|
},
|
||||||
|
getFooter(): boolean {
|
||||||
|
return this.footer
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
setBreadcrumb(breadcrumb: boolean) {
|
||||||
|
this.breadcrumb = breadcrumb
|
||||||
|
},
|
||||||
|
setBreadcrumbIcon(breadcrumbIcon: boolean) {
|
||||||
|
this.breadcrumbIcon = breadcrumbIcon
|
||||||
|
},
|
||||||
|
setCollapse(collapse: boolean) {
|
||||||
|
this.collapse = collapse
|
||||||
|
},
|
||||||
|
setUniqueOpened(uniqueOpened: boolean) {
|
||||||
|
this.uniqueOpened = uniqueOpened
|
||||||
|
},
|
||||||
|
setHamburger(hamburger: boolean) {
|
||||||
|
this.hamburger = hamburger
|
||||||
|
},
|
||||||
|
setScreenfull(screenfull: boolean) {
|
||||||
|
this.screenfull = screenfull
|
||||||
|
},
|
||||||
|
setSize(size: boolean) {
|
||||||
|
this.size = size
|
||||||
|
},
|
||||||
|
setLocale(locale: boolean) {
|
||||||
|
this.locale = locale
|
||||||
|
},
|
||||||
|
setMessage(message: boolean) {
|
||||||
|
this.message = message
|
||||||
|
},
|
||||||
|
setTagsView(tagsView: boolean) {
|
||||||
|
this.tagsView = tagsView
|
||||||
|
},
|
||||||
|
setTagsViewIcon(tagsViewIcon: boolean) {
|
||||||
|
this.tagsViewIcon = tagsViewIcon
|
||||||
|
},
|
||||||
|
setLogo(logo: boolean) {
|
||||||
|
this.logo = logo
|
||||||
|
},
|
||||||
|
setFixedHeader(fixedHeader: boolean) {
|
||||||
|
this.fixedHeader = fixedHeader
|
||||||
|
},
|
||||||
|
setGreyMode(greyMode: boolean) {
|
||||||
|
this.greyMode = greyMode
|
||||||
|
},
|
||||||
|
setFixedMenu(fixedMenu: boolean) {
|
||||||
|
wsCache.set('fixedMenu', fixedMenu)
|
||||||
|
this.fixedMenu = fixedMenu
|
||||||
|
},
|
||||||
|
setPageLoading(pageLoading: boolean) {
|
||||||
|
this.pageLoading = pageLoading
|
||||||
|
},
|
||||||
|
setLayout(layout: LayoutType) {
|
||||||
|
if (this.mobile && layout !== 'classic') {
|
||||||
|
ElMessage.warning('移动端模式下不支持切换其他布局')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.layout = layout
|
||||||
|
wsCache.set(CACHE_KEY.LAYOUT, this.layout)
|
||||||
|
},
|
||||||
|
setTitle(title: string) {
|
||||||
|
this.title = title
|
||||||
|
},
|
||||||
|
setIsDark(isDark: boolean) {
|
||||||
|
this.isDark = isDark
|
||||||
|
if (this.isDark) {
|
||||||
|
document.documentElement.classList.add('dark')
|
||||||
|
document.documentElement.classList.remove('light')
|
||||||
|
} else {
|
||||||
|
document.documentElement.classList.add('light')
|
||||||
|
document.documentElement.classList.remove('dark')
|
||||||
|
}
|
||||||
|
wsCache.set(CACHE_KEY.IS_DARK, this.isDark)
|
||||||
|
},
|
||||||
|
setCurrentSize(currentSize: ElementPlusSize) {
|
||||||
|
this.currentSize = currentSize
|
||||||
|
wsCache.set('currentSize', this.currentSize)
|
||||||
|
},
|
||||||
|
setMobile(mobile: boolean) {
|
||||||
|
this.mobile = mobile
|
||||||
|
},
|
||||||
|
setTheme(theme: ThemeTypes) {
|
||||||
|
this.theme = Object.assign(this.theme, theme)
|
||||||
|
wsCache.set(CACHE_KEY.THEME, this.theme)
|
||||||
|
},
|
||||||
|
setCssVarTheme() {
|
||||||
|
for (const key in this.theme) {
|
||||||
|
setCssVar(`--${humpToUnderline(key)}`, this.theme[key])
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setFooter(footer: boolean) {
|
||||||
|
this.footer = footer
|
||||||
|
}
|
||||||
|
},
|
||||||
|
persist: false
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useAppStoreWithOut = () => {
|
||||||
|
return useAppStore(store)
|
||||||
|
}
|
||||||
104
src/stores/modules/dict.ts
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { store } from '../indexs'
|
||||||
|
// @ts-ignore
|
||||||
|
import { DictDataVO } from '@/api/system/dict/types'
|
||||||
|
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
||||||
|
const { wsCache } = useCache('sessionStorage')
|
||||||
|
// import { getSimpleDictDataList } from '@/api/system/dict/dict.data'
|
||||||
|
|
||||||
|
export interface DictValueType {
|
||||||
|
value: any
|
||||||
|
label: string
|
||||||
|
clorType?: string
|
||||||
|
cssClass?: string
|
||||||
|
}
|
||||||
|
export interface DictTypeType {
|
||||||
|
dictType: string
|
||||||
|
dictValue: DictValueType[]
|
||||||
|
}
|
||||||
|
export interface DictState {
|
||||||
|
dictMap: Map<string, any>
|
||||||
|
isSetDict: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useDictStore = defineStore('dict', {
|
||||||
|
state: (): DictState => ({
|
||||||
|
dictMap: new Map<string, any>(),
|
||||||
|
isSetDict: false
|
||||||
|
}),
|
||||||
|
getters: {
|
||||||
|
getDictMap(): Recordable {
|
||||||
|
const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE)
|
||||||
|
if (dictMap) {
|
||||||
|
this.dictMap = dictMap
|
||||||
|
}
|
||||||
|
return this.dictMap
|
||||||
|
},
|
||||||
|
getIsSetDict(): boolean {
|
||||||
|
return this.isSetDict
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
async setDictMap() {
|
||||||
|
const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE)
|
||||||
|
if (dictMap) {
|
||||||
|
this.dictMap = dictMap
|
||||||
|
this.isSetDict = true
|
||||||
|
} else {
|
||||||
|
// const res = await getSimpleDictDataList()
|
||||||
|
// 设置数据
|
||||||
|
const dictDataMap = new Map<string, any>()
|
||||||
|
// res.forEach((dictData: DictDataVO) => {
|
||||||
|
// // 获得 dictType 层级
|
||||||
|
// const enumValueObj = dictDataMap[dictData.dictType]
|
||||||
|
// if (!enumValueObj) {
|
||||||
|
// dictDataMap[dictData.dictType] = []
|
||||||
|
// }
|
||||||
|
// // 处理 dictValue 层级
|
||||||
|
// dictDataMap[dictData.dictType].push({
|
||||||
|
// value: dictData.value,
|
||||||
|
// label: dictData.label,
|
||||||
|
// colorType: dictData.colorType,
|
||||||
|
// cssClass: dictData.cssClass
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
this.dictMap = dictDataMap
|
||||||
|
this.isSetDict = true
|
||||||
|
wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getDictByType(type: string) {
|
||||||
|
if (!this.isSetDict) {
|
||||||
|
this.setDictMap()
|
||||||
|
}
|
||||||
|
return this.dictMap[type]
|
||||||
|
},
|
||||||
|
async resetDict() {
|
||||||
|
wsCache.delete(CACHE_KEY.DICT_CACHE)
|
||||||
|
// const res = await getSimpleDictDataList()
|
||||||
|
// 设置数据
|
||||||
|
const dictDataMap = new Map<string, any>()
|
||||||
|
// res.forEach((dictData: DictDataVO) => {
|
||||||
|
// // 获得 dictType 层级
|
||||||
|
// const enumValueObj = dictDataMap[dictData.dictType]
|
||||||
|
// if (!enumValueObj) {
|
||||||
|
// dictDataMap[dictData.dictType] = []
|
||||||
|
// }
|
||||||
|
// // 处理 dictValue 层级
|
||||||
|
// dictDataMap[dictData.dictType].push({
|
||||||
|
// value: dictData.value,
|
||||||
|
// label: dictData.label,
|
||||||
|
// colorType: dictData.colorType,
|
||||||
|
// cssClass: dictData.cssClass
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
this.dictMap = dictDataMap
|
||||||
|
this.isSetDict = true
|
||||||
|
wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useDictStoreWithOut = () => {
|
||||||
|
return useDictStore(store)
|
||||||
|
}
|
||||||
59
src/stores/modules/locale.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { store } from '../indexs'
|
||||||
|
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||||
|
import en from 'element-plus/es/locale/lang/en'
|
||||||
|
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
||||||
|
import { LocaleDropdownType } from '@/types/localeDropdown'
|
||||||
|
|
||||||
|
const { wsCache } = useCache()
|
||||||
|
|
||||||
|
const elLocaleMap = {
|
||||||
|
'zh-CN': zhCn,
|
||||||
|
en: en
|
||||||
|
}
|
||||||
|
interface LocaleState {
|
||||||
|
currentLocale: LocaleDropdownType
|
||||||
|
localeMap: LocaleDropdownType[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useLocaleStore = defineStore('locales', {
|
||||||
|
state: (): LocaleState => {
|
||||||
|
return {
|
||||||
|
currentLocale: {
|
||||||
|
lang: wsCache.get(CACHE_KEY.LANG) || 'zh-CN',
|
||||||
|
elLocale: elLocaleMap[wsCache.get(CACHE_KEY.LANG) || 'zh-CN']
|
||||||
|
},
|
||||||
|
// 多语言
|
||||||
|
localeMap: [
|
||||||
|
{
|
||||||
|
lang: 'zh-CN',
|
||||||
|
name: '简体中文'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
lang: 'en',
|
||||||
|
name: 'English'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getters: {
|
||||||
|
getCurrentLocale(): LocaleDropdownType {
|
||||||
|
return this.currentLocale
|
||||||
|
},
|
||||||
|
getLocaleMap(): LocaleDropdownType[] {
|
||||||
|
return this.localeMap
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
setCurrentLocale(localeMap: LocaleDropdownType) {
|
||||||
|
// this.locale = Object.assign(this.locale, localeMap)
|
||||||
|
this.currentLocale.lang = localeMap?.lang
|
||||||
|
this.currentLocale.elLocale = elLocaleMap[localeMap?.lang]
|
||||||
|
wsCache.set(CACHE_KEY.LANG, localeMap?.lang)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useLocaleStoreWithOut = () => {
|
||||||
|
return useLocaleStore(store)
|
||||||
|
}
|
||||||
48
src/stores/modules/lock.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { store } from '@/stores/indexs'
|
||||||
|
|
||||||
|
interface lockInfo {
|
||||||
|
isLock?: boolean
|
||||||
|
password?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LockState {
|
||||||
|
lockInfo: lockInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useLockStore = defineStore('lock', {
|
||||||
|
state: (): LockState => {
|
||||||
|
return {
|
||||||
|
lockInfo: {
|
||||||
|
// isLock: false, // 是否锁定屏幕
|
||||||
|
// password: '' // 锁屏密码
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getters: {
|
||||||
|
getLockInfo(): lockInfo {
|
||||||
|
return this.lockInfo
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
setLockInfo(lockInfo: lockInfo) {
|
||||||
|
this.lockInfo = lockInfo
|
||||||
|
},
|
||||||
|
resetLockInfo() {
|
||||||
|
this.lockInfo = {}
|
||||||
|
},
|
||||||
|
unLock(password: string) {
|
||||||
|
if (this.lockInfo?.password === password) {
|
||||||
|
this.resetLockInfo()
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
persist: true
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useLockStoreWithOut = () => {
|
||||||
|
return useLockStore(store)
|
||||||
|
}
|
||||||
66
src/stores/modules/permission.ts
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { store } from '@/stores/indexs'
|
||||||
|
import { cloneDeep } from 'lodash-es'
|
||||||
|
import { flatMultiLevelRoutes, generateRoute } from '@/utils/routerHelper'
|
||||||
|
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
||||||
|
|
||||||
|
const { wsCache } = useCache()
|
||||||
|
|
||||||
|
export interface PermissionState {
|
||||||
|
routers: AppRouteRecordRaw[]
|
||||||
|
addRouters: AppRouteRecordRaw[]
|
||||||
|
menuTabRouters: AppRouteRecordRaw[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export const usePermissionStore = defineStore('permission', {
|
||||||
|
state: (): PermissionState => ({
|
||||||
|
routers: [],
|
||||||
|
addRouters: [],
|
||||||
|
menuTabRouters: []
|
||||||
|
}),
|
||||||
|
getters: {
|
||||||
|
getRouters(): AppRouteRecordRaw[] {
|
||||||
|
return this.routers
|
||||||
|
},
|
||||||
|
getAddRouters(): AppRouteRecordRaw[] {
|
||||||
|
return flatMultiLevelRoutes(cloneDeep(this.addRouters))
|
||||||
|
},
|
||||||
|
getMenuTabRouters(): AppRouteRecordRaw[] {
|
||||||
|
return this.menuTabRouters
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
async generateRoutes(): Promise<unknown> {
|
||||||
|
return new Promise<void>(async (resolve) => {
|
||||||
|
// 获得菜单列表,它在登录的时候,setUserInfoAction 方法中已经进行获取
|
||||||
|
let res: AppCustomRouteRecordRaw[] = []
|
||||||
|
if (wsCache.get(CACHE_KEY.ROLE_ROUTERS)) {
|
||||||
|
res = wsCache.get(CACHE_KEY.ROLE_ROUTERS) as AppCustomRouteRecordRaw[]
|
||||||
|
}
|
||||||
|
const routerMap: AppRouteRecordRaw[] = generateRoute(res)
|
||||||
|
// 动态路由,404一定要放到最后面
|
||||||
|
this.addRouters = routerMap.concat([
|
||||||
|
{
|
||||||
|
path: '/:path(.*)*',
|
||||||
|
redirect: '/404',
|
||||||
|
name: '404Page',
|
||||||
|
meta: {
|
||||||
|
hidden: true,
|
||||||
|
breadcrumb: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
// 渲染菜单的所有路由
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
setMenuTabRouters(routers: AppRouteRecordRaw[]): void {
|
||||||
|
this.menuTabRouters = routers
|
||||||
|
}
|
||||||
|
},
|
||||||
|
persist: false
|
||||||
|
})
|
||||||
|
|
||||||
|
export const usePermissionStoreWithOut = () => {
|
||||||
|
return usePermissionStore(store)
|
||||||
|
}
|
||||||
55
src/stores/modules/simpleWorkflow.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { store } from '../index'
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
|
export const useWorkFlowStore = defineStore('simpleWorkflow', {
|
||||||
|
state: () => ({
|
||||||
|
tableId: '',
|
||||||
|
isTried: false,
|
||||||
|
promoterDrawer: false,
|
||||||
|
flowPermission1: {},
|
||||||
|
approverDrawer: false,
|
||||||
|
approverConfig1: {},
|
||||||
|
copyerDrawer: false,
|
||||||
|
copyerConfig1: {},
|
||||||
|
conditionDrawer: false,
|
||||||
|
conditionsConfig1: {
|
||||||
|
conditionNodes: []
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
actions: {
|
||||||
|
setTableId(payload) {
|
||||||
|
this.tableId = payload
|
||||||
|
},
|
||||||
|
setIsTried(payload) {
|
||||||
|
this.isTried = payload
|
||||||
|
},
|
||||||
|
setPromoter(payload) {
|
||||||
|
this.promoterDrawer = payload
|
||||||
|
},
|
||||||
|
setFlowPermission(payload) {
|
||||||
|
this.flowPermission1 = payload
|
||||||
|
},
|
||||||
|
setApprover(payload) {
|
||||||
|
this.approverDrawer = payload
|
||||||
|
},
|
||||||
|
setApproverConfig(payload) {
|
||||||
|
this.approverConfig1 = payload
|
||||||
|
},
|
||||||
|
setCopyer(payload) {
|
||||||
|
this.copyerDrawer = payload
|
||||||
|
},
|
||||||
|
setCopyerConfig(payload) {
|
||||||
|
this.copyerConfig1 = payload
|
||||||
|
},
|
||||||
|
setCondition(payload) {
|
||||||
|
this.conditionDrawer = payload
|
||||||
|
},
|
||||||
|
setConditionsConfig(payload) {
|
||||||
|
this.conditionsConfig1 = payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useWorkFlowStoreWithOut = () => {
|
||||||
|
return useWorkFlowStore(store)
|
||||||
|
}
|
||||||
141
src/stores/modules/tagsView.ts
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
import router from '@/router'
|
||||||
|
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
||||||
|
import { getRawRoute } from '@/utils/routerHelper'
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { store } from '../indexs'
|
||||||
|
import { findIndex } from '@/utils'
|
||||||
|
|
||||||
|
export interface TagsViewState {
|
||||||
|
visitedViews: RouteLocationNormalizedLoaded[]
|
||||||
|
cachedViews: Set<string>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useTagsViewStore = defineStore('tagsView', {
|
||||||
|
state: (): TagsViewState => ({
|
||||||
|
visitedViews: [],
|
||||||
|
cachedViews: new Set()
|
||||||
|
}),
|
||||||
|
getters: {
|
||||||
|
getVisitedViews(): RouteLocationNormalizedLoaded[] {
|
||||||
|
return this.visitedViews
|
||||||
|
},
|
||||||
|
getCachedViews(): string[] {
|
||||||
|
return Array.from(this.cachedViews)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
// 新增缓存和tag
|
||||||
|
addView(view: RouteLocationNormalizedLoaded): void {
|
||||||
|
this.addVisitedView(view)
|
||||||
|
this.addCachedView()
|
||||||
|
},
|
||||||
|
// 新增tag
|
||||||
|
addVisitedView(view: RouteLocationNormalizedLoaded) {
|
||||||
|
if (this.visitedViews.some((v) => v.path === view.path)) return
|
||||||
|
if (view.meta?.noTagsView) return
|
||||||
|
this.visitedViews.push(
|
||||||
|
Object.assign({}, view, {
|
||||||
|
title: view.meta?.title || 'no-name'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
},
|
||||||
|
// 新增缓存
|
||||||
|
addCachedView() {
|
||||||
|
const cacheMap: Set<string> = new Set()
|
||||||
|
for (const v of this.visitedViews) {
|
||||||
|
const item = getRawRoute(v)
|
||||||
|
const needCache = !item.meta?.noCache
|
||||||
|
if (!needCache) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const name = item.name as string
|
||||||
|
cacheMap.add(name)
|
||||||
|
}
|
||||||
|
if (Array.from(this.cachedViews).sort().toString() === Array.from(cacheMap).sort().toString())
|
||||||
|
return
|
||||||
|
this.cachedViews = cacheMap
|
||||||
|
},
|
||||||
|
// 删除某个
|
||||||
|
delView(view: RouteLocationNormalizedLoaded) {
|
||||||
|
this.delVisitedView(view)
|
||||||
|
this.delCachedView()
|
||||||
|
},
|
||||||
|
// 删除tag
|
||||||
|
delVisitedView(view: RouteLocationNormalizedLoaded) {
|
||||||
|
for (const [i, v] of this.visitedViews.entries()) {
|
||||||
|
if (v.path === view.path) {
|
||||||
|
this.visitedViews.splice(i, 1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 删除缓存
|
||||||
|
delCachedView() {
|
||||||
|
const route = router.currentRoute.value
|
||||||
|
const index = findIndex<string>(this.getCachedViews, (v) => v === route.name)
|
||||||
|
if (index > -1) {
|
||||||
|
this.cachedViews.delete(this.getCachedViews[index])
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 删除所有缓存和tag
|
||||||
|
delAllViews() {
|
||||||
|
this.delAllVisitedViews()
|
||||||
|
this.delCachedView()
|
||||||
|
},
|
||||||
|
// 删除所有tag
|
||||||
|
delAllVisitedViews() {
|
||||||
|
// const affixTags = this.visitedViews.filter((tag) => tag.meta.affix)
|
||||||
|
this.visitedViews = []
|
||||||
|
},
|
||||||
|
// 删除其他
|
||||||
|
delOthersViews(view: RouteLocationNormalizedLoaded) {
|
||||||
|
this.delOthersVisitedViews(view)
|
||||||
|
this.addCachedView()
|
||||||
|
},
|
||||||
|
// 删除其他tag
|
||||||
|
delOthersVisitedViews(view: RouteLocationNormalizedLoaded) {
|
||||||
|
this.visitedViews = this.visitedViews.filter((v) => {
|
||||||
|
return v?.meta?.affix || v.path === view.path
|
||||||
|
})
|
||||||
|
},
|
||||||
|
// 删除左侧
|
||||||
|
delLeftViews(view: RouteLocationNormalizedLoaded) {
|
||||||
|
const index = findIndex<RouteLocationNormalizedLoaded>(
|
||||||
|
this.visitedViews,
|
||||||
|
(v) => v.path === view.path
|
||||||
|
)
|
||||||
|
if (index > -1) {
|
||||||
|
this.visitedViews = this.visitedViews.filter((v, i) => {
|
||||||
|
return v?.meta?.affix || v.path === view.path || i > index
|
||||||
|
})
|
||||||
|
this.addCachedView()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 删除右侧
|
||||||
|
delRightViews(view: RouteLocationNormalizedLoaded) {
|
||||||
|
const index = findIndex<RouteLocationNormalizedLoaded>(
|
||||||
|
this.visitedViews,
|
||||||
|
(v) => v.path === view.path
|
||||||
|
)
|
||||||
|
if (index > -1) {
|
||||||
|
this.visitedViews = this.visitedViews.filter((v, i) => {
|
||||||
|
return v?.meta?.affix || v.path === view.path || i < index
|
||||||
|
})
|
||||||
|
this.addCachedView()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateVisitedView(view: RouteLocationNormalizedLoaded) {
|
||||||
|
for (let v of this.visitedViews) {
|
||||||
|
if (v.path === view.path) {
|
||||||
|
v = Object.assign(v, view)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
persist: false
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useTagsViewStoreWithOut = () => {
|
||||||
|
return useTagsViewStore(store)
|
||||||
|
}
|
||||||
103
src/stores/modules/user.ts
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
import { store } from '@/stores/indexs'
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { getAccessToken, removeToken } from '@/utils/auth'
|
||||||
|
import { CACHE_KEY, useCache, deleteUserCache } from '@/hooks/web/useCache'
|
||||||
|
// import { getInfo, loginOut } from '@/api/login'
|
||||||
|
|
||||||
|
const { wsCache } = useCache()
|
||||||
|
|
||||||
|
interface UserVO {
|
||||||
|
id: number
|
||||||
|
avatar: string
|
||||||
|
nickname: string
|
||||||
|
deptId: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UserInfoVO {
|
||||||
|
// USER 缓存
|
||||||
|
permissions: string[]
|
||||||
|
roles: string[]
|
||||||
|
isSetUser: boolean
|
||||||
|
user: UserVO
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useUserStore = defineStore('admin-user', {
|
||||||
|
state: (): UserInfoVO => ({
|
||||||
|
permissions: [],
|
||||||
|
roles: [],
|
||||||
|
isSetUser: false,
|
||||||
|
user: {
|
||||||
|
id: 0,
|
||||||
|
avatar: '',
|
||||||
|
nickname: '',
|
||||||
|
deptId: 0
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
getters: {
|
||||||
|
getPermissions(): string[] {
|
||||||
|
return this.permissions
|
||||||
|
},
|
||||||
|
getRoles(): string[] {
|
||||||
|
return this.roles
|
||||||
|
},
|
||||||
|
getIsSetUser(): boolean {
|
||||||
|
return this.isSetUser
|
||||||
|
},
|
||||||
|
getUser(): UserVO {
|
||||||
|
return this.user
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
async setUserInfoAction() {
|
||||||
|
if (!getAccessToken()) {
|
||||||
|
this.resetState()
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
let userInfo = wsCache.get(CACHE_KEY.USER)
|
||||||
|
if (!userInfo) {
|
||||||
|
// userInfo = await getInfo()
|
||||||
|
}
|
||||||
|
this.permissions = userInfo.permissions
|
||||||
|
this.roles = userInfo.roles
|
||||||
|
this.user = userInfo.user
|
||||||
|
this.isSetUser = true
|
||||||
|
wsCache.set(CACHE_KEY.USER, userInfo)
|
||||||
|
wsCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
|
||||||
|
},
|
||||||
|
async setUserAvatarAction(avatar: string) {
|
||||||
|
const userInfo = wsCache.get(CACHE_KEY.USER)
|
||||||
|
// NOTE: 是否需要像`setUserInfoAction`一样判断`userInfo != null`
|
||||||
|
this.user.avatar = avatar
|
||||||
|
userInfo.user.avatar = avatar
|
||||||
|
wsCache.set(CACHE_KEY.USER, userInfo)
|
||||||
|
},
|
||||||
|
async setUserNicknameAction(nickname: string) {
|
||||||
|
const userInfo = wsCache.get(CACHE_KEY.USER)
|
||||||
|
// NOTE: 是否需要像`setUserInfoAction`一样判断`userInfo != null`
|
||||||
|
this.user.nickname = nickname
|
||||||
|
userInfo.user.nickname = nickname
|
||||||
|
wsCache.set(CACHE_KEY.USER, userInfo)
|
||||||
|
},
|
||||||
|
async loginOut() {
|
||||||
|
// await loginOut()
|
||||||
|
removeToken()
|
||||||
|
deleteUserCache() // 删除用户缓存
|
||||||
|
this.resetState()
|
||||||
|
},
|
||||||
|
resetState() {
|
||||||
|
this.permissions = []
|
||||||
|
this.roles = []
|
||||||
|
this.isSetUser = false
|
||||||
|
this.user = {
|
||||||
|
id: 0,
|
||||||
|
avatar: '',
|
||||||
|
nickname: '',
|
||||||
|
deptId: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useUserStoreWithOut = () => {
|
||||||
|
return useUserStore(store)
|
||||||
|
}
|
||||||
6
src/styles/global.module.scss
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
@import './variables.scss';
|
||||||
|
// 导出变量
|
||||||
|
:export {
|
||||||
|
namespace: $namespace;
|
||||||
|
elNamespace: $elNamespace;
|
||||||
|
}
|
||||||
4
src/styles/variables.scss
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// 命名空间
|
||||||
|
$namespace: v;
|
||||||
|
// el命名空间
|
||||||
|
$elNamespace: el;
|
||||||
141
src/types/auto-components.d.ts
vendored
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
/* prettier-ignore */
|
||||||
|
// @ts-nocheck
|
||||||
|
// Generated by unplugin-vue-components
|
||||||
|
// Read more: https://github.com/vuejs/core/pull/3399
|
||||||
|
export {}
|
||||||
|
|
||||||
|
declare module 'vue' {
|
||||||
|
export interface GlobalComponents {
|
||||||
|
AddNode: typeof import('./../components/SimpleProcessDesigner/src/addNode.vue')['default']
|
||||||
|
AppLinkInput: typeof import('./../components/AppLinkInput/index.vue')['default']
|
||||||
|
AppLinkSelectDialog: typeof import('./../components/AppLinkInput/AppLinkSelectDialog.vue')['default']
|
||||||
|
Backtop: typeof import('./../components/Backtop/src/Backtop.vue')['default']
|
||||||
|
CardTitle: typeof import('./../components/Card/src/CardTitle.vue')['default']
|
||||||
|
ColorInput: typeof import('./../components/ColorInput/index.vue')['default']
|
||||||
|
ComponentContainer: typeof import('./../components/DiyEditor/components/ComponentContainer.vue')['default']
|
||||||
|
ComponentContainerProperty: typeof import('./../components/DiyEditor/components/ComponentContainerProperty.vue')['default']
|
||||||
|
ComponentLibrary: typeof import('./../components/DiyEditor/components/ComponentLibrary.vue')['default']
|
||||||
|
ConfigGlobal: typeof import('./../components/ConfigGlobal/src/ConfigGlobal.vue')['default']
|
||||||
|
ContentDetailWrap: typeof import('./../components/ContentDetailWrap/src/ContentDetailWrap.vue')['default']
|
||||||
|
// ContentWrap: typeof import('./../components/ContentWrap/src/ContentWrap.vue')['default']
|
||||||
|
CopperModal: typeof import('./../components/Cropper/src/CopperModal.vue')['default']
|
||||||
|
CountTo: typeof import('./../components/CountTo/src/CountTo.vue')['default']
|
||||||
|
Crontab: typeof import('./../components/Crontab/src/Crontab.vue')['default']
|
||||||
|
Cropper: typeof import('./../components/Cropper/src/Cropper.vue')['default']
|
||||||
|
CropperAvatar: typeof import('./../components/Cropper/src/CropperAvatar.vue')['default']
|
||||||
|
Descriptions: typeof import('./../components/Descriptions/src/Descriptions.vue')['default']
|
||||||
|
DescriptionsItemLabel: typeof import('./../components/Descriptions/src/DescriptionsItemLabel.vue')['default']
|
||||||
|
Dialog: typeof import('./../components/Dialog/src/Dialog.vue')['default']
|
||||||
|
DictSelect: typeof import('./../components/DictSelect/src/DictSelect.vue')['default']
|
||||||
|
DictTag: typeof import('./../components/DictTag/src/DictTag.vue')['default']
|
||||||
|
DiyEditor: typeof import('./../components/DiyEditor/index.vue')['default']
|
||||||
|
DocAlert: typeof import('./../components/DocAlert/index.vue')['default']
|
||||||
|
Draggable: typeof import('./../components/Draggable/index.vue')['default']
|
||||||
|
Echart: typeof import('./../components/Echart/src/Echart.vue')['default']
|
||||||
|
Editor: typeof import('./../components/Editor/src/Editor.vue')['default']
|
||||||
|
ElAlert: typeof import('element-plus/es')['ElAlert']
|
||||||
|
ElAvatar: typeof import('element-plus/es')['ElAvatar']
|
||||||
|
ElBadge: typeof import('element-plus/es')['ElBadge']
|
||||||
|
ElButton: typeof import('element-plus/es')['ElButton']
|
||||||
|
ElButtonGroup: typeof import('element-plus/es')['ElButtonGroup']
|
||||||
|
ElCard: typeof import('element-plus/es')['ElCard']
|
||||||
|
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
|
||||||
|
ElCheckboxGroup: typeof import('element-plus/es')['ElCheckboxGroup']
|
||||||
|
ElCol: typeof import('element-plus/es')['ElCol']
|
||||||
|
ElCollapse: typeof import('element-plus/es')['ElCollapse']
|
||||||
|
ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
|
||||||
|
ElDatePicker: typeof import('element-plus/es')['ElDatePicker']
|
||||||
|
ElDialog: typeof import('element-plus/es')['ElDialog']
|
||||||
|
ElDivider: typeof import('element-plus/es')['ElDivider']
|
||||||
|
ElDrawer: typeof import('element-plus/es')['ElDrawer']
|
||||||
|
ElDropdown: typeof import('element-plus/es')['ElDropdown']
|
||||||
|
ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
|
||||||
|
ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
|
||||||
|
ElementBaseInfo: typeof import('./../components/bpmnProcessDesigner/package/penal/base/ElementBaseInfo.vue')['default']
|
||||||
|
ElementForm: typeof import('./../components/bpmnProcessDesigner/package/penal/form/ElementForm.vue')['default']
|
||||||
|
ElementListeners: typeof import('./../components/bpmnProcessDesigner/package/penal/listeners/ElementListeners.vue')['default']
|
||||||
|
ElementMultiInstance: typeof import('./../components/bpmnProcessDesigner/package/penal/multi-instance/ElementMultiInstance.vue')['default']
|
||||||
|
ElementOtherConfig: typeof import('./../components/bpmnProcessDesigner/package/penal/other/ElementOtherConfig.vue')['default']
|
||||||
|
ElementProperties: typeof import('./../components/bpmnProcessDesigner/package/penal/properties/ElementProperties.vue')['default']
|
||||||
|
ElementTask: typeof import('./../components/bpmnProcessDesigner/package/penal/task/ElementTask.vue')['default']
|
||||||
|
ElForm: typeof import('element-plus/es')['ElForm']
|
||||||
|
ElFormItem: typeof import('element-plus/es')['ElFormItem']
|
||||||
|
ElIcon: typeof import('element-plus/es')['ElIcon']
|
||||||
|
ElImage: typeof import('element-plus/es')['ElImage']
|
||||||
|
ElImageViewer: typeof import('element-plus/es')['ElImageViewer']
|
||||||
|
ElInput: typeof import('element-plus/es')['ElInput']
|
||||||
|
ElLink: typeof import('element-plus/es')['ElLink']
|
||||||
|
ElOption: typeof import('element-plus/es')['ElOption']
|
||||||
|
ElPagination: typeof import('element-plus/es')['ElPagination']
|
||||||
|
ElPopover: typeof import('element-plus/es')['ElPopover']
|
||||||
|
ElRadio: typeof import('element-plus/es')['ElRadio']
|
||||||
|
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
|
||||||
|
ElRow: typeof import('element-plus/es')['ElRow']
|
||||||
|
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
|
||||||
|
ElSelect: typeof import('element-plus/es')['ElSelect']
|
||||||
|
ElSkeleton: typeof import('element-plus/es')['ElSkeleton']
|
||||||
|
ElSwitch: typeof import('element-plus/es')['ElSwitch']
|
||||||
|
ElTable: typeof import('element-plus/es')['ElTable']
|
||||||
|
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
|
||||||
|
ElTabPane: typeof import('element-plus/es')['ElTabPane']
|
||||||
|
ElTabs: typeof import('element-plus/es')['ElTabs']
|
||||||
|
ElTag: typeof import('element-plus/es')['ElTag']
|
||||||
|
ElTooltip: typeof import('element-plus/es')['ElTooltip']
|
||||||
|
ElTreeSelect: typeof import('element-plus/es')['ElTreeSelect']
|
||||||
|
ElUpload: typeof import('element-plus/es')['ElUpload']
|
||||||
|
Error: typeof import('./../components/Error/src/Error.vue')['default']
|
||||||
|
FlowCondition: typeof import('./../components/bpmnProcessDesigner/package/penal/flow-condition/FlowCondition.vue')['default']
|
||||||
|
Form: typeof import('./../components/Form/src/Form.vue')['default']
|
||||||
|
Highlight: typeof import('./../components/Highlight/src/Highlight.vue')['default']
|
||||||
|
Icon: typeof import('./../components/Icon/src/Icon.vue')['default']
|
||||||
|
IconSelect: typeof import('./../components/Icon/src/IconSelect.vue')['default']
|
||||||
|
IFrame: typeof import('./../components/IFrame/src/IFrame.vue')['default']
|
||||||
|
ImageViewer: typeof import('./../components/ImageViewer/src/ImageViewer.vue')['default']
|
||||||
|
Infotip: typeof import('./../components/Infotip/src/Infotip.vue')['default']
|
||||||
|
InputPassword: typeof import('./../components/InputPassword/src/InputPassword.vue')['default']
|
||||||
|
InputWithColor: typeof import('./../components/InputWithColor/index.vue')['default']
|
||||||
|
MagicCubeEditor: typeof import('./../components/MagicCubeEditor/index.vue')['default']
|
||||||
|
Modules: typeof import('./../../.idea/modules.xml')['default']
|
||||||
|
NodeWrap: typeof import('./../components/SimpleProcessDesigner/src/nodeWrap.vue')['default']
|
||||||
|
OperateLogV2: typeof import('./../components/OperateLogV2/src/OperateLogV2.vue')['default']
|
||||||
|
Pagination: typeof import('./../components/Pagination/index.vue')['default']
|
||||||
|
ProcessDesigner: typeof import('./../components/bpmnProcessDesigner/package/designer/ProcessDesigner.vue')['default']
|
||||||
|
ProcessExpressionDialog: typeof import('./../components/bpmnProcessDesigner/package/penal/task/task-components/ProcessExpressionDialog.vue')['default']
|
||||||
|
ProcessListenerDialog: typeof import('./../components/bpmnProcessDesigner/package/penal/listeners/ProcessListenerDialog.vue')['default']
|
||||||
|
ProcessPalette: typeof import('./../components/bpmnProcessDesigner/package/palette/ProcessPalette.vue')['default']
|
||||||
|
ProcessViewer: typeof import('./../components/bpmnProcessDesigner/package/designer/ProcessViewer.vue')['default']
|
||||||
|
PropertiesPanel: typeof import('./../components/bpmnProcessDesigner/package/penal/PropertiesPanel.vue')['default']
|
||||||
|
Qrcode: typeof import('./../components/Qrcode/src/Qrcode.vue')['default']
|
||||||
|
ReceiveTask: typeof import('./../components/bpmnProcessDesigner/package/penal/task/task-components/ReceiveTask.vue')['default']
|
||||||
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
|
RouterSearch: typeof import('./../components/RouterSearch/index.vue')['default']
|
||||||
|
RouterView: typeof import('vue-router')['RouterView']
|
||||||
|
ScriptTask: typeof import('./../components/bpmnProcessDesigner/package/penal/task/task-components/ScriptTask.vue')['default']
|
||||||
|
Search: typeof import('./../components/Search/src/Search.vue')['default']
|
||||||
|
ShortcutDateRangePicker: typeof import('./../components/ShortcutDateRangePicker/index.vue')['default']
|
||||||
|
SignalAndMessage: typeof import('./../components/bpmnProcessDesigner/package/penal/signal-message/SignalAndMessage.vue')['default']
|
||||||
|
Sticky: typeof import('./../components/Sticky/src/Sticky.vue')['default']
|
||||||
|
SummaryCard: typeof import('./../components/SummaryCard/index.vue')['default']
|
||||||
|
Table: typeof import('./../components/Table/src/Table.vue')['default']
|
||||||
|
TableSelectForm: typeof import('./../components/Table/src/TableSelectForm.vue')['default']
|
||||||
|
Tooltip: typeof import('./../components/Tooltip/src/Tooltip.vue')['default']
|
||||||
|
UploadFile: typeof import('./../components/UploadFile/src/UploadFile.vue')['default']
|
||||||
|
UploadImg: typeof import('./../components/UploadFile/src/UploadImg.vue')['default']
|
||||||
|
UploadImgs: typeof import('./../components/UploadFile/src/UploadImgs.vue')['default']
|
||||||
|
UserTask: typeof import('./../components/bpmnProcessDesigner/package/penal/task/task-components/UserTask.vue')['default']
|
||||||
|
UserTaskListeners: typeof import('./../components/bpmnProcessDesigner/package/penal/listeners/UserTaskListeners.vue')['default']
|
||||||
|
Vcs: typeof import('./../../.idea/vcs.xml')['default']
|
||||||
|
Verify: typeof import('./../components/Verifition/src/Verify.vue')['default']
|
||||||
|
VerifyPoints: typeof import('./../components/Verifition/src/Verify/VerifyPoints.vue')['default']
|
||||||
|
VerifySlide: typeof import('./../components/Verifition/src/Verify/VerifySlide.vue')['default']
|
||||||
|
VerticalButtonGroup: typeof import('./../components/VerticalButtonGroup/index.vue')['default']
|
||||||
|
'Workspace.xml': typeof import('./../../.idea/workspace.xml.tmp')['default']
|
||||||
|
XButton: typeof import('./../components/XButton/src/XButton.vue')['default']
|
||||||
|
XTextButton: typeof import('./../components/XButton/src/XTextButton.vue')['default']
|
||||||
|
YudaoUiAdminVue3: typeof import('./../../.idea/yudao-ui-admin-vue3.iml')['default']
|
||||||
|
}
|
||||||
|
export interface ComponentCustomProperties {
|
||||||
|
vLoading: typeof import('element-plus/es')['ElLoadingDirective']
|
||||||
|
}
|
||||||
|
}
|
||||||
78
src/types/auto-imports.d.ts
vendored
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
/* prettier-ignore */
|
||||||
|
// @ts-nocheck
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
|
// Generated by unplugin-auto-import
|
||||||
|
export {}
|
||||||
|
declare global {
|
||||||
|
const DICT_TYPE: typeof import('@/utils/dict')['DICT_TYPE']
|
||||||
|
const EffectScope: typeof import('vue')['EffectScope']
|
||||||
|
const ElMessageBox: typeof import('element-plus/es')['ElMessageBox']
|
||||||
|
const computed: typeof import('vue')['computed']
|
||||||
|
const createApp: typeof import('vue')['createApp']
|
||||||
|
const customRef: typeof import('vue')['customRef']
|
||||||
|
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
|
||||||
|
const defineComponent: typeof import('vue')['defineComponent']
|
||||||
|
const effectScope: typeof import('vue')['effectScope']
|
||||||
|
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
|
||||||
|
const getCurrentScope: typeof import('vue')['getCurrentScope']
|
||||||
|
const h: typeof import('vue')['h']
|
||||||
|
const inject: typeof import('vue')['inject']
|
||||||
|
const isProxy: typeof import('vue')['isProxy']
|
||||||
|
const isReactive: typeof import('vue')['isReactive']
|
||||||
|
const isReadonly: typeof import('vue')['isReadonly']
|
||||||
|
const isRef: typeof import('vue')['isRef']
|
||||||
|
const markRaw: typeof import('vue')['markRaw']
|
||||||
|
const nextTick: typeof import('vue')['nextTick']
|
||||||
|
const onActivated: typeof import('vue')['onActivated']
|
||||||
|
const onBeforeMount: typeof import('vue')['onBeforeMount']
|
||||||
|
const onBeforeRouteLeave: typeof import('vue-router')['onBeforeRouteLeave']
|
||||||
|
const onBeforeRouteUpdate: typeof import('vue-router')['onBeforeRouteUpdate']
|
||||||
|
const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
|
||||||
|
const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']
|
||||||
|
const onDeactivated: typeof import('vue')['onDeactivated']
|
||||||
|
const onErrorCaptured: typeof import('vue')['onErrorCaptured']
|
||||||
|
const onMounted: typeof import('vue')['onMounted']
|
||||||
|
const onRenderTracked: typeof import('vue')['onRenderTracked']
|
||||||
|
const onRenderTriggered: typeof import('vue')['onRenderTriggered']
|
||||||
|
const onScopeDispose: typeof import('vue')['onScopeDispose']
|
||||||
|
const onServerPrefetch: typeof import('vue')['onServerPrefetch']
|
||||||
|
const onUnmounted: typeof import('vue')['onUnmounted']
|
||||||
|
const onUpdated: typeof import('vue')['onUpdated']
|
||||||
|
const provide: typeof import('vue')['provide']
|
||||||
|
const reactive: typeof import('vue')['reactive']
|
||||||
|
const readonly: typeof import('vue')['readonly']
|
||||||
|
const ref: typeof import('vue')['ref']
|
||||||
|
const required: typeof import('@/utils/formRules')['required']
|
||||||
|
const resolveComponent: typeof import('vue')['resolveComponent']
|
||||||
|
const shallowReactive: typeof import('vue')['shallowReactive']
|
||||||
|
const shallowReadonly: typeof import('vue')['shallowReadonly']
|
||||||
|
const shallowRef: typeof import('vue')['shallowRef']
|
||||||
|
const toRaw: typeof import('vue')['toRaw']
|
||||||
|
const toRef: typeof import('vue')['toRef']
|
||||||
|
const toRefs: typeof import('vue')['toRefs']
|
||||||
|
const toValue: typeof import('vue')['toValue']
|
||||||
|
const triggerRef: typeof import('vue')['triggerRef']
|
||||||
|
const unref: typeof import('vue')['unref']
|
||||||
|
const useAttrs: typeof import('vue')['useAttrs']
|
||||||
|
const useCrudSchemas: typeof import('@/hooks/web/useCrudSchemas')['useCrudSchemas']
|
||||||
|
const useCssModule: typeof import('vue')['useCssModule']
|
||||||
|
const useCssVars: typeof import('vue')['useCssVars']
|
||||||
|
const useI18n: typeof import('@/hooks/web/useI18n')['useI18n']
|
||||||
|
const useLink: typeof import('vue-router')['useLink']
|
||||||
|
const useMessage: typeof import('@/hooks/web/useMessage')['useMessage']
|
||||||
|
const useRoute: typeof import('vue-router')['useRoute']
|
||||||
|
const useRouter: typeof import('vue-router')['useRouter']
|
||||||
|
const useSlots: typeof import('vue')['useSlots']
|
||||||
|
const useTable: typeof import('@/hooks/web/useTable')['useTable']
|
||||||
|
const watch: typeof import('vue')['watch']
|
||||||
|
const watchEffect: typeof import('vue')['watchEffect']
|
||||||
|
const watchPostEffect: typeof import('vue')['watchPostEffect']
|
||||||
|
const watchSyncEffect: typeof import('vue')['watchSyncEffect']
|
||||||
|
}
|
||||||
|
// for type re-export
|
||||||
|
declare global {
|
||||||
|
// @ts-ignore
|
||||||
|
export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
|
||||||
|
import('vue')
|
||||||
|
}
|
||||||
3
src/types/elementPlus.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export type ElementPlusSize = 'default' | 'small' | 'large'
|
||||||
|
|
||||||
|
export type ElementPlusInfoType = 'success' | 'info' | 'warning' | 'danger'
|
||||||
5
src/types/icon.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export interface IconTypes {
|
||||||
|
size?: number
|
||||||
|
color?: string
|
||||||
|
icon: string
|
||||||
|
}
|
||||||
1
src/types/layout.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export type LayoutType = 'classic' | 'topLeft' | 'top' | 'cutMenu'
|
||||||
16
src/types/theme.d.ts
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
export type ThemeTypes = {
|
||||||
|
elColorPrimary?: string
|
||||||
|
leftMenuBorderColor?: string
|
||||||
|
leftMenuBgColor?: string
|
||||||
|
leftMenuBgLightColor?: string
|
||||||
|
leftMenuBgActiveColor?: string
|
||||||
|
leftMenuCollapseBgActiveColor?: string
|
||||||
|
leftMenuTextColor?: string
|
||||||
|
leftMenuTextActiveColor?: string
|
||||||
|
logoTitleTextColor?: string
|
||||||
|
logoBorderColor?: string
|
||||||
|
topHeaderBgColor?: string
|
||||||
|
topHeaderTextColor?: string
|
||||||
|
topHeaderHoverColor?: string
|
||||||
|
topToolBorderColor?: string
|
||||||
|
}
|
||||||
70
src/utils/auth.ts
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import { useCache, CACHE_KEY } from '@/hooks/web/useCache'
|
||||||
|
import { decrypt, encrypt } from '@/utils/jsencrypt'
|
||||||
|
|
||||||
|
const { wsCache } = useCache()
|
||||||
|
|
||||||
|
const AccessTokenKey = 'ACCESS_TOKEN'
|
||||||
|
const RefreshTokenKey = 'REFRESH_TOKEN'
|
||||||
|
|
||||||
|
// 获取token
|
||||||
|
export const getAccessToken = () => {
|
||||||
|
// 此处与TokenKey相同,此写法解决初始化时Cookies中不存在TokenKey报错
|
||||||
|
return wsCache.get(AccessTokenKey) ? wsCache.get(AccessTokenKey) : wsCache.get('ACCESS_TOKEN')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 刷新token
|
||||||
|
export const getRefreshToken = () => {
|
||||||
|
return wsCache.get(RefreshTokenKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置token
|
||||||
|
export const setToken = (token: any) => {
|
||||||
|
wsCache.set(RefreshTokenKey, token.refreshToken)
|
||||||
|
wsCache.set(AccessTokenKey, token.accessToken)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除token
|
||||||
|
export const removeToken = () => {
|
||||||
|
wsCache.delete(AccessTokenKey)
|
||||||
|
wsCache.delete(RefreshTokenKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 格式化token(jwt格式) */
|
||||||
|
export const formatToken = (token: string): string => {
|
||||||
|
return 'Bearer ' + token
|
||||||
|
}
|
||||||
|
// ========== 账号相关 ==========
|
||||||
|
|
||||||
|
export type LoginFormType = {
|
||||||
|
tenantName: string
|
||||||
|
username: string
|
||||||
|
password: string
|
||||||
|
rememberMe: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getLoginForm = () => {
|
||||||
|
const loginForm: LoginFormType = wsCache.get(CACHE_KEY.LoginForm)
|
||||||
|
if (loginForm) {
|
||||||
|
loginForm.password = decrypt(loginForm.password) as string
|
||||||
|
}
|
||||||
|
return loginForm
|
||||||
|
}
|
||||||
|
|
||||||
|
export const setLoginForm = (loginForm: LoginFormType) => {
|
||||||
|
loginForm.password = encrypt(loginForm.password) as string
|
||||||
|
wsCache.set(CACHE_KEY.LoginForm, loginForm, { exp: 30 * 24 * 60 * 60 })
|
||||||
|
}
|
||||||
|
|
||||||
|
export const removeLoginForm = () => {
|
||||||
|
wsCache.delete(CACHE_KEY.LoginForm)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 租户相关 ==========
|
||||||
|
|
||||||
|
export const getTenantId = () => {
|
||||||
|
return wsCache.get(CACHE_KEY.TenantId)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const setTenantId = (username: string) => {
|
||||||
|
wsCache.set(CACHE_KEY.TenantId, username)
|
||||||
|
}
|
||||||
174
src/utils/color.ts
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
/**
|
||||||
|
* 判断是否 十六进制颜色值.
|
||||||
|
* 输入形式可为 #fff000 #f00
|
||||||
|
*
|
||||||
|
* @param String color 十六进制颜色值
|
||||||
|
* @return Boolean
|
||||||
|
*/
|
||||||
|
export const isHexColor = (color: string) => {
|
||||||
|
const reg = /^#([0-9a-fA-F]{3}|[0-9a-fA-f]{6})$/
|
||||||
|
return reg.test(color)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RGB 颜色值转换为 十六进制颜色值.
|
||||||
|
* r, g, 和 b 需要在 [0, 255] 范围内
|
||||||
|
*
|
||||||
|
* @return String 类似#ff00ff
|
||||||
|
* @param r
|
||||||
|
* @param g
|
||||||
|
* @param b
|
||||||
|
*/
|
||||||
|
export const rgbToHex = (r: number, g: number, b: number) => {
|
||||||
|
// tslint:disable-next-line:no-bitwise
|
||||||
|
const hex = ((r << 16) | (g << 8) | b).toString(16)
|
||||||
|
return '#' + new Array(Math.abs(hex.length - 7)).join('0') + hex
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform a HEX color to its RGB representation
|
||||||
|
* @param {string} hex The color to transform
|
||||||
|
* @returns The RGB representation of the passed color
|
||||||
|
*/
|
||||||
|
export const hexToRGB = (hex: string, opacity?: number) => {
|
||||||
|
let sHex = hex.toLowerCase()
|
||||||
|
if (isHexColor(hex)) {
|
||||||
|
if (sHex.length === 4) {
|
||||||
|
let sColorNew = '#'
|
||||||
|
for (let i = 1; i < 4; i += 1) {
|
||||||
|
sColorNew += sHex.slice(i, i + 1).concat(sHex.slice(i, i + 1))
|
||||||
|
}
|
||||||
|
sHex = sColorNew
|
||||||
|
}
|
||||||
|
const sColorChange: number[] = []
|
||||||
|
for (let i = 1; i < 7; i += 2) {
|
||||||
|
sColorChange.push(parseInt('0x' + sHex.slice(i, i + 2)))
|
||||||
|
}
|
||||||
|
return opacity
|
||||||
|
? 'RGBA(' + sColorChange.join(',') + ',' + opacity + ')'
|
||||||
|
: 'RGB(' + sColorChange.join(',') + ')'
|
||||||
|
}
|
||||||
|
return sHex
|
||||||
|
}
|
||||||
|
|
||||||
|
export const colorIsDark = (color: string) => {
|
||||||
|
if (!isHexColor(color)) return
|
||||||
|
const [r, g, b] = hexToRGB(color)
|
||||||
|
.replace(/(?:\(|\)|rgb|RGB)*/g, '')
|
||||||
|
.split(',')
|
||||||
|
.map((item) => Number(item))
|
||||||
|
return r * 0.299 + g * 0.578 + b * 0.114 < 192
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Darkens a HEX color given the passed percentage
|
||||||
|
* @param {string} color The color to process
|
||||||
|
* @param {number} amount The amount to change the color by
|
||||||
|
* @returns {string} The HEX representation of the processed color
|
||||||
|
*/
|
||||||
|
export const darken = (color: string, amount: number) => {
|
||||||
|
color = color.indexOf('#') >= 0 ? color.substring(1, color.length) : color
|
||||||
|
amount = Math.trunc((255 * amount) / 100)
|
||||||
|
return `#${subtractLight(color.substring(0, 2), amount)}${subtractLight(
|
||||||
|
color.substring(2, 4),
|
||||||
|
amount
|
||||||
|
)}${subtractLight(color.substring(4, 6), amount)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lightens a 6 char HEX color according to the passed percentage
|
||||||
|
* @param {string} color The color to change
|
||||||
|
* @param {number} amount The amount to change the color by
|
||||||
|
* @returns {string} The processed color represented as HEX
|
||||||
|
*/
|
||||||
|
export const lighten = (color: string, amount: number) => {
|
||||||
|
color = color.indexOf('#') >= 0 ? color.substring(1, color.length) : color
|
||||||
|
amount = Math.trunc((255 * amount) / 100)
|
||||||
|
return `#${addLight(color.substring(0, 2), amount)}${addLight(
|
||||||
|
color.substring(2, 4),
|
||||||
|
amount
|
||||||
|
)}${addLight(color.substring(4, 6), amount)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Suma el porcentaje indicado a un color (RR, GG o BB) hexadecimal para aclararlo */
|
||||||
|
/**
|
||||||
|
* Sums the passed percentage to the R, G or B of a HEX color
|
||||||
|
* @param {string} color The color to change
|
||||||
|
* @param {number} amount The amount to change the color by
|
||||||
|
* @returns {string} The processed part of the color
|
||||||
|
*/
|
||||||
|
const addLight = (color: string, amount: number) => {
|
||||||
|
const cc = parseInt(color, 16) + amount
|
||||||
|
const c = cc > 255 ? 255 : cc
|
||||||
|
return c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates luminance of an rgb color
|
||||||
|
* @param {number} r red
|
||||||
|
* @param {number} g green
|
||||||
|
* @param {number} b blue
|
||||||
|
*/
|
||||||
|
const luminanace = (r: number, g: number, b: number) => {
|
||||||
|
const a = [r, g, b].map((v) => {
|
||||||
|
v /= 255
|
||||||
|
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4)
|
||||||
|
})
|
||||||
|
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates contrast between two rgb colors
|
||||||
|
* @param {string} rgb1 rgb color 1
|
||||||
|
* @param {string} rgb2 rgb color 2
|
||||||
|
*/
|
||||||
|
const contrast = (rgb1: string[], rgb2: number[]) => {
|
||||||
|
return (
|
||||||
|
(luminanace(~~rgb1[0], ~~rgb1[1], ~~rgb1[2]) + 0.05) /
|
||||||
|
(luminanace(rgb2[0], rgb2[1], rgb2[2]) + 0.05)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines what the best text color is (black or white) based con the contrast with the background
|
||||||
|
* @param hexColor - Last selected color by the user
|
||||||
|
*/
|
||||||
|
export const calculateBestTextColor = (hexColor: string) => {
|
||||||
|
const rgbColor = hexToRGB(hexColor.substring(1))
|
||||||
|
const contrastWithBlack = contrast(rgbColor.split(','), [0, 0, 0])
|
||||||
|
|
||||||
|
return contrastWithBlack >= 12 ? '#000000' : '#FFFFFF'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subtracts the indicated percentage to the R, G or B of a HEX color
|
||||||
|
* @param {string} color The color to change
|
||||||
|
* @param {number} amount The amount to change the color by
|
||||||
|
* @returns {string} The processed part of the color
|
||||||
|
*/
|
||||||
|
const subtractLight = (color: string, amount: number) => {
|
||||||
|
const cc = parseInt(color, 16) - amount
|
||||||
|
const c = cc < 0 ? 0 : cc
|
||||||
|
return c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 预设颜色
|
||||||
|
export const PREDEFINE_COLORS = [
|
||||||
|
'#ff4500',
|
||||||
|
'#ff8c00',
|
||||||
|
'#ffd700',
|
||||||
|
'#90ee90',
|
||||||
|
'#00ced1',
|
||||||
|
'#1e90ff',
|
||||||
|
'#c71585',
|
||||||
|
'#409EFF',
|
||||||
|
'#909399',
|
||||||
|
'#C0C4CC',
|
||||||
|
'#b7390b',
|
||||||
|
'#ff7800',
|
||||||
|
'#fad400',
|
||||||
|
'#5b8c5f',
|
||||||
|
'#00babd',
|
||||||
|
'#1f73c3',
|
||||||
|
'#711f57'
|
||||||
|
]
|
||||||
18
src/utils/dateUtil.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Independent time operation tool to facilitate subsequent switch to dayjs
|
||||||
|
*/
|
||||||
|
// TODO 芋艿:【锁屏】可能后面删除掉
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
|
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
|
||||||
|
const DATE_FORMAT = 'YYYY-MM-DD'
|
||||||
|
|
||||||
|
export function formatToDateTime(date?: dayjs.ConfigType, format = DATE_TIME_FORMAT): string {
|
||||||
|
return dayjs(date).format(format)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatToDate(date?: dayjs.ConfigType, format = DATE_FORMAT): string {
|
||||||
|
return dayjs(date).format(format)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const dateUtil = dayjs
|
||||||
452
src/utils/index.ts
Normal file
@@ -0,0 +1,452 @@
|
|||||||
|
import { toNumber } from 'lodash-es'
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param component 需要注册的组件
|
||||||
|
* @param alias 组件别名
|
||||||
|
* @returns any
|
||||||
|
*/
|
||||||
|
export const withInstall = <T>(component: T, alias?: string) => {
|
||||||
|
const comp = component as any
|
||||||
|
comp.install = (app: any) => {
|
||||||
|
app.component(comp.name || comp.displayName, component)
|
||||||
|
if (alias) {
|
||||||
|
app.config.globalProperties[alias] = component
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return component as T & Plugin
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param str 需要转下划线的驼峰字符串
|
||||||
|
* @returns 字符串下划线
|
||||||
|
*/
|
||||||
|
export const humpToUnderline = (str: string): string => {
|
||||||
|
return str.replace(/([A-Z])/g, '-$1').toLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param str 需要转驼峰的下划线字符串
|
||||||
|
* @returns 字符串驼峰
|
||||||
|
*/
|
||||||
|
export const underlineToHump = (str: string): string => {
|
||||||
|
if (!str) return ''
|
||||||
|
return str.replace(/\-(\w)/g, (_, letter: string) => {
|
||||||
|
return letter.toUpperCase()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 驼峰转横杠
|
||||||
|
*/
|
||||||
|
export const humpToDash = (str: string): string => {
|
||||||
|
return str.replace(/([A-Z])/g, '-$1').toLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const setCssVar = (prop: string, val: any, dom = document.documentElement) => {
|
||||||
|
dom.style.setProperty(prop, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找数组对象的某个下标
|
||||||
|
* @param {Array} ary 查找的数组
|
||||||
|
* @param {Functon} fn 判断的方法
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line
|
||||||
|
export const findIndex = <T = Recordable>(ary: Array<T>, fn: Fn): number => {
|
||||||
|
if (ary.findIndex) {
|
||||||
|
return ary.findIndex(fn)
|
||||||
|
}
|
||||||
|
let index = -1
|
||||||
|
ary.some((item: T, i: number, ary: Array<T>) => {
|
||||||
|
const ret: T = fn(item, i, ary)
|
||||||
|
if (ret) {
|
||||||
|
index = i
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
|
||||||
|
export const trim = (str: string) => {
|
||||||
|
return str.replace(/(^\s*)|(\s*$)/g, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Date | number | string} time 需要转换的时间
|
||||||
|
* @param {String} fmt 需要转换的格式 如 yyyy-MM-dd、yyyy-MM-dd HH:mm:ss
|
||||||
|
*/
|
||||||
|
export function formatTime(time: Date | number | string, fmt: string) {
|
||||||
|
if (!time) return ''
|
||||||
|
else {
|
||||||
|
const date = new Date(time)
|
||||||
|
const o = {
|
||||||
|
'M+': date.getMonth() + 1,
|
||||||
|
'd+': date.getDate(),
|
||||||
|
'H+': date.getHours(),
|
||||||
|
'm+': date.getMinutes(),
|
||||||
|
's+': date.getSeconds(),
|
||||||
|
'q+': Math.floor((date.getMonth() + 3) / 3),
|
||||||
|
S: date.getMilliseconds()
|
||||||
|
}
|
||||||
|
if (/(y+)/.test(fmt)) {
|
||||||
|
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
|
||||||
|
}
|
||||||
|
for (const k in o) {
|
||||||
|
if (new RegExp('(' + k + ')').test(fmt)) {
|
||||||
|
fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fmt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成随机字符串
|
||||||
|
*/
|
||||||
|
export function toAnyString() {
|
||||||
|
const str: string = 'xxxxx-xxxxx-4xxxx-yxxxx-xxxxx'.replace(/[xy]/g, (c: string) => {
|
||||||
|
const r: number = (Math.random() * 16) | 0
|
||||||
|
const v: number = c === 'x' ? r : (r & 0x3) | 0x8
|
||||||
|
return v.toString()
|
||||||
|
})
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首字母大写
|
||||||
|
*/
|
||||||
|
export function firstUpperCase(str: string) {
|
||||||
|
return str.toLowerCase().replace(/( |^)[a-z]/g, L => L.toUpperCase())
|
||||||
|
}
|
||||||
|
|
||||||
|
export const generateUUID = () => {
|
||||||
|
if (typeof crypto === 'object') {
|
||||||
|
if (typeof crypto.randomUUID === 'function') {
|
||||||
|
return crypto.randomUUID()
|
||||||
|
}
|
||||||
|
if (typeof crypto.getRandomValues === 'function' && typeof Uint8Array === 'function') {
|
||||||
|
const callback = (c: any) => {
|
||||||
|
const num = Number(c)
|
||||||
|
return (num ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (num / 4)))).toString(16)
|
||||||
|
}
|
||||||
|
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let timestamp = new Date().getTime()
|
||||||
|
let performanceNow = (typeof performance !== 'undefined' && performance.now && performance.now() * 1000) || 0
|
||||||
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
||||||
|
let random = Math.random() * 16
|
||||||
|
if (timestamp > 0) {
|
||||||
|
random = (timestamp + random) % 16 | 0
|
||||||
|
timestamp = Math.floor(timestamp / 16)
|
||||||
|
} else {
|
||||||
|
random = (performanceNow + random) % 16 | 0
|
||||||
|
performanceNow = Math.floor(performanceNow / 16)
|
||||||
|
}
|
||||||
|
return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* element plus 的文件大小 Formatter 实现
|
||||||
|
*
|
||||||
|
* @param row 行数据
|
||||||
|
* @param column 字段
|
||||||
|
* @param cellValue 字段值
|
||||||
|
*/
|
||||||
|
// @ts-ignore
|
||||||
|
export const fileSizeFormatter = (row, column, cellValue) => {
|
||||||
|
const fileSize = cellValue
|
||||||
|
const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
||||||
|
const srcSize = parseFloat(fileSize)
|
||||||
|
const index = Math.floor(Math.log(srcSize) / Math.log(1024))
|
||||||
|
const size = srcSize / Math.pow(1024, index)
|
||||||
|
const sizeStr = size.toFixed(2) //保留的小数位数
|
||||||
|
return sizeStr + ' ' + unitArr[index]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将值复制到目标对象,且以目标对象属性为准,例:target: {a:1} source:{a:2,b:3} 结果为:{a:2}
|
||||||
|
* @param target 目标对象
|
||||||
|
* @param source 源对象
|
||||||
|
*/
|
||||||
|
export const copyValueToTarget = (target: any, source: any) => {
|
||||||
|
const newObj = Object.assign({}, target, source)
|
||||||
|
// 删除多余属性
|
||||||
|
Object.keys(newObj).forEach(key => {
|
||||||
|
// 如果不是target中的属性则删除
|
||||||
|
if (Object.keys(target).indexOf(key) === -1) {
|
||||||
|
delete newObj[key]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 更新目标对象值
|
||||||
|
Object.assign(target, newObj)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取链接的参数值
|
||||||
|
* @param key 参数键名
|
||||||
|
* @param urlStr 链接地址,默认为当前浏览器的地址
|
||||||
|
*/
|
||||||
|
export const getUrlValue = (key: string, urlStr: string = location.href): string => {
|
||||||
|
if (!urlStr || !key) return ''
|
||||||
|
const url = new URL(decodeURIComponent(urlStr))
|
||||||
|
return url.searchParams.get(key) ?? ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取链接的参数值(值类型)
|
||||||
|
* @param key 参数键名
|
||||||
|
* @param urlStr 链接地址,默认为当前浏览器的地址
|
||||||
|
*/
|
||||||
|
export const getUrlNumberValue = (key: string, urlStr: string = location.href): number => {
|
||||||
|
return toNumber(getUrlValue(key, urlStr))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建排序字段
|
||||||
|
* @param prop 字段名称
|
||||||
|
* @param order 顺序
|
||||||
|
*/
|
||||||
|
export const buildSortingField = ({ prop, order }) => {
|
||||||
|
return { field: prop, order: order === 'ascending' ? 'asc' : 'desc' }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== NumberUtils 数字方法 ==========
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数组求和
|
||||||
|
*
|
||||||
|
* @param values 数字数组
|
||||||
|
* @return 求和结果,默认为 0
|
||||||
|
*/
|
||||||
|
export const getSumValue = (values: number[]): number => {
|
||||||
|
return values.reduce((prev, curr) => {
|
||||||
|
const value = Number(curr)
|
||||||
|
if (!Number.isNaN(value)) {
|
||||||
|
return prev + curr
|
||||||
|
} else {
|
||||||
|
return prev
|
||||||
|
}
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 通用金额方法 ==========
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将一个整数转换为分数保留两位小数
|
||||||
|
* @param num
|
||||||
|
*/
|
||||||
|
export const formatToFraction = (num: number | string | undefined): string => {
|
||||||
|
if (typeof num === 'undefined') return '0.00'
|
||||||
|
const parsedNumber = typeof num === 'string' ? parseFloat(num) : num
|
||||||
|
return (parsedNumber / 100.0).toFixed(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将一个数转换为 1.00 这样
|
||||||
|
* 数据呈现的时候使用
|
||||||
|
*
|
||||||
|
* @param num 整数
|
||||||
|
*/
|
||||||
|
// TODO @芋艿:看看怎么融合掉
|
||||||
|
export const floatToFixed2 = (num: number | string | undefined): string => {
|
||||||
|
let str = '0.00'
|
||||||
|
if (typeof num === 'undefined') {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
const f = formatToFraction(num)
|
||||||
|
const decimalPart = f.toString().split('.')[1]
|
||||||
|
const len = decimalPart ? decimalPart.length : 0
|
||||||
|
switch (len) {
|
||||||
|
case 0:
|
||||||
|
str = f.toString() + '.00'
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
str = f.toString() + '0'
|
||||||
|
break
|
||||||
|
case 2:
|
||||||
|
str = f.toString()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将一个分数转换为整数
|
||||||
|
* @param num
|
||||||
|
*/
|
||||||
|
// TODO @芋艿:看看怎么融合掉
|
||||||
|
export const convertToInteger = (num: number | string | undefined): number => {
|
||||||
|
if (typeof num === 'undefined') return 0
|
||||||
|
const parsedNumber = typeof num === 'string' ? parseFloat(num) : num
|
||||||
|
// TODO 分转元后还有小数则四舍五入
|
||||||
|
return Math.round(parsedNumber * 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 元转分
|
||||||
|
*/
|
||||||
|
export const yuanToFen = (amount: string | number): number => {
|
||||||
|
return convertToInteger(amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分转元
|
||||||
|
*/
|
||||||
|
export const fenToYuan = (price: string | number): string => {
|
||||||
|
return formatToFraction(price)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算环比
|
||||||
|
*
|
||||||
|
* @param value 当前数值
|
||||||
|
* @param reference 对比数值
|
||||||
|
*/
|
||||||
|
export const calculateRelativeRate = (value?: number, reference?: number) => {
|
||||||
|
// 防止除0
|
||||||
|
if (!reference) return 0
|
||||||
|
|
||||||
|
return ((100 * ((value || 0) - reference)) / reference).toFixed(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== ERP 专属方法 ==========
|
||||||
|
|
||||||
|
const ERP_COUNT_DIGIT = 3
|
||||||
|
const ERP_PRICE_DIGIT = 2
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【ERP】格式化 Input 数字
|
||||||
|
*
|
||||||
|
* 例如说:库存数量
|
||||||
|
*
|
||||||
|
* @param num 数量
|
||||||
|
* @package digit 保留的小数位数
|
||||||
|
* @return 格式化后的数量
|
||||||
|
*/
|
||||||
|
export const erpNumberFormatter = (num: number | string | undefined, digit: number) => {
|
||||||
|
if (num == null) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
if (typeof num === 'string') {
|
||||||
|
num = parseFloat(num)
|
||||||
|
}
|
||||||
|
// 如果非 number,则直接返回空串
|
||||||
|
if (isNaN(num)) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
return num.toFixed(digit)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【ERP】格式化数量,保留三位小数
|
||||||
|
*
|
||||||
|
* 例如说:库存数量
|
||||||
|
*
|
||||||
|
* @param num 数量
|
||||||
|
* @return 格式化后的数量
|
||||||
|
*/
|
||||||
|
export const erpCountInputFormatter = (num: number | string | undefined) => {
|
||||||
|
return erpNumberFormatter(num, ERP_COUNT_DIGIT)
|
||||||
|
}
|
||||||
|
|
||||||
|
// noinspection JSCommentMatchesSignature
|
||||||
|
/**
|
||||||
|
* 【ERP】格式化数量,保留三位小数
|
||||||
|
*
|
||||||
|
* @param cellValue 数量
|
||||||
|
* @return 格式化后的数量
|
||||||
|
*/
|
||||||
|
export const erpCountTableColumnFormatter = (_, __, cellValue: any, ___) => {
|
||||||
|
return erpNumberFormatter(cellValue, ERP_COUNT_DIGIT)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【ERP】格式化金额,保留二位小数
|
||||||
|
*
|
||||||
|
* 例如说:库存数量
|
||||||
|
*
|
||||||
|
* @param num 数量
|
||||||
|
* @return 格式化后的数量
|
||||||
|
*/
|
||||||
|
export const erpPriceInputFormatter = (num: number | string | undefined) => {
|
||||||
|
return erpNumberFormatter(num, ERP_PRICE_DIGIT)
|
||||||
|
}
|
||||||
|
|
||||||
|
// noinspection JSCommentMatchesSignature
|
||||||
|
/**
|
||||||
|
* 【ERP】格式化金额,保留二位小数
|
||||||
|
*
|
||||||
|
* @param cellValue 数量
|
||||||
|
* @return 格式化后的数量
|
||||||
|
*/
|
||||||
|
export const erpPriceTableColumnFormatter = (_, __, cellValue: any, ___) => {
|
||||||
|
return erpNumberFormatter(cellValue, ERP_PRICE_DIGIT)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【ERP】价格计算,四舍五入保留两位小数
|
||||||
|
*
|
||||||
|
* @param price 价格
|
||||||
|
* @param count 数量
|
||||||
|
* @return 总价格。如果有任一为空,则返回 undefined
|
||||||
|
*/
|
||||||
|
export const erpPriceMultiply = (price: number, count: number) => {
|
||||||
|
if (price == null || count == null) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
return parseFloat((price * count).toFixed(ERP_PRICE_DIGIT))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【ERP】百分比计算,四舍五入保留两位小数
|
||||||
|
*
|
||||||
|
* 如果 total 为 0,则返回 0
|
||||||
|
*
|
||||||
|
* @param value 当前值
|
||||||
|
* @param total 总值
|
||||||
|
*/
|
||||||
|
export const erpCalculatePercentage = (value: number, total: number) => {
|
||||||
|
if (total === 0) return 0
|
||||||
|
return ((value / total) * 100).toFixed(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 适配 echarts map 的地名
|
||||||
|
*
|
||||||
|
* @param areaName 地区名称
|
||||||
|
*/
|
||||||
|
export const areaReplace = (areaName: string) => {
|
||||||
|
if (!areaName) {
|
||||||
|
return areaName
|
||||||
|
}
|
||||||
|
return areaName
|
||||||
|
.replace('维吾尔自治区', '')
|
||||||
|
.replace('壮族自治区', '')
|
||||||
|
.replace('回族自治区', '')
|
||||||
|
.replace('自治区', '')
|
||||||
|
.replace('省', '')
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* bes64解密函数
|
||||||
|
*
|
||||||
|
* @param areaName 地区名称
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
export const decryptFromBase64 = (base64Str: string) => {
|
||||||
|
try {
|
||||||
|
const binaryStr = atob(base64Str)
|
||||||
|
const encodedStr = binaryStr
|
||||||
|
.split('')
|
||||||
|
.map(char => {
|
||||||
|
return '%' + ('00' + char.charCodeAt(0).toString(16)).slice(-2)
|
||||||
|
})
|
||||||
|
.join('')
|
||||||
|
return decodeURIComponent(encodedStr)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('解密出错:', error)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
117
src/utils/is.ts
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
// copy to vben-admin
|
||||||
|
|
||||||
|
const toString = Object.prototype.toString
|
||||||
|
|
||||||
|
export const is = (val: unknown, type: string) => {
|
||||||
|
return toString.call(val) === `[object ${type}]`
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isDef = <T = unknown>(val?: T): val is T => {
|
||||||
|
return typeof val !== 'undefined'
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isUnDef = <T = unknown>(val?: T): val is T => {
|
||||||
|
return !isDef(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isObject = (val: any): val is Record<any, any> => {
|
||||||
|
return val !== null && is(val, 'Object')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isEmpty = <T = unknown>(val: T): val is T => {
|
||||||
|
if (val === null) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (isArray(val) || isString(val)) {
|
||||||
|
return val.length === 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val instanceof Map || val instanceof Set) {
|
||||||
|
return val.size === 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isObject(val)) {
|
||||||
|
return Object.keys(val).length === 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isDate = (val: unknown): val is Date => {
|
||||||
|
return is(val, 'Date')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isNull = (val: unknown): val is null => {
|
||||||
|
return val === null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isNullAndUnDef = (val: unknown): val is null | undefined => {
|
||||||
|
return isUnDef(val) && isNull(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isNullOrUnDef = (val: unknown): val is null | undefined => {
|
||||||
|
return isUnDef(val) || isNull(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isNumber = (val: unknown): val is number => {
|
||||||
|
return is(val, 'Number')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isPromise = <T = any>(val: unknown): val is Promise<T> => {
|
||||||
|
return is(val, 'Promise') && isObject(val) && isFunction(val.then) && isFunction(val.catch)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isString = (val: unknown): val is string => {
|
||||||
|
return is(val, 'String')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isFunction = (val: unknown): val is Function => {
|
||||||
|
return typeof val === 'function'
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isBoolean = (val: unknown): val is boolean => {
|
||||||
|
return is(val, 'Boolean')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isRegExp = (val: unknown): val is RegExp => {
|
||||||
|
return is(val, 'RegExp')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isArray = (val: any): val is Array<any> => {
|
||||||
|
return val && Array.isArray(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isWindow = (val: any): val is Window => {
|
||||||
|
return typeof window !== 'undefined' && is(val, 'Window')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isElement = (val: unknown): val is Element => {
|
||||||
|
return isObject(val) && !!val.tagName
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isMap = (val: unknown): val is Map<any, any> => {
|
||||||
|
return is(val, 'Map')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isServer = typeof window === 'undefined'
|
||||||
|
|
||||||
|
export const isClient = !isServer
|
||||||
|
|
||||||
|
export const isUrl = (path: string): boolean => {
|
||||||
|
const reg =
|
||||||
|
/(((^https?:(?:\/\/)?)(?:[-:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&%@.\w_]*)#?(?:[\w]*))?)$/
|
||||||
|
return reg.test(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isDark = (): boolean => {
|
||||||
|
return window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否是图片链接
|
||||||
|
export const isImgPath = (path: string): boolean => {
|
||||||
|
return /(https?:\/\/|data:image\/).*?\.(png|jpg|jpeg|gif|svg|webp|ico)/gi.test(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isEmptyVal = (val: any): boolean => {
|
||||||
|
return val === '' || val === null || val === undefined
|
||||||
|
}
|
||||||
31
src/utils/jsencrypt copy.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { JSEncrypt } from 'jsencrypt'
|
||||||
|
|
||||||
|
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
||||||
|
|
||||||
|
const publicKey =
|
||||||
|
'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
|
||||||
|
'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
|
||||||
|
|
||||||
|
const privateKey =
|
||||||
|
'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
|
||||||
|
'7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
|
||||||
|
'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
|
||||||
|
'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
|
||||||
|
'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
|
||||||
|
'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
|
||||||
|
'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
|
||||||
|
'UP8iWi1Qw0Y='
|
||||||
|
|
||||||
|
// 加密
|
||||||
|
export const encrypt = (txt: string) => {
|
||||||
|
const encryptor = new JSEncrypt()
|
||||||
|
encryptor.setPublicKey(publicKey) // 设置公钥
|
||||||
|
return encryptor.encrypt(txt) // 对数据进行加密
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解密
|
||||||
|
export const decrypt = (txt: string) => {
|
||||||
|
const encryptor = new JSEncrypt()
|
||||||
|
encryptor.setPrivateKey(privateKey) // 设置私钥
|
||||||
|
return encryptor.decrypt(txt) // 对数据进行解密
|
||||||
|
}
|
||||||
31
src/utils/jsencrypt.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { JSEncrypt } from 'jsencrypt'
|
||||||
|
|
||||||
|
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
||||||
|
|
||||||
|
const publicKey =
|
||||||
|
'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
|
||||||
|
'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
|
||||||
|
|
||||||
|
const privateKey =
|
||||||
|
'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
|
||||||
|
'7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
|
||||||
|
'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
|
||||||
|
'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
|
||||||
|
'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
|
||||||
|
'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
|
||||||
|
'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
|
||||||
|
'UP8iWi1Qw0Y='
|
||||||
|
|
||||||
|
// 加密
|
||||||
|
export const encrypt = (txt: string) => {
|
||||||
|
const encryptor = new JSEncrypt()
|
||||||
|
encryptor.setPublicKey(publicKey) // 设置公钥
|
||||||
|
return encryptor.encrypt(txt) // 对数据进行加密
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解密
|
||||||
|
export const decrypt = (txt: string) => {
|
||||||
|
const encryptor = new JSEncrypt()
|
||||||
|
encryptor.setPrivateKey(privateKey) // 设置私钥
|
||||||
|
return encryptor.decrypt(txt) // 对数据进行解密
|
||||||
|
}
|
||||||
253
src/utils/routerHelper.ts
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
import type { RouteLocationNormalized, Router, RouteRecordNormalized } from 'vue-router'
|
||||||
|
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
|
||||||
|
import { isUrl } from '@/utils/is'
|
||||||
|
import { cloneDeep, omit } from 'lodash-es'
|
||||||
|
import qs from 'qs'
|
||||||
|
|
||||||
|
const modules = import.meta.glob('../views/**/*.{vue,tsx}')
|
||||||
|
/**
|
||||||
|
* 注册一个异步组件
|
||||||
|
* @param componentPath 例:/bpm/oa/leave/detail
|
||||||
|
*/
|
||||||
|
export const registerComponent = (componentPath: string) => {
|
||||||
|
for (const item in modules) {
|
||||||
|
if (item.includes(componentPath)) {
|
||||||
|
// 使用异步组件的方式来动态加载组件
|
||||||
|
// @ts-ignore
|
||||||
|
return defineAsyncComponent(modules[item])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Layout */
|
||||||
|
export const Layout = () => import('@/layouts/Layout.vue')
|
||||||
|
|
||||||
|
export const getParentLayout = () => {
|
||||||
|
return () =>
|
||||||
|
new Promise((resolve) => {
|
||||||
|
resolve({
|
||||||
|
name: 'ParentLayout'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按照路由中meta下的rank等级升序来排序路由
|
||||||
|
export const ascending = (arr: any[]) => {
|
||||||
|
arr.forEach((v) => {
|
||||||
|
if (v?.meta?.rank === null) v.meta.rank = undefined
|
||||||
|
if (v?.meta?.rank === 0) {
|
||||||
|
if (v.name !== 'home' && v.path !== '/') {
|
||||||
|
console.warn('rank only the home page can be 0')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return arr.sort((a: { meta: { rank: number } }, b: { meta: { rank: number } }) => {
|
||||||
|
return a?.meta?.rank - b?.meta?.rank
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getRawRoute = (route: RouteLocationNormalized): RouteLocationNormalized => {
|
||||||
|
if (!route) return route
|
||||||
|
const { matched, ...opt } = route
|
||||||
|
return {
|
||||||
|
...opt,
|
||||||
|
matched: (matched
|
||||||
|
? matched.map((item) => ({
|
||||||
|
meta: item.meta,
|
||||||
|
name: item.name,
|
||||||
|
path: item.path
|
||||||
|
}))
|
||||||
|
: undefined) as RouteRecordNormalized[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 后端控制路由生成
|
||||||
|
export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecordRaw[] => {
|
||||||
|
const res: AppRouteRecordRaw[] = []
|
||||||
|
const modulesRoutesKeys = Object.keys(modules)
|
||||||
|
for (const route of routes) {
|
||||||
|
// 1. 生成 meta 菜单元数据
|
||||||
|
const meta = {
|
||||||
|
title: route.name,
|
||||||
|
icon: route.icon,
|
||||||
|
hidden: !route.visible,
|
||||||
|
noCache: !route.keepAlive,
|
||||||
|
alwaysShow:
|
||||||
|
route.children &&
|
||||||
|
route.children.length === 1 &&
|
||||||
|
(route.alwaysShow !== undefined ? route.alwaysShow : true)
|
||||||
|
} as any
|
||||||
|
// 特殊逻辑:如果后端配置的 MenuDO.component 包含 ?,则表示需要传递参数
|
||||||
|
// 此时,我们需要解析参数,并且将参数放到 meta.query 中
|
||||||
|
// 这样,后续在 Vue 文件中,可以通过 const { currentRoute } = useRouter() 中,通过 meta.query 获取到参数
|
||||||
|
if (route.component && route.component.indexOf('?') > -1) {
|
||||||
|
const query = route.component.split('?')[1]
|
||||||
|
route.component = route.component.split('?')[0]
|
||||||
|
meta.query = qs.parse(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 生成 data(AppRouteRecordRaw)
|
||||||
|
// 路由地址转首字母大写驼峰,作为路由名称,适配keepAlive
|
||||||
|
let data: AppRouteRecordRaw = {
|
||||||
|
path: route.path.indexOf('?') > -1 ? route.path.split('?')[0] : route.path,
|
||||||
|
name:
|
||||||
|
route.componentName && route.componentName.length > 0
|
||||||
|
? route.componentName
|
||||||
|
: toCamelCase(route.path, true),
|
||||||
|
redirect: route.redirect,
|
||||||
|
meta: meta
|
||||||
|
}
|
||||||
|
//处理顶级非目录路由
|
||||||
|
if (!route.children && route.parentId == 0 && route.component) {
|
||||||
|
data.component = Layout
|
||||||
|
data.meta = {}
|
||||||
|
data.name = toCamelCase(route.path, true) + 'Parent'
|
||||||
|
data.redirect = ''
|
||||||
|
meta.alwaysShow = true
|
||||||
|
const childrenData: AppRouteRecordRaw = {
|
||||||
|
path: '',
|
||||||
|
name:
|
||||||
|
route.componentName && route.componentName.length > 0
|
||||||
|
? route.componentName
|
||||||
|
: toCamelCase(route.path, true),
|
||||||
|
redirect: route.redirect,
|
||||||
|
meta: meta
|
||||||
|
}
|
||||||
|
const index = route?.component
|
||||||
|
? modulesRoutesKeys.findIndex((ev) => ev.includes(route.component))
|
||||||
|
: modulesRoutesKeys.findIndex((ev) => ev.includes(route.path))
|
||||||
|
childrenData.component = modules[modulesRoutesKeys[index]]
|
||||||
|
data.children = [childrenData]
|
||||||
|
} else {
|
||||||
|
// 目录
|
||||||
|
if (route.children) {
|
||||||
|
data.component = Layout
|
||||||
|
data.redirect = getRedirect(route.path, route.children)
|
||||||
|
// 外链
|
||||||
|
} else if (isUrl(route.path)) {
|
||||||
|
data = {
|
||||||
|
path: '/external-link',
|
||||||
|
component: Layout,
|
||||||
|
meta: {
|
||||||
|
name: route.name
|
||||||
|
},
|
||||||
|
children: [data]
|
||||||
|
} as AppRouteRecordRaw
|
||||||
|
// 菜单
|
||||||
|
} else {
|
||||||
|
// 对后端传component组件路径和不传做兼容(如果后端传component组件路径,那么path可以随便写,如果不传,component组件路径会根path保持一致)
|
||||||
|
const index = route?.component
|
||||||
|
? modulesRoutesKeys.findIndex((ev) => ev.includes(route.component))
|
||||||
|
: modulesRoutesKeys.findIndex((ev) => ev.includes(route.path))
|
||||||
|
data.component = modules[modulesRoutesKeys[index]]
|
||||||
|
}
|
||||||
|
if (route.children) {
|
||||||
|
data.children = generateRoute(route.children)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.push(data as AppRouteRecordRaw)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
export const getRedirect = (parentPath: string, children: AppCustomRouteRecordRaw[]) => {
|
||||||
|
if (!children || children.length == 0) {
|
||||||
|
return parentPath
|
||||||
|
}
|
||||||
|
const path = generateRoutePath(parentPath, children[0].path)
|
||||||
|
// 递归子节点
|
||||||
|
if (children[0].children) return getRedirect(path, children[0].children)
|
||||||
|
}
|
||||||
|
const generateRoutePath = (parentPath: string, path: string) => {
|
||||||
|
if (parentPath.endsWith('/')) {
|
||||||
|
parentPath = parentPath.slice(0, -1) // 移除默认的 /
|
||||||
|
}
|
||||||
|
if (!path.startsWith('/')) {
|
||||||
|
path = '/' + path
|
||||||
|
}
|
||||||
|
return parentPath + path
|
||||||
|
}
|
||||||
|
export const pathResolve = (parentPath: string, path: string) => {
|
||||||
|
if (isUrl(path)) return path
|
||||||
|
const childPath = path.startsWith('/') || !path ? path : `/${path}`
|
||||||
|
return `${parentPath}${childPath}`.replace(/\/\//g, '/')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 路由降级
|
||||||
|
export const flatMultiLevelRoutes = (routes: AppRouteRecordRaw[]) => {
|
||||||
|
const modules: AppRouteRecordRaw[] = cloneDeep(routes)
|
||||||
|
for (let index = 0; index < modules.length; index++) {
|
||||||
|
const route = modules[index]
|
||||||
|
if (!isMultipleRoute(route)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
promoteRouteLevel(route)
|
||||||
|
}
|
||||||
|
return modules
|
||||||
|
}
|
||||||
|
|
||||||
|
// 层级是否大于2
|
||||||
|
const isMultipleRoute = (route: AppRouteRecordRaw) => {
|
||||||
|
if (!route || !Reflect.has(route, 'children') || !route.children?.length) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const children = route.children
|
||||||
|
|
||||||
|
let flag = false
|
||||||
|
for (let index = 0; index < children.length; index++) {
|
||||||
|
const child = children[index]
|
||||||
|
if (child.children?.length) {
|
||||||
|
flag = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flag
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成二级路由
|
||||||
|
const promoteRouteLevel = (route: AppRouteRecordRaw) => {
|
||||||
|
let router: Router | null = createRouter({
|
||||||
|
routes: [route as RouteRecordRaw],
|
||||||
|
history: createWebHashHistory()
|
||||||
|
})
|
||||||
|
|
||||||
|
const routes = router.getRoutes()
|
||||||
|
addToChildren(routes, route.children || [], route)
|
||||||
|
router = null
|
||||||
|
|
||||||
|
route.children = route.children?.map((item) => omit(item, 'children'))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加所有子菜单
|
||||||
|
const addToChildren = (
|
||||||
|
routes: RouteRecordNormalized[],
|
||||||
|
children: AppRouteRecordRaw[],
|
||||||
|
routeModule: AppRouteRecordRaw
|
||||||
|
) => {
|
||||||
|
for (let index = 0; index < children.length; index++) {
|
||||||
|
const child = children[index]
|
||||||
|
const route = routes.find((item) => item.name === child.name)
|
||||||
|
if (!route) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
routeModule.children = routeModule.children || []
|
||||||
|
if (!routeModule.children.find((item) => item.name === route.name)) {
|
||||||
|
routeModule.children?.push(route as unknown as AppRouteRecordRaw)
|
||||||
|
}
|
||||||
|
if (child.children?.length) {
|
||||||
|
addToChildren(routes, child.children, routeModule)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const toCamelCase = (str: string, upperCaseFirst: boolean) => {
|
||||||
|
str = (str || '')
|
||||||
|
.replace(/-(.)/g, function (group1: string) {
|
||||||
|
return group1.toUpperCase()
|
||||||
|
})
|
||||||
|
.replaceAll('-', '')
|
||||||
|
|
||||||
|
if (upperCaseFirst && str) {
|
||||||
|
str = str.charAt(0).toUpperCase() + str.slice(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return str
|
||||||
|
}
|
||||||
400
src/utils/tree.ts
Normal file
@@ -0,0 +1,400 @@
|
|||||||
|
interface TreeHelperConfig {
|
||||||
|
id: string
|
||||||
|
children: string
|
||||||
|
pid: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_CONFIG: TreeHelperConfig = {
|
||||||
|
id: 'id',
|
||||||
|
children: 'children',
|
||||||
|
pid: 'pid'
|
||||||
|
}
|
||||||
|
export const defaultProps = {
|
||||||
|
children: 'children',
|
||||||
|
label: 'name',
|
||||||
|
value: 'id',
|
||||||
|
isLeaf: 'leaf',
|
||||||
|
emitPath: false // 用于 cascader 组件:在选中节点改变时,是否返回由该节点所在的各级菜单的值所组成的数组,若设置 false,则只返回该节点的值
|
||||||
|
}
|
||||||
|
|
||||||
|
const getConfig = (config: Partial<TreeHelperConfig>) => Object.assign({}, DEFAULT_CONFIG, config)
|
||||||
|
|
||||||
|
// tree from list
|
||||||
|
export const listToTree = <T = any>(list: any[], config: Partial<TreeHelperConfig> = {}): T[] => {
|
||||||
|
const conf = getConfig(config) as TreeHelperConfig
|
||||||
|
const nodeMap = new Map()
|
||||||
|
const result: T[] = []
|
||||||
|
const { id, children, pid } = conf
|
||||||
|
|
||||||
|
for (const node of list) {
|
||||||
|
node[children] = node[children] || []
|
||||||
|
nodeMap.set(node[id], node)
|
||||||
|
}
|
||||||
|
for (const node of list) {
|
||||||
|
const parent = nodeMap.get(node[pid])
|
||||||
|
;(parent ? parent.children : result).push(node)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export const treeToList = <T = any>(tree: any, config: Partial<TreeHelperConfig> = {}): T => {
|
||||||
|
config = getConfig(config)
|
||||||
|
const { children } = config
|
||||||
|
const result: any = [...tree]
|
||||||
|
for (let i = 0; i < result.length; i++) {
|
||||||
|
if (!result[i][children!]) continue
|
||||||
|
result.splice(i + 1, 0, ...result[i][children!])
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export const findNode = <T = any>(
|
||||||
|
tree: any,
|
||||||
|
func: Fn,
|
||||||
|
config: Partial<TreeHelperConfig> = {}
|
||||||
|
): T | null => {
|
||||||
|
config = getConfig(config)
|
||||||
|
const { children } = config
|
||||||
|
const list = [...tree]
|
||||||
|
for (const node of list) {
|
||||||
|
if (func(node)) return node
|
||||||
|
node[children!] && list.push(...node[children!])
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const findNodeAll = <T = any>(
|
||||||
|
tree: any,
|
||||||
|
func: Fn,
|
||||||
|
config: Partial<TreeHelperConfig> = {}
|
||||||
|
): T[] => {
|
||||||
|
config = getConfig(config)
|
||||||
|
const { children } = config
|
||||||
|
const list = [...tree]
|
||||||
|
const result: T[] = []
|
||||||
|
for (const node of list) {
|
||||||
|
func(node) && result.push(node)
|
||||||
|
node[children!] && list.push(...node[children!])
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export const findPath = <T = any>(
|
||||||
|
tree: any,
|
||||||
|
func: Fn,
|
||||||
|
config: Partial<TreeHelperConfig> = {}
|
||||||
|
): T | T[] | null => {
|
||||||
|
config = getConfig(config)
|
||||||
|
const path: T[] = []
|
||||||
|
const list = [...tree]
|
||||||
|
const visitedSet = new Set()
|
||||||
|
const { children } = config
|
||||||
|
while (list.length) {
|
||||||
|
const node = list[0]
|
||||||
|
if (visitedSet.has(node)) {
|
||||||
|
path.pop()
|
||||||
|
list.shift()
|
||||||
|
} else {
|
||||||
|
visitedSet.add(node)
|
||||||
|
node[children!] && list.unshift(...node[children!])
|
||||||
|
path.push(node)
|
||||||
|
if (func(node)) {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const findPathAll = (tree: any, func: Fn, config: Partial<TreeHelperConfig> = {}) => {
|
||||||
|
config = getConfig(config)
|
||||||
|
const path: any[] = []
|
||||||
|
const list = [...tree]
|
||||||
|
const result: any[] = []
|
||||||
|
const visitedSet = new Set(),
|
||||||
|
{ children } = config
|
||||||
|
while (list.length) {
|
||||||
|
const node = list[0]
|
||||||
|
if (visitedSet.has(node)) {
|
||||||
|
path.pop()
|
||||||
|
list.shift()
|
||||||
|
} else {
|
||||||
|
visitedSet.add(node)
|
||||||
|
node[children!] && list.unshift(...node[children!])
|
||||||
|
path.push(node)
|
||||||
|
func(node) && result.push([...path])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export const filter = <T = any>(
|
||||||
|
tree: T[],
|
||||||
|
func: (n: T) => boolean,
|
||||||
|
config: Partial<TreeHelperConfig> = {}
|
||||||
|
): T[] => {
|
||||||
|
config = getConfig(config)
|
||||||
|
const children = config.children as string
|
||||||
|
|
||||||
|
function listFilter(list: T[]) {
|
||||||
|
return list
|
||||||
|
.map((node: any) => ({ ...node }))
|
||||||
|
.filter((node) => {
|
||||||
|
node[children] = node[children] && listFilter(node[children])
|
||||||
|
return func(node) || (node[children] && node[children].length)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return listFilter(tree)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const forEach = <T = any>(
|
||||||
|
tree: T[],
|
||||||
|
func: (n: T) => any,
|
||||||
|
config: Partial<TreeHelperConfig> = {}
|
||||||
|
): void => {
|
||||||
|
config = getConfig(config)
|
||||||
|
const list: any[] = [...tree]
|
||||||
|
const { children } = config
|
||||||
|
for (let i = 0; i < list.length; i++) {
|
||||||
|
// func 返回true就终止遍历,避免大量节点场景下无意义循环,引起浏览器卡顿
|
||||||
|
if (func(list[i])) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
children && list[i][children] && list.splice(i + 1, 0, ...list[i][children])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Extract tree specified structure
|
||||||
|
*/
|
||||||
|
export const treeMap = <T = any>(
|
||||||
|
treeData: T[],
|
||||||
|
opt: { children?: string; conversion: Fn }
|
||||||
|
): T[] => {
|
||||||
|
return treeData.map((item) => treeMapEach(item, opt))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Extract tree specified structure
|
||||||
|
*/
|
||||||
|
export const treeMapEach = (
|
||||||
|
data: any,
|
||||||
|
{ children = 'children', conversion }: { children?: string; conversion: Fn }
|
||||||
|
) => {
|
||||||
|
const haveChildren = Array.isArray(data[children]) && data[children].length > 0
|
||||||
|
const conversionData = conversion(data) || {}
|
||||||
|
if (haveChildren) {
|
||||||
|
return {
|
||||||
|
...conversionData,
|
||||||
|
[children]: data[children].map((i: number) =>
|
||||||
|
treeMapEach(i, {
|
||||||
|
children,
|
||||||
|
conversion
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
...conversionData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归遍历树结构
|
||||||
|
* @param treeDatas 树
|
||||||
|
* @param callBack 回调
|
||||||
|
* @param parentNode 父节点
|
||||||
|
*/
|
||||||
|
export const eachTree = (treeDatas: any[], callBack: Fn, parentNode = {}) => {
|
||||||
|
treeDatas.forEach((element) => {
|
||||||
|
const newNode = callBack(element, parentNode) || element
|
||||||
|
if (element.children) {
|
||||||
|
eachTree(element.children, callBack, newNode)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造树型结构数据
|
||||||
|
* @param {*} data 数据源
|
||||||
|
* @param {*} id id字段 默认 'id'
|
||||||
|
* @param {*} parentId 父节点字段 默认 'parentId'
|
||||||
|
* @param {*} children 孩子节点字段 默认 'children'
|
||||||
|
*/
|
||||||
|
export const handleTree = (data: any[], id?: string, parentId?: string, children?: string) => {
|
||||||
|
if (!Array.isArray(data)) {
|
||||||
|
console.warn('data must be an array')
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
const config = {
|
||||||
|
id: id || 'id',
|
||||||
|
parentId: parentId || 'parentId',
|
||||||
|
childrenList: children || 'children'
|
||||||
|
}
|
||||||
|
|
||||||
|
const childrenListMap = {}
|
||||||
|
const nodeIds = {}
|
||||||
|
const tree: any[] = []
|
||||||
|
|
||||||
|
for (const d of data) {
|
||||||
|
const parentId = d[config.parentId]
|
||||||
|
if (childrenListMap[parentId] == null) {
|
||||||
|
childrenListMap[parentId] = []
|
||||||
|
}
|
||||||
|
nodeIds[d[config.id]] = d
|
||||||
|
childrenListMap[parentId].push(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const d of data) {
|
||||||
|
const parentId = d[config.parentId]
|
||||||
|
if (nodeIds[parentId] == null) {
|
||||||
|
tree.push(d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const t of tree) {
|
||||||
|
adaptToChildrenList(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
function adaptToChildrenList(o) {
|
||||||
|
if (childrenListMap[o[config.id]] !== null) {
|
||||||
|
o[config.childrenList] = childrenListMap[o[config.id]]
|
||||||
|
}
|
||||||
|
if (o[config.childrenList]) {
|
||||||
|
for (const c of o[config.childrenList]) {
|
||||||
|
adaptToChildrenList(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tree
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造树型结构数据
|
||||||
|
* @param {*} data 数据源
|
||||||
|
* @param {*} id id字段 默认 'id'
|
||||||
|
* @param {*} parentId 父节点字段 默认 'parentId'
|
||||||
|
* @param {*} children 孩子节点字段 默认 'children'
|
||||||
|
* @param {*} rootId 根Id 默认 0
|
||||||
|
*/
|
||||||
|
// @ts-ignore
|
||||||
|
export const handleTree2 = (data, id, parentId, children, rootId) => {
|
||||||
|
id = id || 'id'
|
||||||
|
parentId = parentId || 'parentId'
|
||||||
|
// children = children || 'children'
|
||||||
|
rootId =
|
||||||
|
rootId ||
|
||||||
|
Math.min(
|
||||||
|
...data.map((item) => {
|
||||||
|
return item[parentId]
|
||||||
|
})
|
||||||
|
) ||
|
||||||
|
0
|
||||||
|
// 对源数据深度克隆
|
||||||
|
const cloneData = JSON.parse(JSON.stringify(data))
|
||||||
|
// 循环所有项
|
||||||
|
const treeData = cloneData.filter((father) => {
|
||||||
|
const branchArr = cloneData.filter((child) => {
|
||||||
|
// 返回每一项的子级数组
|
||||||
|
return father[id] === child[parentId]
|
||||||
|
})
|
||||||
|
branchArr.length > 0 ? (father.children = branchArr) : ''
|
||||||
|
// 返回第一层
|
||||||
|
return father[parentId] === rootId
|
||||||
|
})
|
||||||
|
return treeData !== '' ? treeData : data
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验选中的节点,是否为指定 level
|
||||||
|
*
|
||||||
|
* @param tree 要操作的树结构数据
|
||||||
|
* @param nodeId 需要判断在什么层级的数据
|
||||||
|
* @param level 检查的级别, 默认检查到二级
|
||||||
|
* @return true 是;false 否
|
||||||
|
*/
|
||||||
|
export const checkSelectedNode = (tree: any[], nodeId: any, level = 2): boolean => {
|
||||||
|
if (typeof tree === 'undefined' || !Array.isArray(tree) || tree.length === 0) {
|
||||||
|
console.warn('tree must be an array')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验是否是一级节点
|
||||||
|
if (tree.some((item) => item.id === nodeId)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 递归计数
|
||||||
|
let count = 1
|
||||||
|
|
||||||
|
// 深层次校验
|
||||||
|
function performAThoroughValidation(arr: any[]): boolean {
|
||||||
|
count += 1
|
||||||
|
for (const item of arr) {
|
||||||
|
if (item.id === nodeId) {
|
||||||
|
return true
|
||||||
|
} else if (typeof item.children !== 'undefined' && item.children.length !== 0) {
|
||||||
|
if (performAThoroughValidation(item.children)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const item of tree) {
|
||||||
|
count = 1
|
||||||
|
if (performAThoroughValidation(item.children)) {
|
||||||
|
// 找到后对比是否是期望的层级
|
||||||
|
if (count >= level) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取节点的完整结构
|
||||||
|
* @param tree 树数据
|
||||||
|
* @param nodeId 节点 id
|
||||||
|
*/
|
||||||
|
export const treeToString = (tree: any[], nodeId) => {
|
||||||
|
if (typeof tree === 'undefined' || !Array.isArray(tree) || tree.length === 0) {
|
||||||
|
console.warn('tree must be an array')
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
// 校验是否是一级节点
|
||||||
|
const node = tree.find((item) => item.id === nodeId)
|
||||||
|
if (typeof node !== 'undefined') {
|
||||||
|
return node.name
|
||||||
|
}
|
||||||
|
let str = ''
|
||||||
|
|
||||||
|
function performAThoroughValidation(arr) {
|
||||||
|
for (const item of arr) {
|
||||||
|
if (item.id === nodeId) {
|
||||||
|
str += ` / ${item.name}`
|
||||||
|
return true
|
||||||
|
} else if (typeof item.children !== 'undefined' && item.children.length !== 0) {
|
||||||
|
str += ` / ${item.name}`
|
||||||
|
if (performAThoroughValidation(item.children)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const item of tree) {
|
||||||
|
str = `${item.name}`
|
||||||
|
if (performAThoroughValidation(item.children)) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
@@ -107,8 +107,8 @@ const editd = (e: any) => {
|
|||||||
}
|
}
|
||||||
// 设计
|
// 设计
|
||||||
const Aclick = (e: any) => {
|
const Aclick = (e: any) => {
|
||||||
// window.open(window.location.origin + `/zutai/?id=${e.id}&&name=${e.name}&&preview=false`)
|
// window.open(window.location.origin + `/zutai/?id=${e.id}&&name=${e.name}&&preview=false&&graphicDisplay=zl`)
|
||||||
window.open('http://192.168.1.128:4001' + `/zutai/?id=${e.id}&&name=${e.name}&&preview=false`)
|
window.open('http://192.168.1.128:4001' + `/zutai/?id=${e.id}&&name=${e.name}&&preview=false&&graphicDisplay=zl`)
|
||||||
|
|
||||||
}
|
}
|
||||||
// 删除
|
// 删除
|
||||||
@@ -143,8 +143,8 @@ const deleted = (e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const imgData = (e: any) => {
|
const imgData = (e: any) => {
|
||||||
// window.open(window.location.origin + `/zutai/?id=${e.id}&&name=${e.name}&&preview=true#/preview`)
|
// window.open(window.location.origin + `/zutai/?id=${e.id}&&name=${e.name}&&preview=true&&graphicDisplay=zl#/preview`)
|
||||||
window.open('http://192.168.1.128:4001' + `/zutai/?id=${e.id}&&name=${e.name}&&preview=true#/preview`)
|
window.open('http://192.168.1.128:4001' + `/zutai/?id=${e.id}&&name=${e.name}&&preview=true&&graphicDisplay=zl#/preview`)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,48 +1,63 @@
|
|||||||
<template>
|
<template>
|
||||||
<GridLayout
|
<div class="default-main">
|
||||||
class="default-main"
|
<TableHeader :showSearch="false">
|
||||||
v-model:layout="layout"
|
<template v-slot:select>
|
||||||
:row-height="rowHeight"
|
<el-form-item label="日期">
|
||||||
:is-resizable="false"
|
<DatePicker ref="datePickerRef" :nextFlag="false" :theCurrentTime="true"></DatePicker>
|
||||||
:is-draggable="false"
|
</el-form-item>
|
||||||
:responsive="false"
|
</template>
|
||||||
:vertical-compact="false"
|
</TableHeader>
|
||||||
prevent-collision
|
<GridLayout
|
||||||
:col-num="12"
|
v-model:layout="layout"
|
||||||
>
|
:row-height="rowHeight"
|
||||||
<template #item="{ item }">
|
:is-resizable="false"
|
||||||
<div class="box">
|
:is-draggable="false"
|
||||||
<div class="title">
|
:responsive="false"
|
||||||
<div style="display: flex; align-items: center">
|
:vertical-compact="false"
|
||||||
<Icon class="HelpFilled" :name="item.icon" />
|
prevent-collision
|
||||||
{{ item.name }}
|
:col-num="12"
|
||||||
|
>
|
||||||
|
<template #item="{ item }">
|
||||||
|
<div class="box">
|
||||||
|
<div class="title">
|
||||||
|
<div style="display: flex; align-items: center">
|
||||||
|
<Icon class="HelpFilled" :name="item.icon" />
|
||||||
|
{{ item.name }}
|
||||||
|
</div>
|
||||||
|
<!-- <FullScreen class="HelpFilled" style="cursor: pointer" @click="zoom(item)" /> -->
|
||||||
|
<img :src="flag ? img : img1" style="cursor: pointer; height: 16px" @click="zoom(item)" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<component
|
||||||
|
:is="item.component"
|
||||||
|
v-if="item.component"
|
||||||
|
class="pd10"
|
||||||
|
:key="key"
|
||||||
|
:timeValue="datePickerRef.timeValue"
|
||||||
|
:height="rowHeight * item.h - seRowHeight(item.h) + 'px'"
|
||||||
|
:width="rowWidth * item.w - 30 + 'px'"
|
||||||
|
:timeKey="item.timeKey"
|
||||||
|
/>
|
||||||
|
<div v-else class="pd10">组件加载失败...</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- <FullScreen class="HelpFilled" style="cursor: pointer" @click="zoom(item)" /> -->
|
|
||||||
<img :src="flag ? img : img1" style="cursor: pointer; height: 16px" @click="zoom(item)" />
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
</template>
|
||||||
<component
|
</GridLayout>
|
||||||
:is="item.component"
|
</div>
|
||||||
v-if="item.component"
|
|
||||||
class="pd10"
|
|
||||||
:key="key"
|
|
||||||
:height="rowHeight * item.h - (item.h == 6 ? -20 : item.h == 2 ? 20 : 5) + 'px'"
|
|
||||||
:width="rowWidth * item.w - 5 + 'px'"
|
|
||||||
:timeKey="item.timeKey"
|
|
||||||
/>
|
|
||||||
<div v-else class="pd10">组件加载失败...</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</GridLayout>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted, markRaw, onUnmounted, defineAsyncComponent, type Component } from 'vue'
|
import { ref, reactive, onMounted, markRaw, onUnmounted, defineAsyncComponent, type Component } from 'vue'
|
||||||
|
import TableHeader from '@/components/table/header/index.vue'
|
||||||
import { GridLayout } from 'grid-layout-plus'
|
import { GridLayout } from 'grid-layout-plus'
|
||||||
|
import DatePicker from '@/components/form/datePicker/index.vue'
|
||||||
import { useDebounceFn } from '@vueuse/core'
|
import { useDebounceFn } from '@vueuse/core'
|
||||||
import { queryActivatePage } from '@/api/system-boot/csstatisticalset'
|
import { queryActivatePage, queryByPagePath } from '@/api/system-boot/csstatisticalset'
|
||||||
import { HelpFilled, FullScreen } from '@element-plus/icons-vue'
|
import { HelpFilled, FullScreen } from '@element-plus/icons-vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
const datePickerRef = ref()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
// defineOptions({
|
// defineOptions({
|
||||||
// name: 'cockpit/homePage'
|
// name: 'cockpit/homePage'
|
||||||
// })
|
// })
|
||||||
@@ -94,7 +109,7 @@ const getMainWidth = () => {
|
|||||||
|
|
||||||
// 初始化行高
|
// 初始化行高
|
||||||
const initRowHeight = () => {
|
const initRowHeight = () => {
|
||||||
rowHeight.value = Math.max(0, (getMainHeight() - 20) / 6)
|
rowHeight.value = Math.max(0, (getMainHeight() - 72) / 6)
|
||||||
rowWidth.value = Math.max(0, getMainWidth() / 12)
|
rowWidth.value = Math.max(0, getMainWidth() / 12)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,10 +162,21 @@ const zoom = (value: any) => {
|
|||||||
flag.value = !flag.value
|
flag.value = !flag.value
|
||||||
key.value += 1
|
key.value += 1
|
||||||
}
|
}
|
||||||
|
// 计算组件高度
|
||||||
|
const seRowHeight = (value: any) => {
|
||||||
|
if (value == 6) return 0
|
||||||
|
if (value == 5) return 12
|
||||||
|
if (value == 4) return 20
|
||||||
|
if (value == 3) return 30
|
||||||
|
if (value == 2) return 40
|
||||||
|
if (value == 1) return 50
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
// 获取布局数据
|
// 获取布局数据
|
||||||
const fetchLayoutData = async () => {
|
const fetchLayoutData = async () => {
|
||||||
try {
|
try {
|
||||||
const { data } = await queryActivatePage()
|
const { data } = await queryByPagePath({ pagePath: router.currentRoute.value.name })
|
||||||
const parsedLayout = JSON.parse(data.containerConfig || '[]') as LayoutItem[]
|
const parsedLayout = JSON.parse(data.containerConfig || '[]') as LayoutItem[]
|
||||||
// 处理布局数据
|
// 处理布局数据
|
||||||
layout.value = parsedLayout.map((item, index) => ({
|
layout.value = parsedLayout.map((item, index) => ({
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<!-- 实时数据 -->
|
<!-- 实时数据 -->
|
||||||
<div> </div>
|
<div>123</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
<script setup lang='ts'>
|
<script setup lang="ts">
|
||||||
import { ref, reactive } from 'vue'
|
import { ref, reactive } from 'vue'
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped></style>
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -19,9 +19,13 @@
|
|||||||
:min="0"
|
:min="0"
|
||||||
:step="1"
|
:step="1"
|
||||||
step-strictly
|
step-strictly
|
||||||
style="width: 100%"
|
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="绑定页面">
|
||||||
|
<el-select v-model="form.pagePath" filterable placeholder="请选择绑定页面" style="width: 100%" clearable>
|
||||||
|
<el-option v-for="item in pageList" :key="item.path" :label="item.name" :value="item.path" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="备注" class="top">
|
<el-form-item label="备注" class="top">
|
||||||
<el-input
|
<el-input
|
||||||
@@ -131,14 +135,17 @@ import { Tools, CloseBold } from '@element-plus/icons-vue'
|
|||||||
import { addDashboard, updateDashboard, queryById } from '@/api/system-boot/csstatisticalset'
|
import { addDashboard, updateDashboard, queryById } from '@/api/system-boot/csstatisticalset'
|
||||||
import html2canvas from 'html2canvas'
|
import html2canvas from 'html2canvas'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
// defineOptions({
|
// defineOptions({
|
||||||
// name: 'cockpit/popup'
|
// name: 'cockpit/popup'
|
||||||
// })
|
// })
|
||||||
const { go } = useRouter()
|
const { go } = useRouter()
|
||||||
const { query } = useRoute()
|
const { query } = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
const height = mainHeight(108)
|
const height = mainHeight(108)
|
||||||
const indicatorHeight = mainHeight(128)
|
const indicatorHeight = mainHeight(128)
|
||||||
const rowHeight = ref(0)
|
const rowHeight = ref(0)
|
||||||
|
const pageList: any = ref([])
|
||||||
const GridHeight = ref(0)
|
const GridHeight = ref(0)
|
||||||
const position = ref<CollapseIconPositionType>('left')
|
const position = ref<CollapseIconPositionType>('left')
|
||||||
const form: any = reactive({
|
const form: any = reactive({
|
||||||
@@ -147,6 +154,8 @@ const form: any = reactive({
|
|||||||
containerConfig: [],
|
containerConfig: [],
|
||||||
sort: '100',
|
sort: '100',
|
||||||
id: '',
|
id: '',
|
||||||
|
pagePath: '',
|
||||||
|
pathName: '',
|
||||||
remark: ''
|
remark: ''
|
||||||
})
|
})
|
||||||
const activeNames = ref([])
|
const activeNames = ref([])
|
||||||
@@ -171,6 +180,13 @@ const layout: any = ref([
|
|||||||
const treeComponents: any = ref([]) //组件树
|
const treeComponents: any = ref([]) //组件树
|
||||||
const treeComponentsCopy: any = ref([]) //组件树
|
const treeComponentsCopy: any = ref([]) //组件树
|
||||||
const info = () => {
|
const info = () => {
|
||||||
|
pageList.value = router
|
||||||
|
.getRoutes()
|
||||||
|
.filter(item => item?.meta?.component == '/src/views/pqs/cockpit/homePage/index.vue')
|
||||||
|
.map(item => {
|
||||||
|
return { name: item?.meta?.title, path: item?.meta?.path }
|
||||||
|
})
|
||||||
|
|
||||||
activeNames.value = []
|
activeNames.value = []
|
||||||
activeNames1.value = []
|
activeNames1.value = []
|
||||||
componentTree().then(res => {
|
componentTree().then(res => {
|
||||||
@@ -188,6 +204,8 @@ const info = () => {
|
|||||||
queryById({ id: query.id }).then(res => {
|
queryById({ id: query.id }).then(res => {
|
||||||
layout.value = JSON.parse(res.data.containerConfig)
|
layout.value = JSON.parse(res.data.containerConfig)
|
||||||
form.pageName = res.data.pageName
|
form.pageName = res.data.pageName
|
||||||
|
form.pagePath = res.data.pagePath
|
||||||
|
form.pathName = res.data.pathName
|
||||||
form.sort = res.data.sort
|
form.sort = res.data.sort
|
||||||
form.remark = res.data.remark
|
form.remark = res.data.remark
|
||||||
form.id = res.data.id
|
form.id = res.data.id
|
||||||
@@ -343,6 +361,8 @@ const onSubmit = () => {
|
|||||||
}).then(canvas => {
|
}).then(canvas => {
|
||||||
url = canvas.toDataURL('image/png')
|
url = canvas.toDataURL('image/png')
|
||||||
})
|
})
|
||||||
|
form.pagePath = form.pagePath || ''
|
||||||
|
form.pathName = pageList.value.filter((item: any) => item.path == form.pagePath)?.[0]?.name || ''
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (form.id == '') {
|
if (form.id == '') {
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ const fetchLayoutData = async () => {
|
|||||||
// 可以添加错误提示逻辑
|
// 可以添加错误提示逻辑
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 计算组件高度
|
||||||
const seRowHeight = (value: any) => {
|
const seRowHeight = (value: any) => {
|
||||||
if (value == 6) return 0
|
if (value == 6) return 0
|
||||||
if (value == 5) return 12
|
if (value == 5) return 12
|
||||||
|
|||||||
@@ -31,8 +31,15 @@
|
|||||||
>
|
>
|
||||||
{{ item.pageName }}
|
{{ item.pageName }}
|
||||||
</span>
|
</span>
|
||||||
|
<div style="display: flex; align-items: center; font-weight: 550">
|
||||||
|
<div v-if="item.pathName" :style="{ color: `var(--el-color-primary)` }">
|
||||||
|
绑定页面:{{ item.pathName }}
|
||||||
|
</div>
|
||||||
|
<div v-else>暂未绑定</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div style="display: flex; justify-content: end">
|
<div style="display: flex; justify-content: end">
|
||||||
<el-button
|
<!-- <el-button
|
||||||
class="color"
|
class="color"
|
||||||
icon="el-icon-Position"
|
icon="el-icon-Position"
|
||||||
style="padding: 3px 0"
|
style="padding: 3px 0"
|
||||||
@@ -41,7 +48,7 @@
|
|||||||
@click="activation(item)"
|
@click="activation(item)"
|
||||||
>
|
>
|
||||||
激活
|
激活
|
||||||
</el-button>
|
</el-button> -->
|
||||||
<el-button
|
<el-button
|
||||||
class="color"
|
class="color"
|
||||||
icon="el-icon-View"
|
icon="el-icon-View"
|
||||||
|
|||||||