干燥机配套车间生产管理系统/云平台前端
baoshiwei
2023-03-10 1fb197352b6a263646e4ccd3ed1c7854ede031dd
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!--用户选择框-->
<template>
  <div>
    <BasicModal v-bind="$attrs" @register="register" title="数据对比" width="50%" destroyOnClose :showOkBtn="false">
      <a-row :gutter="6" v-if="dataVersionList" style="margin-left: 2px">
        <span style="margin-top: 5px; margin-right: 3px; margin-left: 4px">版本对比:</span>
        <a-select placeholder="版本号" @change="handleChange1" v-model:value="params.dataId1">
          <a-select-option v-for="(log, logindex) in dataVersionList" :key="log.value" :value="log.value">
            {{ log.text }}
          </a-select-option>
        </a-select>
 
        <a-select placeholder="版本号" @change="handleChange2" style="padding-left: 10px" v-model:value="params.dataId2">
          <a-select-option v-for="(log, logindex) in dataVersionList" :key="log.value" :value="log.value">
            {{ log.text }}
          </a-select-option>
        </a-select>
      </a-row>
      <BasicTable
        :columns="columns"
        v-bind="getBindValue"
        :rowClassName="setDataCss"
        :striped="false"
        :showIndexColumn="false"
        :pagination="false"
        :canResize="false"
        :bordered="true"
        :dataSource="dataSource"
        :searchInfo="searchInfo"
        v-if="isUpdate"
      >
        <template #dataVersionTitle1="{ record }"> <Icon icon="icon-park-outline:grinning-face" /> 版本:{{ dataVersion1Num }} </template>
        <template #dataVersionTitle2="{ record }"> <Icon icon="icon-park-outline:grinning-face" /> 版本:{{ dataVersion2Num }} </template>
        <template #avatarslot="{ record }">
          <div class="anty-img-wrap" v-if="record.dataVersion1 != record.dataVersion2">
            <Icon icon="mdi:arrow-right-bold" style="color: red"></Icon>
          </div>
        </template>
      </BasicTable>
    </BasicModal>
  </div>
</template>
<script lang="ts">
  import { defineComponent, unref, ref, reactive, watch } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { queryCompareList, queryDataVerList } from './datalog.api';
  import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
  import { useAttrs } from '/@/hooks/core/useAttrs';
  import { selectProps } from '/@/components/Form/src/jeecg/props/props';
  import { useMessage } from '/@/hooks/web/useMessage';
 
  export default defineComponent({
    name: 'DataLogCompareModal',
    components: {
      //此处需要异步加载BasicTable
      BasicModal,
      BasicTable: createAsyncComponent(() => import('/@/components/Table/src/BasicTable.vue'), { loading: true }),
    },
    props: {
      ...selectProps,
    },
    emits: ['register', 'btnOk'],
    setup(props, { emit, refs }) {
      const { createMessage } = useMessage();
      const attrs = useAttrs();
      const getBindValue = Object.assign({}, unref(props), unref(attrs));
      const dataSource = ref([]);
      const dataVersion1Num = ref('');
      const dataVersion2Num = ref('');
      const isUpdate = ref(true);
      const searchInfo = {};
      const dataId1 = ref('');
      const dataId2 = ref('');
      const dataId = ref('');
      const dataTable1 = ref('');
      const dataID3 = ref('');
      const dataTable = ref('');
      const confirmLoading = ref(false);
      const dataVersionList = ref([]);
      let params = reactive({ dataId1: '', dataId2: '' });
      let dataLog = reactive({});
      const [register, { setModalProps, closeModal }] = useModalInner(async (data) => {
        isUpdate.value = !!data?.isUpdate;
        if (unref(isUpdate)) {
          let checkedRows = data.selectedRows;
          dataTable.value = checkedRows[0].dataTable;
          dataId.value = checkedRows[0].dataId;
          dataId1.value = checkedRows[0].id;
          dataId2.value = checkedRows[1].id;
          params.dataId1 = dataId1.value;
          params.dataId2 = dataId2.value;
          await initDataVersionList();
          await initTableData();
        }
      });
 
      //定义表格列
      const columns = [
        {
          title: '字段名',
          dataIndex: 'code',
          width: 20,
          align: 'left',
        },
        {
          dataIndex: 'dataVersion1',
          align: 'left',
          width: 60,
          slots: { title: 'dataVersionTitle1' },
        },
        {
          title: '',
          dataIndex: 'imgshow',
          align: 'center',
          slots: { customRender: 'avatarslot' },
          width: 5,
        },
        {
          align: 'left',
          dataIndex: 'dataVersion2',
          width: 60,
          filters: [],
          filterMultiple: false,
          slots: { title: 'dataVersionTitle2' },
        },
      ];
      async function initTableData() {
        console.info('params', params);
        queryCompareList(unref(params)).then((res) => {
          console.info('test', res);
          dataVersion1Num.value = res[0].dataVersion;
          dataVersion2Num.value = res[1].dataVersion;
          let json1 = JSON.parse(res[0].dataContent);
          let json2 = JSON.parse(res[1].dataContent);
          let data = [];
          for (var item1 in json1) {
            for (var item2 in json2) {
              if (item1 == item2) {
                data.push({
                  code: item1,
                  imgshow: '',
                  dataVersion1: json1[item1],
                  dataVersion2: json2[item2],
                });
              }
            }
          }
          dataSource.value = data;
        });
      }
      function handleChange1(value) {
        if (params.dataId2 == value) {
          createMessage.warning('相同版本号不能比较');
          return;
        }
        params.dataId1 = value;
        initTableData();
      }
      function handleChange2(value) {
        if (params.dataId1 == value) {
          createMessage.warning('相同版本号不能比较');
          return;
        }
        params.dataId2 = value;
        initTableData();
      }
      function setDataCss(record) {
        let className = 'trcolor';
        const dataVersion1 = record.dataVersion1;
        const dataVersion2 = record.dataVersion2;
        if (dataVersion1 != dataVersion2) {
          return className;
        }
      }
      async function initDataVersionList() {
        queryDataVerList({ dataTable: dataTable.value, dataId: dataId.value }).then((res) => {
          dataVersionList.value = res.map((value, key, arr) => {
            let item = {};
            item['text'] = value['dataVersion'];
            item['value'] = value['id'];
            return item;
          });
        });
      }
 
      return {
        //config,
        searchInfo,
        dataSource,
        setDataCss,
        isUpdate,
        dataVersionList,
        dataVersion1Num,
        dataVersion2Num,
        queryCompareList,
        initDataVersionList,
        register,
        handleChange1,
        handleChange2,
        params,
        getBindValue,
        columns,
      };
    },
  });
</script>
<style scoped>
  .anty-img-wrap {
    height: 25px;
    position: relative;
  }
 
  .anty-img-wrap > img {
    max-height: 100%;
  }
 
  .marginCss {
    margin-top: 20px;
  }
</style>