cloudroam
2025-03-28 cef2bb0eeeb91a22860cf5d23c7348af1ba921dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template>
  <div class="base-link">
    <div v-for="(item, index) in linkList" :key="index" class="base-link__item">
      <el-input
        v-model="item.name"
        placeholder="请输入名称"
        clearable
        @change="onInputChange"
      />
      <i class="base-link__separator">-</i>
      <el-input
        v-model="item.link"
        placeholder="请输入链接"
        clearable
        @change="onInputChange"
      />
      <div class="base-link__delete" @click="deletePoject(index)">
        <i class="el-icon-delete"></i>
      </div>
    </div>
    <div class="base-link__add">
      <el-button type="primary" icon="el-icon-plus" @click="addPoject"
        >继续添加</el-button
      >
    </div>
  </div>
</template>
 
<script>
export default {
  name: 'BaseLink',
  props: {
    value: {
      type: Array,
      default: () => [],
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      codeForm: {},
      linkList: [],
    }
  },
  watch: {
    value: {
      immediate: true,
      handler(value) {
        this.linkList = value || []
      },
    },
  },
  methods: {
    addPoject() {
      this.linkList.push({
        name: '',
        link: '',
      })
      this.onInputChange()
    },
    deletePoject(item) {
      this.linkList.splice(item, 1)
      this.onInputChange()
    },
    onInputChange() {
      this.$emit('input', this.linkList)
      this.$emit('change', this.linkList)
    },
  },
}
</script>
 
<style lang="scss" scoped>
.base-link {
  height: 100%;
  &__item {
    position: relative;
    display: flex;
    align-items: center;
    .el-input {
      width: 45% !important;
    }
    &:not(:last-child) {
      margin-bottom: 8px;
    }
  }
  &__separator {
    margin: 0 6px;
  }
  &__delete {
    cursor: pointer;
    font-size: 20px;
    margin-left: 15px;
    color: $tip-color;
  }
  &__add {
    margin-top: 5px;
  }
}
</style>