ny
22 小时以前 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
<script lang="ts" setup>
import { computed, unref } from 'vue';
 
defineOptions({ inheritAttrs: false });
const props = defineProps(['activeData', 'drawingList']);
 
const selectTypeOptions = [
  { id: 'all', fullName: '全部' },
  { id: 'custom', fullName: '自定义' },
];
const userSelectTypeOptions = [
  ...selectTypeOptions,
  { id: 'org', fullName: '组织组件联动' },
  { id: 'pos', fullName: '岗位组件联动' },
  { id: 'role', fullName: '角色组件联动' },
  { id: 'group', fullName: '分组组件联动' },
];
 
const jnpfKey = computed(() => unref(props.activeData).__config__?.jnpfKey);
const formFieldsOptions = computed(() => {
  if (props.activeData.selectType === 'all' || props.activeData.selectType === 'custom') return [];
  const list: any[] = [];
  const selectType = props.activeData.selectType == 'org' ? 'organize' : props.activeData.selectType;
  const loop = (data, parent?) => {
    if (!data) return;
    if (data.__config__ && isIncludesTable(data) && data.__config__.children && Array.isArray(data.__config__.children)) {
      loop(data.__config__.children, data);
    }
    if (Array.isArray(data)) data.forEach((d) => loop(d, parent));
    if (data.__vModel__ && data.__config__.jnpfKey === `${selectType}Select` && data.__vModel__ !== props.activeData.__vModel__) {
      const isTableChild = parent && parent.__config__ && parent.__config__.jnpfKey === 'table';
      list.push({
        id: isTableChild ? `${parent.__vModel__}-${data.__vModel__}` : data.__vModel__,
        fullName: isTableChild ? `${parent.__config__.label}-${data.__config__.label}` : data.__config__.label,
        ...data,
      });
    }
  };
  loop(props.drawingList);
  return list;
});
 
function isIncludesTable(data) {
  if ((!data.__config__.layout || data.__config__.layout === 'rowFormItem') && data.__config__.jnpfKey !== 'table') return true;
  if (props.activeData.__config__.isSubTable) return props.activeData.__config__.parentVModel === data.__vModel__;
  return data.__config__.jnpfKey !== 'table';
}
function onTypeChange() {
  onChange();
  props.activeData.ableIds = [];
  props.activeData.__config__.defaultCurrent = false;
  if (props.activeData.__config__.jnpfKey === 'userSelect') props.activeData.relationField = '';
}
function onChange() {
  props.activeData.__config__.defaultValue = props.activeData.multiple ? [] : '';
}
function getLabel(key) {
  if (key === 'organizeSelect') return '组织';
  if (key === 'posSelect') return '岗位';
  return '登录用户';
}
</script>
<template>
  <a-form-item label="可选范围" v-if="jnpfKey !== 'usersSelect'">
    <jnpf-select v-model:value="activeData.selectType" :options="jnpfKey === 'userSelect' ? userSelectTypeOptions : selectTypeOptions" @change="onTypeChange" />
    <template v-if="activeData.selectType === 'custom'">
      <template v-if="jnpfKey === 'organizeSelect'">
        <JnpfOrganizeSelect
          v-model:value="activeData.ableIds"
          modal-title="添加组织"
          button-type="button"
          multiple
          has-sys
          class="!mt-[10px]"
          @change="onChange" />
      </template>
      <template v-if="jnpfKey === 'posSelect'">
        <JnpfPosSelect v-model:value="activeData.ableIds" modal-title="添加岗位" button-type="button" multiple has-sys class="!mt-[10px]" @change="onChange" />
      </template>
      <template v-if="jnpfKey === 'roleSelect'">
        <JnpfRoleSelect v-model:value="activeData.ableIds" button-type="button" multiple class="!mt-[10px]" @change="onChange" />
      </template>
      <template v-if="jnpfKey === 'groupSelect'">
        <JnpfGroupSelect v-model:value="activeData.ableIds" button-type="button" multiple has-sys class="!mt-[10px]" @change="onChange" />
      </template>
      <template v-if="jnpfKey === 'userSelect'">
        <JnpfUsersSelect
          v-model:value="activeData.ableIds"
          modal-title="添加用户"
          button-type="button"
          multiple
          has-sys
          class="!mt-[10px]"
          @change="onChange" />
      </template>
    </template>
    <template v-if="jnpfKey === 'userSelect' && ['org', 'pos', 'role', 'group'].includes(activeData.selectType)">
      <jnpf-radio v-model:value="activeData.relationField" :options="formFieldsOptions" direction="vertical" class="mt-[10px]" />
    </template>
  </a-form-item>
  <a-form-item label="默认值">
    <component
      :is="activeData.__config__.tag"
      v-model:value="activeData.__config__.defaultValue"
      :multiple="activeData.multiple"
      :select-type="activeData.selectType"
      :able-ids="activeData.ableIds"
      :disabled="activeData.__config__.defaultCurrent" />
    <a-checkbox
      v-model:checked="activeData.__config__.defaultCurrent"
      class="!mt-[8px]"
      :disabled="activeData.selectType && activeData.selectType !== 'all'"
      @change="onChange"
      v-if="!['roleSelect', 'groupSelect'].includes(jnpfKey)">
      当前{{ getLabel(activeData.__config__.jnpfKey) }}
      <BasicHelp class="!ml-0" text="单选时取默认组织,多选时取当前所有组织" v-if="activeData.__config__.jnpfKey === 'organizeSelect'" />
      <BasicHelp class="!ml-0" text="单选时取默认岗位,多选时取当前所有岗位" v-if="activeData.__config__.jnpfKey === 'posSelect'" />
    </a-checkbox>
  </a-form-item>
  <a-form-item label="能否清空">
    <a-switch v-model:checked="activeData.clearable" />
  </a-form-item>
  <a-form-item label="能否多选" v-if="jnpfKey !== 'usersSelect'">
    <a-switch v-model:checked="activeData.multiple" @change="onChange" />
  </a-form-item>
</template>