Skip to content
Merged
Changes from all commits
Commits
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
66 changes: 23 additions & 43 deletions packages/plugins/datasource/src/DataSourceType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@
<div class="right-item">
<tiny-form label-position="top">
<tiny-form-item prop="name" label="数据源类型">
<tiny-radio-group v-model="state.value" @change="handleChange">
<tiny-radio
v-for="item in state.dataType"
:key="item.value"
:label="item.name"
:disabled="editable"
></tiny-radio>
<tiny-radio-group v-model="dataSourceType">
<div v-for="{ name, value } in RADIO_GROUP" :key="value">
<tiny-radio :text="name" :label="value" :disabled="editable" />
</div>
</tiny-radio-group>
</tiny-form-item>
</tiny-form>
</div>
</template>

<script>
import { reactive, watchEffect } from 'vue'
import { watch, ref } from 'vue'
import { Form, FormItem, RadioGroup, Radio } from '@opentiny/vue'

export default {
Expand All @@ -38,46 +35,29 @@ export default {
},
emits: ['update:modelValue'],
setup(props, { emit }) {
const state = reactive({
checkedIndex: 0,
value: '对象数组',
dataType: [
{
name: '对象数组',
icon: 'json',
value: 'array'
},
{
name: '树结构',
icon: 'tree-shape',
value: 'tree'
}
]
})
const RADIO_GROUP = [
{
name: '对象数组',
value: 'array'
},
{
name: '树结构',
value: 'tree'
}
]

watchEffect(() => {
const index = state.dataType.findIndex(({ value }) => value === props.modelValue)
state.checkedIndex = index > -1 ? index : 0
})
const dataSourceType = ref(props.modelValue)

const handleChange = () => {
if (props.editable) {
return
}
emit('update:modelValue', state.value)
}
const selectDataType = (item, index) => {
if (props.editable) {
return
watch(
() => dataSourceType.value,
(newVal) => {
emit('update:modelValue', newVal)
}
state.checkedIndex = index
emit('update:modelValue', item.value)
}
)

return {
state,
selectDataType,
handleChange
RADIO_GROUP,
dataSourceType
}
}
}
Expand Down