'admin-07.03:修复图标选择器双向绑定回显问题,感谢群友@伯牙已遇钟子期'

This commit is contained in:
lyt-Top 2021-07-03 20:29:26 +08:00
parent 03b85bc8b0
commit 543a31b6d1

View File

@ -31,21 +31,11 @@
<div class="icon-selector-warp-row"> <div class="icon-selector-warp-row">
<el-scrollbar> <el-scrollbar>
<el-row :gutter="10" v-if="fontIconSheetsFilterList.length > 0"> <el-row :gutter="10" v-if="fontIconSheetsFilterList.length > 0">
<el-col <el-col :xs="6" :sm="4" :md="4" :lg="4" :xl="4" @click="onColClick(v, k)" v-for="(v, k) in fontIconSheetsFilterList" :key="k">
:xs="6"
:sm="4"
:md="4"
:lg="4"
:xl="4"
:class="`${fontIconTabsIcon}-col`"
@click="onColClick(v, k)"
v-for="(v, k) in fontIconSheetsFilterList"
:key="k"
>
<div class="icon-selector-warp-item" :class="{ 'icon-selector-active': fontIconIndex === k }"> <div class="icon-selector-warp-item" :class="{ 'icon-selector-active': fontIconIndex === k }">
<div class="flex-margin"> <div class="flex-margin">
<div class="icon-selector-warp-item-value"> <div class="icon-selector-warp-item-value">
<i :class="[fontIconTabsIcon, v]"></i> <i :class="v"></i>
</div> </div>
</div> </div>
</div> </div>
@ -61,7 +51,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { ref, toRefs, reactive, onMounted, nextTick, computed } from 'vue'; import { ref, toRefs, reactive, onMounted, nextTick, computed, watch } from 'vue';
import initIconfont from '/@/utils/getStyleSheets'; import initIconfont from '/@/utils/getStyleSheets';
export default { export default {
name: 'iconSelector', name: 'iconSelector',
@ -120,7 +110,6 @@ export default {
fontIconIndex: '', fontIconIndex: '',
fontIconSearch: '', fontIconSearch: '',
fontIconTabsIndex: 0, fontIconTabsIndex: 0,
fontIconTabsIcon: 'iconfont ali',
fontIconSheetsList: [], fontIconSheetsList: [],
}); });
// icon input // icon input
@ -166,21 +155,20 @@ export default {
const initFontIconData = async () => { const initFontIconData = async () => {
if (props.type === 'ali') { if (props.type === 'ali') {
await initIconfont.ali().then((res: any) => { await initIconfont.ali().then((res: any) => {
state.fontIconTabsIcon = 'iconfont';
state.fontIconTabsIndex = 0; state.fontIconTabsIndex = 0;
state.fontIconSheetsList = res; // 使 `iconfont xxx`
state.fontIconSheetsList = res.map((i) => `iconfont ${i}`);
}); });
} else if (props.type === 'ele') { } else if (props.type === 'ele') {
await initIconfont.ele().then((res: any) => { await initIconfont.ele().then((res: any) => {
state.fontIconTabsIcon = 'ele';
state.fontIconTabsIndex = 1; state.fontIconTabsIndex = 1;
state.fontIconSheetsList = res; state.fontIconSheetsList = res;
}); });
} else if (props.type === 'awe') { } else if (props.type === 'awe') {
await initIconfont.awe().then((res: any) => { await initIconfont.awe().then((res: any) => {
state.fontIconTabsIcon = 'fa';
state.fontIconTabsIndex = 2; state.fontIconTabsIndex = 2;
state.fontIconSheetsList = res; // fontawesome使 `fa xxx`
state.fontIconSheetsList = res.map((i) => `fa ${i}`);
}); });
} }
initModeValueEcho(); initModeValueEcho();
@ -206,6 +194,13 @@ export default {
initResize(); initResize();
getInputWidth(); getInputWidth();
}); });
// modelValue
watch(
() => props.modelValue,
() => {
initModeValueEcho();
}
);
return { return {
inputWidthRef, inputWidthRef,
fontIconSheetsFilterList, fontIconSheetsFilterList,