ny
23 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<script lang="ts" setup>
import { computed, reactive, toRefs } from 'vue';
 
import { BasicModal, useModal, useModalInner } from '@jnpf/ui/modal';
import { buildBitUUID } from '@jnpf/utils';
 
import { useDebounceFn } from '@vueuse/core';
import { cloneDeep } from 'lodash-es';
import draggable from 'vuedraggable';
 
import { getDataInterfaceInfo } from '#/api/systemData/dataInterface';
import { getDictionaryTypeSelector } from '#/api/systemData/dictionary';
import { BatchOperate, InterfaceModal } from '#/components/CommonModal';
 
interface State {
  activeData: any;
  dicOptions: any[];
  options: any[];
  allOptions: any[];
}
 
const emit = defineEmits(['register', 'confirm']);
const dataTypeOptions = [
  { id: 'static', fullName: '静态数据' },
  { id: 'dictionary', fullName: '数据字典' },
  { id: 'dynamic', fullName: '数据接口' },
];
const valueOptions = [
  { id: 'id', fullName: 'id' },
  { id: 'enCode', fullName: 'enCode' },
];
const dateFormatOptions = [
  { id: 'yyyy', fullName: 'yyyy' },
  { id: 'yyyy-MM', fullName: 'yyyy-MM' },
  { id: 'yyyy-MM-dd', fullName: 'yyyy-MM-dd' },
  { id: 'yyyy-MM-dd HH:mm', fullName: 'yyyy-MM-dd HH:mm' },
  { id: 'yyyy-MM-dd HH:mm:ss', fullName: 'yyyy-MM-dd HH:mm:ss' },
];
const timeFormatOptions = [
  { id: 'HH:mm:ss', fullName: 'HH:mm:ss' },
  { id: 'HH:mm', fullName: 'HH:mm' },
];
const state = reactive<State>({
  activeData: {
    __config__: {},
  },
  dicOptions: [],
  options: [],
  allOptions: [],
});
const { activeData, dicOptions, options } = toRefs(state);
const [registerModal, { closeModal }] = useModalInner(init);
const [registerBatchOperate, { openModal }] = useModal();
 
const getRangeOptions = computed(() => {
  const list: any = [
    { id: '1', fullName: '查询控件选中用户' },
    { id: '2', fullName: '查询控件选中用户及下属' },
    { id: '3', fullName: '查询控件选中用户及子孙下属' },
  ];
  if (state.activeData.jnpfKey === 'posSelect') {
    list[0].fullName = '查询控件选中岗位';
    list[1].fullName = '查询控件选中岗位及子岗位';
    list[2].fullName = '查询控件选中岗位及子孙岗位';
  }
  if (state.activeData.jnpfKey === 'organizeSelect') {
    list[0].fullName = '查询控件选中组织';
    list[1].fullName = '查询控件选中组织及子组织';
    list[2].fullName = '查询控件选中组织及子孙组织';
  }
  return list;
});
 
const onDataTypeChange = () => {
  state.activeData.options = [];
  state.activeData.props.value = 'id';
  state.activeData.props.label = 'fullName';
  if (Reflect.has(state.activeData.props, 'children')) state.activeData.props.children = 'children';
  state.activeData.__config__.dictionaryType = '';
  state.activeData.__config__.propsUrl = '';
  state.activeData.__config__.propsName = '';
  state.activeData.__config__.templateJson = [];
};
const onDictionaryTypeChange = () => {
  state.activeData.options = [];
};
const onPropsUrlChange = (val, row) => {
  state.activeData.options = [];
  if (!val) {
    state.activeData.__config__.propsUrl = '';
    state.activeData.__config__.propsName = '';
    state.activeData.__config__.templateJson = [];
    state.options = [];
    state.allOptions = [];
    return;
  }
  if (state.activeData.__config__.propsUrl === val) return;
  const list = row.parameterJson ? JSON.parse(row.parameterJson) : [];
  state.activeData.__config__.propsUrl = val;
  state.activeData.__config__.propsName = row.fullName;
  state.activeData.__config__.templateJson = list.map((o) => ({ ...o, relationField: '' }));
  initFieldData();
};
const addSelectItem = () => {
  const uuid = buildBitUUID();
  state.activeData.options.push({
    fullName: `选项${uuid}`,
    id: uuid,
  });
};
const onBatchOperateConfirm = (options) => {
  state.activeData.options = options;
};
const debounceOnSearch = useDebounceFn(onSearch, 300);
 
function onSearch(searchText: string) {
  state.options = state.allOptions.filter((o) => o.value.toLowerCase().includes(searchText.toLowerCase()));
}
function onFocus(searchText) {
  onSearch(searchText);
}
function initFieldData() {
  if (state.activeData.__config__.dataType !== 'dynamic' || !state.activeData.__config__.propsUrl) return (state.allOptions = []);
  getDataInterfaceInfo(state.activeData.__config__.propsUrl).then((res) => {
    const data = res.data;
    const list = data.fieldJson ? JSON.parse(data.fieldJson) : [];
    state.allOptions = list.map((o) => ({ ...o, value: o.defaultValue }));
  });
}
function init(data) {
  state.activeData = cloneDeep(data);
  if (data.jnpfKey === 'select') {
    getDicOptions();
    initFieldData();
  }
}
function getDicOptions() {
  getDictionaryTypeSelector().then((res) => {
    state.dicOptions = res.data.list;
  });
}
function handleSubmit() {
  emit('confirm', state.activeData);
  closeModal();
}
</script>
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="组件属性配置" @ok="handleSubmit" destroy-on-close class="extra-config-modal">
    <div class="extra-config-modal-body" :style="{ 'min-height': activeData.jnpfKey === 'select' ? '300px' : '150px' }">
      <a-form :colon="false" label-align="left" :label-col="{ style: { width: '90px' } }">
        <template v-if="activeData.jnpfKey === 'select'">
          <a-form-item label="数据来源">
            <jnpf-radio
              v-model:value="activeData.__config__.dataType"
              :options="dataTypeOptions"
              option-type="button"
              button-style="solid"
              @change="onDataTypeChange" />
          </a-form-item>
          <div class="options-list" v-if="activeData.__config__.dataType === 'static'">
            <draggable v-model="activeData.options" :animation="300" group="selectItem" handle=".option-drag" item-key="uuid">
              <template #item="{ element, index }">
                <div class="select-item">
                  <div class="select-line-icon option-drag">
                    <i class="icon-ym icon-ym-darg"></i>
                  </div>
                  <a-input v-model:value="element.fullName" placeholder="选项名" />
                  <a-input v-model:value="element.id" placeholder="选项值" />
                  <div class="close-btn select-line-icon" @click="activeData.options.splice(index, 1)">
                    <i class="icon-ym icon-ym-btn-clearn"></i>
                  </div>
                </div>
              </template>
            </draggable>
          </div>
          <div class="add-btn" v-if="activeData.__config__.dataType === 'static'">
            <a-button type="link" pre-icon="icon-ym icon-ym-btn-add" @click="addSelectItem" class="!px-0">添加选项</a-button>
            <a-divider type="vertical" />
            <a-button type="link" @click="openModal(true, { options: activeData.options })" class="!px-0">批量编辑</a-button>
          </div>
          <div v-if="activeData.__config__.dataType === 'dictionary'">
            <a-form-item label="数据字典">
              <jnpf-tree-select
                :options="dicOptions"
                v-model:value="activeData.__config__.dictionaryType"
                placeholder="请选择"
                last-level
                allow-clear
                @change="onDictionaryTypeChange" />
            </a-form-item>
            <a-form-item label="存储字段">
              <jnpf-select v-model:value="activeData.props.value" placeholder="请选择" :options="valueOptions" />
            </a-form-item>
          </div>
          <div v-if="activeData.__config__.dataType === 'dynamic'">
            <a-form-item label="数据接口">
              <InterfaceModal
                :value="activeData.__config__.propsUrl"
                :title="activeData.__config__.propsName"
                popup-title="数据接口"
                @change="onPropsUrlChange" />
            </a-form-item>
            <a-form-item label="存储字段">
              <a-auto-complete
                v-model:value="activeData.props.value"
                placeholder="请输入"
                :options="options"
                @focus="onFocus(activeData.props.value)"
                @search="debounceOnSearch(activeData.props.value)" />
            </a-form-item>
            <a-form-item label="回显字段">
              <a-auto-complete
                v-model:value="activeData.props.label"
                placeholder="请输入"
                :options="options"
                @focus="onFocus(activeData.props.label)"
                @search="debounceOnSearch(activeData.props.label)" />
            </a-form-item>
          </div>
        </template>
        <a-form-item label="日期类型" v-if="activeData.jnpfKey === 'datePicker'">
          <jnpf-select v-model:value="activeData.format" placeholder="请选择" :options="dateFormatOptions" />
        </a-form-item>
        <a-form-item label="时间类型" v-if="activeData.jnpfKey === 'timePicker'">
          <jnpf-select v-model:value="activeData.format" placeholder="请选择" :options="timeFormatOptions" />
        </a-form-item>
        <a-form-item label="" v-if="['organizeSelect', 'posSelect', 'userSelect'].includes(activeData.jnpfKey)">
          <JnpfRadio v-model:value="activeData.selectRange" :options="getRangeOptions" direction="vertical" class="range-radio" />
        </a-form-item>
      </a-form>
      <BatchOperate @register="registerBatchOperate" @confirm="onBatchOperateConfirm" />
    </div>
  </BasicModal>
</template>
<style lang="scss">
.extra-config-modal {
  .extra-config-modal-body {
    min-height: 150px;
    padding-bottom: 20px;
 
    .options-list {
      max-height: 200px;
      margin-bottom: -10px;
      overflow-y: auto;
 
      .scrollbar__wrap {
        margin-bottom: 0 !important;
      }
 
      .select-item {
        box-sizing: border-box;
        display: flex;
        border: 1px dashed var(--component-background);
 
        & .ant-input + .ant-input {
          margin-left: 4px;
        }
 
        .ant-select {
          width: 100%;
        }
 
        & + .select-item {
          margin-top: 4px;
        }
 
        &.sortable-chosen {
          border: 1px dashed var(--primary-color);
        }
 
        .select-line-icon {
          padding: 0 4px;
          font-size: 22px;
          line-height: 31px;
          color: #606266;
 
          .icon-ym-darg {
            display: inline-block;
            font-size: 20px;
            line-height: 31px;
          }
 
          .icon-ym-btn-clearn {
            font-size: 18px;
          }
        }
 
        .close-btn {
          display: flex;
          align-items: center;
          height: 32px;
          color: var(--error-color);
          cursor: pointer;
        }
 
        .option-drag {
          cursor: move;
        }
      }
 
      .jnpf-tree__name {
        width: calc(100% - 60px);
      }
    }
 
    .add-btn {
      padding-left: 27px;
      margin-top: 10px;
    }
  }
 
  .range-radio {
    .ant-radio-wrapper {
      margin-bottom: 6px;
    }
  }
}
</style>