feat: Icon改版
This commit is contained in:
parent
64c7e48bd1
commit
882f162ff2
|
@ -27,6 +27,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@iconify/iconify": "^3.1.0",
|
"@iconify/iconify": "^3.1.0",
|
||||||
|
"@iconify/vue": "^4.1.1",
|
||||||
"@vueuse/core": "^10.2.0",
|
"@vueuse/core": "^10.2.0",
|
||||||
"@wangeditor/editor": "^5.1.23",
|
"@wangeditor/editor": "^5.1.23",
|
||||||
"@wangeditor/editor-for-vue": "^5.1.10",
|
"@wangeditor/editor-for-vue": "^5.1.10",
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, unref, ref, watch, nextTick } from 'vue'
|
import { computed, unref } from 'vue'
|
||||||
import { ElIcon } from 'element-plus'
|
import { ElIcon } from 'element-plus'
|
||||||
import { propTypes } from '@/utils/propTypes'
|
import { propTypes } from '@/utils/propTypes'
|
||||||
import Iconify from '@purge-icons/generated'
|
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
|
import { Icon } from '@iconify/vue'
|
||||||
|
|
||||||
const { getPrefixCls } = useDesign()
|
const { getPrefixCls } = useDesign()
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ const props = defineProps({
|
||||||
hoverColor: propTypes.string
|
hoverColor: propTypes.string
|
||||||
})
|
})
|
||||||
|
|
||||||
const elRef = ref<ElRef>(null)
|
const emit = defineEmits(['click'])
|
||||||
|
|
||||||
const isLocal = computed(() => props.icon.startsWith('svg-icon:'))
|
const isLocal = computed(() => props.icon.startsWith('svg-icon:'))
|
||||||
|
|
||||||
|
@ -35,53 +35,28 @@ const getIconifyStyle = computed(() => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const updateIcon = async (icon: string) => {
|
const iconClick = () => {
|
||||||
if (unref(isLocal)) return
|
emit('click')
|
||||||
|
|
||||||
const el = unref(elRef)
|
|
||||||
if (!el) return
|
|
||||||
|
|
||||||
await nextTick()
|
|
||||||
|
|
||||||
if (!icon) return
|
|
||||||
|
|
||||||
const svg = Iconify.renderSVG(icon, {})
|
|
||||||
if (svg) {
|
|
||||||
el.textContent = ''
|
|
||||||
el.appendChild(svg)
|
|
||||||
} else {
|
|
||||||
const span = document.createElement('span')
|
|
||||||
span.className = 'iconify'
|
|
||||||
span.dataset.icon = icon
|
|
||||||
el.textContent = ''
|
|
||||||
el.appendChild(span)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
|
||||||
() => props.icon,
|
|
||||||
(icon: string) => {
|
|
||||||
updateIcon(icon)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ElIcon :class="prefixCls" :size="size" :color="color">
|
<ElIcon :class="prefixCls" :size="size" :color="color" @click="iconClick">
|
||||||
<svg v-if="isLocal" aria-hidden="true">
|
<svg v-if="isLocal" aria-hidden="true">
|
||||||
<use :xlink:href="symbolId" />
|
<use :xlink:href="symbolId" />
|
||||||
</svg>
|
</svg>
|
||||||
|
|
||||||
<span v-else ref="elRef" class="iconify" :data-icon="symbolId" :style="getIconifyStyle"></span>
|
<Icon v-else :icon="icon" :style="getIconifyStyle" />
|
||||||
</ElIcon>
|
</ElIcon>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
@prefix-cls: ~'@{namespace}-icon';
|
@prefix-cls: ~'@{namespace}-icon';
|
||||||
|
|
||||||
.@{prefix-cls} {
|
.@{prefix-cls},
|
||||||
|
.iconify {
|
||||||
&:hover {
|
&:hover {
|
||||||
svg {
|
:deep(svg) {
|
||||||
color: v-bind(hoverColor) !important;
|
color: v-bind(hoverColor) !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
<script lang="tsx">
|
<script lang="tsx">
|
||||||
import { ElTable, ElTableColumn, ElPagination, ComponentSize, ElTooltipProps } from 'element-plus'
|
import {
|
||||||
|
ElTable,
|
||||||
|
ElTableColumn,
|
||||||
|
ElPagination,
|
||||||
|
ComponentSize,
|
||||||
|
ElTooltipProps,
|
||||||
|
ElTooltip
|
||||||
|
} from 'element-plus'
|
||||||
import { defineComponent, PropType, ref, computed, unref, watch, onMounted } from 'vue'
|
import { defineComponent, PropType, ref, computed, unref, watch, onMounted } from 'vue'
|
||||||
import { propTypes } from '@/utils/propTypes'
|
import { propTypes } from '@/utils/propTypes'
|
||||||
import { setIndex } from './helper'
|
import { setIndex } from './helper'
|
||||||
|
@ -8,12 +15,17 @@ import { set } from 'lodash-es'
|
||||||
import { CSSProperties } from 'vue'
|
import { CSSProperties } from 'vue'
|
||||||
import { getSlot } from '@/utils/tsxHelper'
|
import { getSlot } from '@/utils/tsxHelper'
|
||||||
import { Icon } from '@/components/Icon'
|
import { Icon } from '@/components/Icon'
|
||||||
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'Table',
|
name: 'Table',
|
||||||
props: {
|
props: {
|
||||||
pageSize: propTypes.number.def(10),
|
pageSize: propTypes.number.def(10),
|
||||||
currentPage: propTypes.number.def(1),
|
currentPage: propTypes.number.def(1),
|
||||||
|
// 是否展示表格的工具栏
|
||||||
|
showAction: propTypes.bool.def(false),
|
||||||
// 是否所有的超出隐藏,优先级低于schema中的showOverflowTooltip,
|
// 是否所有的超出隐藏,优先级低于schema中的showOverflowTooltip,
|
||||||
showOverflowTooltip: propTypes.bool.def(true),
|
showOverflowTooltip: propTypes.bool.def(true),
|
||||||
// 表头
|
// 表头
|
||||||
|
@ -171,7 +183,7 @@ export default defineComponent({
|
||||||
scrollbarAlwaysOn: propTypes.bool.def(false),
|
scrollbarAlwaysOn: propTypes.bool.def(false),
|
||||||
flexible: propTypes.bool.def(false)
|
flexible: propTypes.bool.def(false)
|
||||||
},
|
},
|
||||||
emits: ['update:pageSize', 'update:currentPage', 'register'],
|
emits: ['update:pageSize', 'update:currentPage', 'register', 'refresh'],
|
||||||
setup(props, { attrs, emit, slots, expose }) {
|
setup(props, { attrs, emit, slots, expose }) {
|
||||||
const elTableRef = ref<ComponentRef<typeof ElTable>>()
|
const elTableRef = ref<ComponentRef<typeof ElTable>>()
|
||||||
|
|
||||||
|
@ -231,6 +243,10 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const refresh = () => {
|
||||||
|
emit('refresh')
|
||||||
|
}
|
||||||
|
|
||||||
expose({
|
expose({
|
||||||
setProps,
|
setProps,
|
||||||
setColumn,
|
setColumn,
|
||||||
|
@ -411,9 +427,18 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div v-loading={unref(getProps).loading}>
|
<div v-loading={unref(getProps).loading}>
|
||||||
<div>
|
{unref(getProps).showAction ? (
|
||||||
<Icon icon="ant-design:sync-outlined" class="cursor-pointer" />
|
<div class="text-right">
|
||||||
|
<ElTooltip content={t('common.refresh')} placement="top">
|
||||||
|
<Icon
|
||||||
|
icon="ant-design:sync-outlined"
|
||||||
|
class="cursor-pointer mr-8px"
|
||||||
|
hover-color="var(--el-color-primary)"
|
||||||
|
onClick={refresh}
|
||||||
|
/>
|
||||||
|
</ElTooltip>
|
||||||
</div>
|
</div>
|
||||||
|
) : null}
|
||||||
<ElTable ref={elTableRef} data={unref(getProps).data} {...unref(getBindValue)}>
|
<ElTable ref={elTableRef} data={unref(getProps).data} {...unref(getBindValue)}>
|
||||||
{{
|
{{
|
||||||
default: () => renderTableColumn(),
|
default: () => renderTableColumn(),
|
||||||
|
|
|
@ -74,6 +74,7 @@ export interface TableSetProps {
|
||||||
export interface TableProps extends Omit<Partial<ElTableProps<any[]>>, 'data'> {
|
export interface TableProps extends Omit<Partial<ElTableProps<any[]>>, 'data'> {
|
||||||
pageSize?: number
|
pageSize?: number
|
||||||
currentPage?: number
|
currentPage?: number
|
||||||
|
showAction?: boolean
|
||||||
// 是否所有的超出隐藏,优先级低于schema中的showOverflowTooltip,
|
// 是否所有的超出隐藏,优先级低于schema中的showOverflowTooltip,
|
||||||
showOverflowTooltip?: boolean
|
showOverflowTooltip?: boolean
|
||||||
// 表头
|
// 表头
|
||||||
|
|
|
@ -371,7 +371,6 @@ watch(
|
||||||
<Icon
|
<Icon
|
||||||
:class="`${prefixCls}__item--close`"
|
:class="`${prefixCls}__item--close`"
|
||||||
color="#333"
|
color="#333"
|
||||||
hover-color="var(--el-color-white)"
|
|
||||||
icon="ant-design:close-outlined"
|
icon="ant-design:close-outlined"
|
||||||
:size="12"
|
:size="12"
|
||||||
@click.prevent.stop="closeSelectedTag(item)"
|
@click.prevent.stop="closeSelectedTag(item)"
|
||||||
|
|
|
@ -150,6 +150,10 @@ export const useTable = (config: UseTableConfig) => {
|
||||||
getElTableExpose: async () => {
|
getElTableExpose: async () => {
|
||||||
await getTable()
|
await getTable()
|
||||||
return unref(elTableRef)
|
return unref(elTableRef)
|
||||||
|
},
|
||||||
|
|
||||||
|
refresh: () => {
|
||||||
|
methods.getList()
|
||||||
}
|
}
|
||||||
// // 删除数据
|
// // 删除数据
|
||||||
// delList: async (ids: string[] | number[], multiple: boolean, message = true) => {
|
// delList: async (ids: string[] | number[], multiple: boolean, message = true) => {
|
||||||
|
|
|
@ -40,7 +40,9 @@ export default {
|
||||||
delOk: 'OK',
|
delOk: 'OK',
|
||||||
delCancel: 'Cancel',
|
delCancel: 'Cancel',
|
||||||
delNoData: 'Please select the data to delete',
|
delNoData: 'Please select the data to delete',
|
||||||
delSuccess: 'Deleted successfully'
|
delSuccess: 'Deleted successfully',
|
||||||
|
refresh: 'Refresh',
|
||||||
|
fullscreen: 'Fullscreen'
|
||||||
},
|
},
|
||||||
lock: {
|
lock: {
|
||||||
lockScreen: 'Lock screen',
|
lockScreen: 'Lock screen',
|
||||||
|
|
|
@ -40,7 +40,9 @@ export default {
|
||||||
delOk: '确定',
|
delOk: '确定',
|
||||||
delCancel: '取消',
|
delCancel: '取消',
|
||||||
delNoData: '请选择需要删除的数据',
|
delNoData: '请选择需要删除的数据',
|
||||||
delSuccess: '删除成功'
|
delSuccess: '删除成功',
|
||||||
|
refresh: '刷新',
|
||||||
|
fullscreen: '全屏'
|
||||||
},
|
},
|
||||||
lock: {
|
lock: {
|
||||||
lockScreen: '锁定屏幕',
|
lockScreen: '锁定屏幕',
|
||||||
|
|
|
@ -21,7 +21,7 @@ const { tableRegister, tableMethods, tableState } = useTable({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const { loading, dataList, total, currentPage, pageSize } = tableState
|
const { loading, dataList, total, currentPage, pageSize } = tableState
|
||||||
const { setProps, setColumn, getElTableExpose, addColumn, delColumn } = tableMethods
|
const { setProps, setColumn, getElTableExpose, addColumn, delColumn, refresh } = tableMethods
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
@ -249,6 +249,7 @@ const getSelections = async () => {
|
||||||
<Table
|
<Table
|
||||||
v-model:pageSize="pageSize"
|
v-model:pageSize="pageSize"
|
||||||
v-model:currentPage="currentPage"
|
v-model:currentPage="currentPage"
|
||||||
|
showAction
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:data="dataList"
|
:data="dataList"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
@ -260,6 +261,7 @@ const getSelections = async () => {
|
||||||
: undefined
|
: undefined
|
||||||
"
|
"
|
||||||
@register="tableRegister"
|
@register="tableRegister"
|
||||||
|
@refresh="refresh"
|
||||||
/>
|
/>
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue