Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TinyTabs): 选项卡组件配置项的modelValue改为select组件,且其options随着选项卡而变化 #439

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
9f7f3e1
add(property-linkage): tinyTabs component's property 'modelValue' rep…
betterdancing Apr 18, 2024
617e712
add(tabs): 修改tinyTabs的modelValue物料配置
betterdancing Apr 20, 2024
d3402ac
feat(TinyTabs): 选项卡组件配置项的modelValue改为select组件,且其options随着选项卡而变化
betterdancing Apr 26, 2024
b382954
feat(tabs-option): 删除无用的console.log日志
betterdancing May 6, 2024
84b9aff
Merge branch 'develop' of github.com:betterdancing/tiny-engine into t…
betterdancing May 7, 2024
a2d6785
feat(tabs): 将组件属性的处理逻辑放到useProperties中
betterdancing May 7, 2024
ba71c5b
Merge branch 'develop' of github.com:betterdancing/tiny-engine into t…
betterdancing May 7, 2024
8443b24
feat(tinyTabs): 修复切换组件后再切换回tabs组件时,modelValue选项错误的问题
betterdancing May 7, 2024
587ae52
feat(tinyTabs): utils function 添加测试用例
betterdancing May 8, 2024
59220ee
feat(tinyTabs): utils新增公共方法的测试用例
betterdancing May 8, 2024
0eac188
feat(tinyTabs): utils新增公共方法测试用例问题修改
betterdancing May 9, 2024
15d0b3e
feat(tinyTabs): utils新增公共方法测试用例问题修改
betterdancing May 10, 2024
3bc8d9e
feat(tinyTabs):删除选项卡时,如果是当前选中的则将当前选中置为第一条,如果列表为空,则已选择的也清空
betterdancing May 11, 2024
7d0a760
feat(tinyTabs): 修改检视意见
betterdancing May 11, 2024
41bdc3a
feat(TinyTabs):完善MetaSelect代码逻辑
betterdancing May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions mockServer/assets/json/bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -4318,7 +4318,7 @@
"defaultValue": ""
}
},
"onBeforeMount": "console.log('table on load'); this.options = source.data"
"onBeforeMount": "this.options = source.data"
},
"configure": {
"loop": true,
Expand Down Expand Up @@ -5832,6 +5832,7 @@
"required": true,
"readOnly": false,
"disabled": false,
"onChange": "function(val) { this.setPropertyProps('modelValue', { 'options': val }) }",
"defaultValue": "",
"cols": 12,
"bindState": false,
Expand All @@ -5842,7 +5843,7 @@
"description": {
"zh_CN": "tabs"
},
"labelPosition": "none"
"labelPosition": "top"
},
{
"property": "modelValue",
Expand All @@ -5856,13 +5857,25 @@
"disabled": false,
"cols": 12,
"widget": {
"component": "MetaInput",
"props": {}
"component": "MetaSelect",
"props": {
"clearable": false,
"options": [
{
"label": "标签页1",
"value": "first"
},
{
"label": "标签页2",
"value": "second"
}
]
}
},
"description": {
"zh_CN": "绑定值,选中选项卡的 name"
},
"labelPosition": "left"
"labelPosition": "top"
},
{
"property": "with-add",
Expand Down Expand Up @@ -7536,7 +7549,7 @@
"contentMenu": {
"actions": ["create symbol"]
},
"onBeforeMount": "console.log('table on load'); this.pager = source.pager; this.fetchData = source.fetchData; this.data = source.data ;this.columns = source.columns"
"onBeforeMount": "this.pager = source.pager; this.fetchData = source.fetchData; this.data = source.data ;this.columns = source.columns"
},
"configure": {
"loop": true,
Expand Down Expand Up @@ -9819,7 +9832,17 @@
"schema": {
"componentName": "TinyTabs",
"props": {
"modelValue": "first"
"modelValue": "first",
"tabs": [
{
"label": "标签页1",
"value": "first"
},
{
"label": "标签页2",
"value": "second"
}
]
},
"children": [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/common/component/ConfigItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export default {

const executeRelationAction = (value, preValue) => {
const { onChange, rules } = props.property
const { setProp, delProp } = useProperties()
const { setProp, delProp, setPropertyProps } = useProperties()

// 关联
if (onChange && propsObj) {
Expand All @@ -374,6 +374,7 @@ export default {
config: {
...widget.value?.props
},
setPropertyProps,
setProp: setProp,
delProp
})
Expand Down
37 changes: 33 additions & 4 deletions packages/common/component/MetaContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<template #content="{ data }">
<div class="item-text">
<div class="tiny-input">
<input v-model="data.props.title" class="tiny-input__inner" />
<input v-model="data.props.title" @input="labelChange" class="tiny-input__inner" />
</div>
</div>
</template>
Expand All @@ -20,7 +20,7 @@
</div>
</template>
<script>
import { ref } from 'vue'
import { ref, watch } from 'vue'
import MetaListItems from './MetaListItems.vue'
import { useProperties, useResource, useHistory } from '@opentiny/tiny-engine-controller'
import { utils } from '@opentiny/tiny-engine-utils'
Expand All @@ -31,7 +31,13 @@ export default {
MetaListItems,
IconDel: iconDel()
},
setup() {
props: {
modelValue: Array,
default: () => []
},
emits: ['update:modelValue'],
setup(props, { emit }) {
const tabsOptions = ref([])
const { children: schemaChildren, componentName } = useProperties().getSchema()
const configureMap = useResource().getConfigureMap()
const childComponentName =
Expand Down Expand Up @@ -63,6 +69,7 @@ export default {

const delChildren = (data) => {
schemaChildren.splice(children.value.indexOf(data), 1)
tabsOptions.value = tabsOptions.value.filter((option) => option.value !== data.props.name)
children.value = [...schemaChildren]
useHistory().addHistory()
}
Expand All @@ -81,7 +88,29 @@ export default {
children.value = [...list]
}

return { children, addChildren, delChildren, dragEnd }
const updateTabsOptions = (schema) => {
tabsOptions.value = schema.map((item) => {
return {
label: item.props.title,
value: item.props.name
}
})
emit('update:modelValue', tabsOptions.value)
}

const labelChange = () => {
updateTabsOptions(children.value)
}

watch(
() => children.value,
(value) => {
updateTabsOptions(value)
},
{ deep: true, immediate: true }
)

return { children, addChildren, delChildren, labelChange, dragEnd }
}
}
</script>
Expand Down
6 changes: 5 additions & 1 deletion packages/common/component/MetaSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:multiple="multi"
:is-drop-inherit-width="true"
:show-alloption="false"
:clearable="true"
:clearable="clearable"
@change="handleChange"
>
<template v-if="groups?.length">
Expand Down Expand Up @@ -70,6 +70,10 @@ export default {
options: {
type: Array,
default: () => []
},
clearable: {
type: Boolean,
default: true
}
},
emits: ['update:modelValue'],
Expand Down
93 changes: 92 additions & 1 deletion packages/controller/src/useProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
*/

import { toRaw, nextTick, shallowReactive, ref } from 'vue'
import { constants } from '@opentiny/tiny-engine-utils'
import { constants, utils } from '@opentiny/tiny-engine-utils'
import useCanvas from './useCanvas'
import useResource from './useResource'
import useTranslate from './useTranslate'

const { COMPONENT_NAME } = constants
const { delNullKey } = utils
const propsUpdateKey = ref(0)

const otherBaseKey = {
Expand Down Expand Up @@ -153,6 +154,90 @@ const properties = shallowReactive({

const isPageOrBlock = (schema) => [COMPONENT_NAME.Block, COMPONENT_NAME.Page].includes(schema?.componentName)

const getPropertyItem = (propertyName, properties) => {
const { pageState } = useCanvas()

if (!properties) {
properties = pageState.properties
}
let propertyItem = null
properties.some((property) => {
return property.content.some((item) => {
if (item.property === propertyName) {
propertyItem = item
return true
}
if (item.properties) {
betterdancing marked this conversation as resolved.
Show resolved Hide resolved
propertyItem = getPropertyItem(propertyName, item.properties)
return propertyItem
}
return false
})
})
return propertyItem
}

/**
* get property value
* @param {string} propertyName
* @returns any
*/
const getPropertyValue = (propertyName) => {
const propertyItem = getPropertyItem(propertyName)
return propertyItem?.widget?.props?.modelValue
}

/**
* set property value
* @param {string} propertyName
* @param {any} value
*/
const setPropertyValue = async (propertyName, value) => {
const propertyItem = getPropertyItem(propertyName)
if (propertyItem?.widget?.props) {
await nextTick()
betterdancing marked this conversation as resolved.
Show resolved Hide resolved
propertyItem.widget.props.modelValue = value
}
}

/**
* get property props
* @param {string} propertyName
* @returns object
*/
const getPropertyProps = (propertyName) => {
const propertyItem = getPropertyItem(propertyName)
return propertyItem?.widget?.props
}

/**
* set property props
* @param {string} propertyName
* @param {object} props
*/
const setPropertyProps = (propertyName, props = {}) => {
const propertyItem = getPropertyItem(propertyName)
if (propertyItem?.widget?.props) {
const realProps = delNullKey(props, { deep: false, keepRef: true })
if (!propertyItem?.widget?.props) {
propertyItem.widget.props = {}
}
Object.assign(propertyItem.widget?.props, realProps)
}
}

const getPropertyHidden = (propertyName) => {
const propertyItem = getPropertyItem(propertyName)
return propertyItem?.hidden ?? false
}

const setPropertyHidden = (propertyName, hidden) => {
const propertyItem = getPropertyItem(propertyName)
if (propertyItem) {
propertyItem.hidden = Boolean(hidden)
}
}

const getProps = (schema, parent) => {
// 1 现在选中的节点和当前节点一样,不需要重新计算, 2 默认进来由于scheme和properities.schema相等,因此判断如果是“页面或者区块”需要进入if判断
if (schema && (properties.schema !== schema || isPageOrBlock(schema))) {
Expand Down Expand Up @@ -219,6 +304,12 @@ const setProps = (schema) => {

export default function () {
return {
getPropertyHidden,
setPropertyHidden,
getPropertyValue,
setPropertyValue,
getPropertyProps,
setPropertyProps,
getProps,
getProp,
setProps,
Expand Down
Loading
Loading