Blame view

antis-ncc-admin/src/views/basic/dynamicModel/list/detail/Item.vue 8.01 KB
de2bd2f9   “wangming”   项目初始化
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  <template>
    <el-col :span="item.__config__.span"
      :class="{'item-card':item.__config__.nccKey==='card','item-table':item.__config__.nccKey==='table'}">
      <template v-if="item.__config__.layout==='colFormItem'">
        <template v-if="item.__config__.nccKey==='divider'">
          <el-divider :content-position="item['content-position']">{{item.__slot__.default}}
          </el-divider>
        </template>
        <template v-else-if="item.__config__.nccKey==='NCCText'">
          <el-form-item label-width="0">
            <NCCText :lineHeight="item.lineHeight" :fontSize="item.fontSize"
              v-model="item.__config__.defaultValue" :textStyle="item.textStyle" />
          </el-form-item>
        </template>
        <template v-else-if="item.__config__.nccKey==='groupTitle'">
          <el-form-item label-width="0">
            <groupTitle :content="item.content" :content-position="item['content-position']" />
          </el-form-item>
        </template>
        <template v-else>
          <el-form-item :prop="item.__vModel__"
            :label-width="item.__config__.labelWidth?`${item.__config__.labelWidth}px`: null"
            :label="item.__config__.showLabel ? item.__config__.label : '' "
            v-if="!item.__config__.noShow">
            <template v-if="item.__config__.nccKey==='uploadFz'">
              <div class="dy-fileList">
                <el-link :underline="false" class="dy-fileList-item"
                  v-for="(cItem,ci) in item.__config__.defaultValue" :key="ci"
                  @click="downloadFile(cItem)"><i class="el-icon-document"></i>{{cItem.name}}
                </el-link>
              </div>
            </template>
            <template v-else-if="item.__config__.nccKey==='uploadImg'">
              <el-image :src="define.comUrl+cItem.url" class="dy-img"
                v-for="(cItem,ci) in item.__config__.defaultValue" :key="ci"
                :preview-src-list="getImgList(item.__config__.defaultValue)" :z-index="10000">
              </el-image>
            </template>
            <template v-else-if="item.__config__.nccKey==='colorPicker'">
              <el-color-picker v-model="item.__config__.defaultValue" :show-alpha="item['show-alpha']"
                :color-format="item['color-format']" :size="item.size" disabled />
            </template>
            <template v-else-if="item.__config__.nccKey==='rate'">
              <el-rate v-model="item.__config__.defaultValue" :max="item.max"
                :allow-half="item['allow-half']" :show-text="item['show-text']"
                :show-score="item['show-score']" disabled />
            </template>
            <template v-else-if="item.__config__.nccKey==='switch'">
              <el-switch v-model="item.__config__.defaultValue" :active-value="item['active-value']"
                :active-color="item['active-color']" :active-text="item['active-text']"
                :inactive-color="item['inactive-color']" :inactive-text="item['inactive-text']"
                :inactive-value="item['inactive-value']" disabled />
            </template>
            <template v-else-if="item.__config__.nccKey==='slider'">
              <div class="slider-box">
                <el-slider v-model="item.__config__.defaultValue" :range='item.range'
                  :show-stops="item['show-stops']" />
                <div class="slider-mark"></div>
              </div>
            </template>
            <template v-else-if="item.__config__.nccKey==='editor'">
              <div v-html="item.__config__.defaultValue"></div>
            </template>
            <template v-else-if="item.__config__.nccKey==='relationForm'">
              <el-link :underline="false" @click.native="toDetail(item)" type="primary">
                {{ item.name }}</el-link>
            </template>
            <template v-else-if="item.__config__.nccKey==='relationFormAttr'">
              <p class="dynamicDetail-text">
                {{ relationData[item.relationField] &&relationData[item.relationField][item.showField] ? relationData[item.relationField][item.showField] : '' }}
              </p>
            </template>
            <template v-else>
              <p class="dynamicDetail-text">{{ getValue(item) }}</p>
            </template>
          </el-form-item>
        </template>
      </template>
      <template v-else>
        <template v-if="item.__config__.nccKey==='card'">
          <el-card :shadow="item.shadow" :header="item.header" class="mb-20">
            <Item v-for="(childItem, childIndex) in item.__config__.children" :key="childIndex"
              :item="childItem" v-bind="$props" v-on="$listeners" />
          </el-card>
        </template>
        <template v-if="item.__config__.nccKey==='row'">
          <el-row :gutter="formConf.gutter">
            <Item v-for="(childItem, childIndex) in item.__config__.children" :key="childIndex"
              :item="childItem" v-bind="$props" v-on="$listeners" />
          </el-row>
        </template>
        <template v-if="item.__config__.nccKey==='table'">
          <el-form-item label-width="0" v-if="!item.__config__.noShow">
            <div class="NCC-common-title" v-if="item.__config__.showTitle">
              <h2>{{item.__config__.label}}</h2>
            </div>
            <NCC-table :data="item.__config__.defaultValue">
              <template v-for="(column,columnIndex) in item.__config__.children">
                <el-table-column :key="columnIndex" :prop="column.__vModel__"
                  :label="column.__config__.label" v-if="column.__config__.nccKey==='relationForm'">
                  <template slot-scope="scope">
                    <el-link :underline="false" type="primary"
                      @click.native="toTableDetail(column,scope.row[column.__vModel__+'_id'])">
                      {{ scope.row[column.__vModel__] }}</el-link>
                  </template>
                </el-table-column>
                <el-table-column :key="columnIndex" :prop="column.__vModel__"
                  :label="column.__config__.label" v-else />
              </template>
            </NCC-table>
          </el-form-item>
        </template>
        <template v-if="item.__config__.nccKey==='tab'">
          <el-tabs :type="item.type" :tab-position="item['tab-position']"
            v-model="item.__config__.active" class="mb-10">
            <el-tab-pane v-for="(pane,i) in item.__config__.children" :key="i" :label="pane.title">
              <Item v-for="(childItem, childIndex) in pane.__config__.children" :key="childIndex"
                :item="childItem" v-bind="$props" v-on="$listeners" />
            </el-tab-pane>
          </el-tabs>
        </template>
        <template v-if="item.__config__.nccKey==='collapse'">
          <el-collapse :accordion="item.accordion" v-model="item.__config__.active" class="mb-20">
            <el-collapse-item v-for="(pane,i) in item.__config__.children" :key="i"
              :title="pane.title" :name="pane.name">
              <Item v-for="(childItem, childIndex) in pane.__config__.children" :key="childIndex"
                :item="childItem" v-bind="$props" v-on="$listeners" />
            </el-collapse-item>
          </el-collapse>
        </template>
      </template>
    </el-col>
  </template>
  <script>
  import { getDownloadUrl } from '@/api/common'
  
  export default {
    name: 'Item',
    props: {
      item: {
        type: Object,
        required: true
      },
      formConf: {
        type: Object,
        required: true
      },
      relationData: {
        type: Object,
        default: () => { }
      }
    },
    methods: {
      toDetail(item) {
        this.$emit('toDetail', item)
      },
      toTableDetail(item, value) {
        item.__config__.defaultValue = value
        this.$emit('toDetail', item)
      },
      downloadFile(file) {
        if (!file.fileId) return
        getDownloadUrl('annex', file.fileId).then(res => {
          if (res.data.url) window.location.href = this.define.comUrl + res.data.url
        })
      },
      getImgList(list) {
        const newList = list.map(o => this.define.comUrl + o.url)
        return newList
      },
      getValue(item) {
        if (Array.isArray(item.__config__.defaultValue)) {
          if (['timeRange', 'dateRange'].includes(item.__config__.nccKey)) {
            return item.__config__.defaultValue.join('')
          }
          return item.__config__.defaultValue.join()
        }
        return item.__config__.defaultValue
      }
    }
  }
  </script>