Skip to content

Commit 8e6896e

Browse files
authored
fix: fix data source type display exception (opentiny#1082)
1 parent 07509fd commit 8e6896e

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

packages/plugins/datasource/src/DataSourceType.vue

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22
<div class="right-item">
33
<tiny-form label-position="top">
44
<tiny-form-item prop="name" label="数据源类型">
5-
<tiny-radio-group v-model="state.value" @change="handleChange">
6-
<tiny-radio
7-
v-for="item in state.dataType"
8-
:key="item.value"
9-
:label="item.name"
10-
:disabled="editable"
11-
></tiny-radio>
5+
<tiny-radio-group v-model="dataSourceType">
6+
<div v-for="{ name, value } in RADIO_GROUP" :key="value">
7+
<tiny-radio :text="name" :label="value" :disabled="editable" />
8+
</div>
129
</tiny-radio-group>
1310
</tiny-form-item>
1411
</tiny-form>
1512
</div>
1613
</template>
1714

1815
<script>
19-
import { reactive, watchEffect } from 'vue'
16+
import { watch, ref } from 'vue'
2017
import { Form, FormItem, RadioGroup, Radio } from '@opentiny/vue'
2118
2219
export default {
@@ -38,46 +35,29 @@ export default {
3835
},
3936
emits: ['update:modelValue'],
4037
setup(props, { emit }) {
41-
const state = reactive({
42-
checkedIndex: 0,
43-
value: '对象数组',
44-
dataType: [
45-
{
46-
name: '对象数组',
47-
icon: 'json',
48-
value: 'array'
49-
},
50-
{
51-
name: '树结构',
52-
icon: 'tree-shape',
53-
value: 'tree'
54-
}
55-
]
56-
})
38+
const RADIO_GROUP = [
39+
{
40+
name: '对象数组',
41+
value: 'array'
42+
},
43+
{
44+
name: '树结构',
45+
value: 'tree'
46+
}
47+
]
5748
58-
watchEffect(() => {
59-
const index = state.dataType.findIndex(({ value }) => value === props.modelValue)
60-
state.checkedIndex = index > -1 ? index : 0
61-
})
49+
const dataSourceType = ref(props.modelValue)
6250
63-
const handleChange = () => {
64-
if (props.editable) {
65-
return
66-
}
67-
emit('update:modelValue', state.value)
68-
}
69-
const selectDataType = (item, index) => {
70-
if (props.editable) {
71-
return
51+
watch(
52+
() => dataSourceType.value,
53+
(newVal) => {
54+
emit('update:modelValue', newVal)
7255
}
73-
state.checkedIndex = index
74-
emit('update:modelValue', item.value)
75-
}
56+
)
7657
7758
return {
78-
state,
79-
selectDataType,
80-
handleChange
59+
RADIO_GROUP,
60+
dataSourceType
8161
}
8262
}
8363
}

0 commit comments

Comments
 (0)