feat: 文本下拉选择首项
This commit is contained in:
parent
aec15233d4
commit
7cd4d99b58
@ -48,6 +48,7 @@
|
||||
:h="config.style.height"
|
||||
:search-count="searchCount"
|
||||
:canvas-id="canvasId"
|
||||
@filter-loaded="filterLoaded"
|
||||
/>
|
||||
<component
|
||||
:is="config.component"
|
||||
@ -235,6 +236,9 @@ export default {
|
||||
runAnimation(this.$el, this.config.animations)
|
||||
},
|
||||
methods: {
|
||||
filterLoaded(p) {
|
||||
this.$emit('filter-loaded', p)
|
||||
},
|
||||
getComponentId() {
|
||||
return this.config.id
|
||||
},
|
||||
|
||||
@ -59,6 +59,7 @@
|
||||
:screen-shot="screenShot"
|
||||
:canvas-style-data="canvasStyleData"
|
||||
:show-position="showPosition"
|
||||
@filter-loaded="filterLoaded"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@ -155,7 +156,7 @@ import eventBus from '@/components/canvas/utils/eventBus'
|
||||
import elementResizeDetectorMaker from 'element-resize-detector'
|
||||
import CanvasOptBar from '@/components/canvas/components/editor/CanvasOptBar'
|
||||
import bus from '@/utils/bus'
|
||||
import { buildFilterMap, buildViewKeyMap, formatCondition, valueValid, viewIdMatch } from '@/utils/conditionUtil'
|
||||
import { buildFilterMap, buildViewKeyMap, formatCondition, valueValid, viewIdMatch, buildAfterFilterLoaded } from '@/utils/conditionUtil'
|
||||
import { hasDataPermission } from '@/utils/permission'
|
||||
import { activeWatermark } from '@/components/canvas/tools/watermark'
|
||||
import { proxyUserLoginInfo, userLoginInfo } from '@/api/systemInfo/userLogin'
|
||||
@ -461,6 +462,9 @@ export default {
|
||||
bus.$off('trigger-reset-button', this.triggerResetButton)
|
||||
},
|
||||
methods: {
|
||||
filterLoaded(p) {
|
||||
buildAfterFilterLoaded(this.componentData, this.filterMap, p)
|
||||
},
|
||||
getWrapperChildRefs() {
|
||||
return this.$refs['viewWrapperChild']
|
||||
},
|
||||
|
||||
@ -599,7 +599,23 @@ export default {
|
||||
this.refId = uuid.v1
|
||||
if (this.element && this.element.propValue && this.element.propValue.viewId) {
|
||||
// 如果watch.filters 已经进行数据初始化时候,此处放弃数据初始化
|
||||
|
||||
const unReadyList = []
|
||||
const readyList = []
|
||||
this.filters.forEach(f => {
|
||||
if (f instanceof Promise) {
|
||||
unReadyList.push(f)
|
||||
} else {
|
||||
readyList.push(f)
|
||||
}
|
||||
})
|
||||
if (unReadyList.length) {
|
||||
Promise.all(this.filters.filter(f => f instanceof Promise)).then(fList => {
|
||||
readyList.concat(fList)
|
||||
this.filter.filters = readyList
|
||||
this.getData(this.element.propValue.viewId, false)
|
||||
})
|
||||
return
|
||||
}
|
||||
this.getData(this.element.propValue.viewId, false)
|
||||
}
|
||||
},
|
||||
|
||||
@ -49,6 +49,7 @@
|
||||
:element="element"
|
||||
:in-draw="inDraw"
|
||||
:in-screen="inScreen"
|
||||
@filter-loaded="filterLoaded"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@ -180,6 +181,9 @@ export default {
|
||||
this.$set(this.element.style, 'innerBgColor', innerBgColor || '')
|
||||
},
|
||||
methods: {
|
||||
filterLoaded(p) {
|
||||
this.$emit('filter-loaded', p)
|
||||
},
|
||||
getComponentId() {
|
||||
return this.element.id
|
||||
},
|
||||
|
||||
@ -133,6 +133,9 @@ export default {
|
||||
},
|
||||
isCustomSortWidget() {
|
||||
return this.element.serviceName === 'textSelectWidget'
|
||||
},
|
||||
selectFirst() {
|
||||
return this.element.serviceName === 'textSelectWidget' && this.element.options.attrs.selectFirst
|
||||
}
|
||||
},
|
||||
|
||||
@ -286,16 +289,26 @@ export default {
|
||||
},
|
||||
initLoad() {
|
||||
this.value = this.fillValueDerfault()
|
||||
this.initOptions()
|
||||
if (this.element.options.value) {
|
||||
this.initOptions(this.fillFirstSelected)
|
||||
if (this.element.options.value && !this.selectFirst) {
|
||||
this.value = this.fillValueDerfault()
|
||||
this.changeValue(this.value)
|
||||
}
|
||||
},
|
||||
fillFirstSelected() {
|
||||
if (this.selectFirst && this.data?.length) {
|
||||
this.element.options.value = this.data[0]['id']
|
||||
this.value = this.fillValueDerfault()
|
||||
this.$emit('filter-loaded', {
|
||||
componentId: this.element.id,
|
||||
val: this.value
|
||||
})
|
||||
}
|
||||
},
|
||||
refreshLoad() {
|
||||
this.initOptions()
|
||||
},
|
||||
initOptions() {
|
||||
initOptions(cb) {
|
||||
this.data = []
|
||||
if (this.element.options.attrs.fieldId) {
|
||||
let method = multFieldValues
|
||||
@ -310,6 +323,7 @@ export default {
|
||||
}).then(res => {
|
||||
this.data = this.optionData(res.data)
|
||||
bus.$emit('valid-values-change', true)
|
||||
cb && cb()
|
||||
}).catch(e => {
|
||||
bus.$emit('valid-values-change', false)
|
||||
})
|
||||
|
||||
@ -87,8 +87,13 @@ class TextSelectServiceImpl extends WidgetService {
|
||||
})
|
||||
}
|
||||
|
||||
getParam(element) {
|
||||
const value = this.fillValueDerfault(element)
|
||||
getParam(element, val) {
|
||||
let value = null
|
||||
if (!val) {
|
||||
value = this.fillValueDerfault(element)
|
||||
} else {
|
||||
value = [val]
|
||||
}
|
||||
const param = {
|
||||
component: element,
|
||||
value: !value ? [] : Array.isArray(value) ? value : value.toString().split(','),
|
||||
|
||||
@ -79,6 +79,7 @@ export const buildViewKeyFilters = (panelItems, result) => {
|
||||
if (element.type !== 'custom') {
|
||||
return true
|
||||
}
|
||||
const selectFirst = element.serviceName === 'textSelectWidget' && element.options.attrs.selectFirst
|
||||
|
||||
let param = null
|
||||
const widget = ApplicationContext.getService(element.serviceName)
|
||||
@ -88,15 +89,28 @@ export const buildViewKeyFilters = (panelItems, result) => {
|
||||
const filterComponentId = condition.componentId
|
||||
Object.keys(result).forEach(viewId => {
|
||||
const vidMatch = viewIdMatch(condition.viewIds, viewId)
|
||||
const viewFilters = result[viewId]
|
||||
let j = viewFilters.length
|
||||
while (j--) {
|
||||
const filter = viewFilters[j]
|
||||
if (filter.componentId === filterComponentId) {
|
||||
viewFilters.splice(j, 1)
|
||||
if (vidMatch && selectFirst) {
|
||||
|
||||
const promise = new Promise(resolve => {
|
||||
cbParam => {
|
||||
const newCondition = buildAfterFilterLoaded1(element, cbParam)
|
||||
resolve(newCondition)
|
||||
}
|
||||
})
|
||||
promise.componentId = filterComponentId
|
||||
// promise.cb =
|
||||
result[viewId].push(promise)
|
||||
} else {
|
||||
const viewFilters = result[viewId]
|
||||
let j = viewFilters.length
|
||||
while (j--) {
|
||||
const filter = viewFilters[j]
|
||||
if (filter.componentId === filterComponentId) {
|
||||
viewFilters.splice(j, 1)
|
||||
}
|
||||
}
|
||||
vidMatch && vValid && viewFilters.push(condition)
|
||||
}
|
||||
vidMatch && vValid && viewFilters.push(condition)
|
||||
})
|
||||
})
|
||||
return result
|
||||
@ -108,6 +122,41 @@ export const buildFilterMap = panelItems => {
|
||||
return result
|
||||
}
|
||||
|
||||
const getElementById = (componentId, panelItems) => {
|
||||
for (let index = 0; index < panelItems.length; index++) {
|
||||
const element = panelItems[index]
|
||||
if (element.id === componentId) {
|
||||
return element
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
const buildAfterFilterLoaded1 = (element, p) => {
|
||||
const widget = ApplicationContext.getService(element.serviceName)
|
||||
const param = widget.getParam(element, p.val)
|
||||
const condition = formatCondition(param)
|
||||
return condition
|
||||
}
|
||||
export const buildAfterFilterLoaded = (panelItems, originMap, p) => {
|
||||
const componentId = p.componentId
|
||||
const element = getElementById(componentId, panelItems)
|
||||
let param = null
|
||||
const widget = ApplicationContext.getService(element.serviceName)
|
||||
param = widget.getParam(element, p.val)
|
||||
const condition = formatCondition(param)
|
||||
const vValid = valueValid(condition)
|
||||
Object.keys(originMap).forEach(viewId => {
|
||||
const conditions = originMap[viewId]
|
||||
if (conditions?.length) {
|
||||
conditions.forEach(condition => {
|
||||
if (condition instanceof Promise && condition.componentId === componentId && vValid) {
|
||||
condition.resolve(condition)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const fillElementsFilter = (panelItems, filterMap) => {
|
||||
panelItems.forEach(element => {
|
||||
if (element.type === 'view') {
|
||||
|
||||
@ -278,7 +278,10 @@
|
||||
:active-name="activeName"
|
||||
/>
|
||||
|
||||
<filter-foot :element="currentElement" />
|
||||
<filter-foot
|
||||
:element="currentElement"
|
||||
:control-attrs="myAttrs"
|
||||
/>
|
||||
|
||||
</div>
|
||||
</de-main-container>
|
||||
|
||||
@ -8,6 +8,14 @@
|
||||
>
|
||||
<div style="margin-bottom: 10px;">
|
||||
<span>{{ $t('dynamic_time.set_default') }}</span>
|
||||
|
||||
<el-checkbox
|
||||
v-if="element.serviceName === 'textSelectWidget'"
|
||||
v-model="element.options.attrs.selectFirst"
|
||||
class="select-first-check"
|
||||
@change="selectFirstChange"
|
||||
>首项
|
||||
</el-checkbox>
|
||||
</div>
|
||||
<div class="custom-component-class">
|
||||
<component
|
||||
@ -67,12 +75,15 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
||||
attrs: null
|
||||
}
|
||||
},
|
||||
|
||||
created() {
|
||||
},
|
||||
methods: {
|
||||
|
||||
selectFirstChange(val) {
|
||||
console.log(val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,5 +102,8 @@ export default {
|
||||
max-height: 100%;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
.select-first-check {
|
||||
margin-left: 25px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user