|
@@ -2,10 +2,11 @@
|
|
|
<!-- <BasicTable @register="registerTable" /> -->
|
|
|
<div class="wrap">
|
|
|
<div class="head">
|
|
|
- <div class="value-head">关系<span style="color: red">*</span></div>
|
|
|
- <div class="value-head">姓名<span style="color: red">*</span></div>
|
|
|
- <div class="value-head">年龄<span style="color: red">*</span></div>
|
|
|
- <div class="value-head">工作单位及职务<span style="color: red">*</span></div>
|
|
|
+ <div class="value-head">关系</div>
|
|
|
+ <div class="value-head">姓名</div>
|
|
|
+ <div class="value-head">年龄</div>
|
|
|
+ <div class="value-head">工作单位</div>
|
|
|
+ <div class="value-head">职务</div>
|
|
|
</div>
|
|
|
<div class="array-item">
|
|
|
<div class="content-item" v-for="(item, index) in list" :key="index">
|
|
@@ -19,19 +20,28 @@
|
|
|
<Input v-model:value="item.age" @change="onChange" />
|
|
|
</div>
|
|
|
<div class="value-content">
|
|
|
+ <Input v-model:value="item.company" @change="onChange" />
|
|
|
+ </div>
|
|
|
+ <div class="value-content">
|
|
|
<Input v-model:value="item.job" @change="onChange" />
|
|
|
</div>
|
|
|
+ <a-button
|
|
|
+ class="mr-2 delete-btn"
|
|
|
+ preIcon="mdi:close-thick"
|
|
|
+ color="error"
|
|
|
+ @click="remove(index)"
|
|
|
+ />
|
|
|
</div>
|
|
|
</div>
|
|
|
<a-button class="add-btn mr-2" size="small" color="success" @click="create"> 追加 </a-button>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
- import { defineComponent, onMounted, reactive, toRefs } from 'vue';
|
|
|
+ import { defineComponent, onUpdated, reactive, nextTick, toRefs, watch } from 'vue';
|
|
|
import { Input } from 'ant-design-vue';
|
|
|
|
|
|
const props = {
|
|
|
- value: { type: [Object], default: [] },
|
|
|
+ value: { type: [], default: [] },
|
|
|
};
|
|
|
|
|
|
export default defineComponent({
|
|
@@ -42,40 +52,32 @@
|
|
|
const state = reactive({
|
|
|
list: [] as object[],
|
|
|
});
|
|
|
- // 初始化 sortable 实现拖动
|
|
|
- function initSortable() {
|
|
|
- // for (let k in props.value) {
|
|
|
- // state.list.push({ name: k, value: props.value[k] });
|
|
|
- // }
|
|
|
- state.list = props.value;
|
|
|
- state.list = [{ relation: '父子', name: '某某', age: '35', job: '会长' }];
|
|
|
- }
|
|
|
- onMounted(() => {
|
|
|
- initSortable(); // 开启拖拽功能
|
|
|
- });
|
|
|
+ // 初始化
|
|
|
+ function init() {
|
|
|
+ // setTimeout(() => {
|
|
|
|
|
|
- function formatList(list) {
|
|
|
- const data: object = {};
|
|
|
- list.map((item) => {
|
|
|
- data[item.name] = item.value;
|
|
|
+ // }, 200);
|
|
|
+ nextTick(() => {
|
|
|
+ console.log(`props.value`, props.value);
|
|
|
+ state.list = props.value;
|
|
|
});
|
|
|
- console.log(`list`, list);
|
|
|
- console.log(`data`, data);
|
|
|
- return data;
|
|
|
}
|
|
|
+ watch(props.value, (value: object[]) => {
|
|
|
+ state.list = value;
|
|
|
+ });
|
|
|
+ onUpdated(() => {
|
|
|
+ init();
|
|
|
+ });
|
|
|
|
|
|
function onChange() {
|
|
|
- const data = formatList(state.list);
|
|
|
- console.log(`state.list`, state.list);
|
|
|
- emit('change', data);
|
|
|
+ emit('change', state.list);
|
|
|
}
|
|
|
function create() {
|
|
|
- state.list.push({ relation: '', name: '', 年龄: '', job: '' });
|
|
|
+ state.list.push({ relation: '', name: '', age: '', company: '', job: '' });
|
|
|
}
|
|
|
function remove(i) {
|
|
|
state.list.splice(i, 1);
|
|
|
- const data = formatList(state.list);
|
|
|
- emit('change', data);
|
|
|
+ emit('change', state.list);
|
|
|
}
|
|
|
|
|
|
return {
|
|
@@ -90,12 +92,15 @@
|
|
|
<style scoped>
|
|
|
.head {
|
|
|
display: flex;
|
|
|
+ width: 93%;
|
|
|
text-align: left;
|
|
|
justify-content: space-around;
|
|
|
}
|
|
|
|
|
|
.value-head {
|
|
|
+ width: 20%;
|
|
|
font-weight: bold;
|
|
|
+ line-height: 20px;
|
|
|
}
|
|
|
|
|
|
.content-item {
|
|
@@ -108,6 +113,12 @@
|
|
|
margin-right: 2px;
|
|
|
}
|
|
|
|
|
|
+ .delete-btn {
|
|
|
+ position: relative;
|
|
|
+ top: 5px;
|
|
|
+ padding: 5px;
|
|
|
+ }
|
|
|
+
|
|
|
.add-btn {
|
|
|
margin-top: 2px;
|
|
|
color: #fff;
|