ny
昨天 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
<script lang="ts" setup>
import { onMounted, reactive, toRefs } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { useModal } from '@jnpf/ui/modal';
 
import { LoadingOutlined } from '@ant-design/icons-vue';
import dayjs from 'dayjs';
 
import { getOrganizeSyncList } from '#/api/permission/organize';
import { clearAllSyn, getSocialsConfig, getSynData, testDing, updateSocialsConfig } from '#/api/system/sysConfig';
import { $t } from '#/locales';
 
import CountModal from './CountModal.vue';
import SyncModal from './SyncModal.vue';
 
interface State {
  baseForm: any;
  btnLoading: boolean;
  testDingLoading: boolean;
  eventsColumns: any[];
  resultsColumns: any[];
  eventsList: any[];
  resultsList: any[];
  synData: any;
  orgOptions: any[];
}
 
defineOptions({ name: 'IntegrationCenterDingTalk' });
 
const state = reactive<State>({
  baseForm: {},
  btnLoading: false,
  testDingLoading: false,
  eventsColumns: [
    { title: '', dataIndex: 'select', width: 50, align: 'center' },
    { title: '触发事件', dataIndex: 'title' },
    { title: '描述', dataIndex: 'desc' },
  ],
  resultsColumns: [
    { title: '同步类型', dataIndex: 'synType' },
    { title: '总数', dataIndex: 'recordTotal' },
    { title: '同步成功数', dataIndex: 'synSuccessCount' },
    { title: '同步失败数', dataIndex: 'synFailCount' },
    { title: '未同步数', dataIndex: 'unSynCount' },
    { title: '同步时间', dataIndex: 'synDate' },
    { title: '操作', dataIndex: 'action', width: 50 },
  ],
  eventsList: [
    { select: false, title: '启用同步组织', desc: '新增、删除、修改组织信息触发同步组织事件' },
    { select: false, title: '启用同步用户', desc: '新增、删除、修改用户信息触发同步用户事件' },
  ],
  resultsList: [
    { recordTotal: '', synDate: '', synFailCount: '', synSuccessCount: '', synType: '组织', unSynCount: '' },
    { recordTotal: '', synDate: '', synFailCount: '', synSuccessCount: '', synType: '用户', unSynCount: '' },
  ],
  synData: {},
  orgOptions: [],
});
const { baseForm, btnLoading, testDingLoading, eventsColumns, resultsColumns, eventsList, resultsList, orgOptions } = toRefs(state);
const { createConfirm, createMessage } = useMessage();
const [registerModal, { openModal }] = useModal();
const [registerCountModal, { openModal: openCountModal }] = useModal();
 
function initData() {
  state.testDingLoading = false;
  getOrgOptions();
  getSocialsConfigs();
  getSynDataFun(2);
}
function getSocialsConfigs() {
  getSocialsConfig().then((res) => {
    state.baseForm = res.data;
    state.eventsList[0].select = !!state.baseForm.dingSynIsSynOrg;
    state.eventsList[1].select = !!state.baseForm.dingSynIsSynUser;
  });
}
function getOrgOptions() {
  getOrganizeSyncList({ parentId: '0' }).then((res) => {
    state.orgOptions = res.data.list || [];
  });
}
function handleRelieve() {
  if (state.btnLoading) return;
  createConfirm({
    iconType: 'warning',
    title: '解除确认',
    content: '确定解除当前选中组织的同步关系?',
    onOk: () => {
      clearAllSyn(2).then((res) => {
        createMessage.success(res.msg);
        initData();
      });
    },
  });
}
function handleSubmit() {
  state.baseForm.dingSynIsSynOrg = state.eventsList[0].select ? 1 : 0;
  state.baseForm.dingSynIsSynUser = state.eventsList[1].select ? 1 : 0;
  createConfirm({
    iconType: 'warning',
    title: $t('common.tipTitle'),
    content: '您确定要保存,是否继续?',
    onOk: () => {
      state.btnLoading = true;
      updateSocialsConfig(state.baseForm)
        .then((res) => {
          createMessage.success(res.msg);
          state.btnLoading = false;
          initData();
        })
        .catch(() => {
          state.btnLoading = false;
        });
    },
  });
}
 
function checkDing() {
  state.testDingLoading = true;
  const data = {
    dingAgentId: state.baseForm.dingAgentId,
    dingSynAppKey: state.baseForm.dingSynAppKey,
    dingSynAppSecret: state.baseForm.dingSynAppSecret,
  };
  testDing(data)
    .then((res) => {
      createMessage.success(res.msg);
      state.testDingLoading = false;
    })
    .catch(() => {
      state.testDingLoading = false;
    });
}
function handleSync(record) {
  if (!state.baseForm.dingDepartment) return createMessage.warning('请选择组织');
  if (!state.baseForm.dingDisabled && record.synType != '组织') return createMessage.warning('请先同步组织数据');
  state.synData = record;
  openModal(true, state.synData);
}
function getSynDataFun(type) {
  getSynData(type).then((res) => {
    state.resultsList = res.data.map((o) => ({ loading: false, ...o }));
  });
}
function updateSyncData(data) {
  state.synData = data;
  getSocialsConfigs();
}
function handleFailCount(record, resultType, count) {
  if (!count) return;
  const synType = record.synType == '组织' ? 1 : 2;
  openCountModal(true, { synType, resultType });
}
 
onMounted(() => {
  initData();
});
</script>
<template>
  <div class="jnpf-content-wrapper">
    <div class="jnpf-content-wrapper-center !overflow-auto bg-white">
      <a-form :colon="false" label-align="right" :label-col="{ style: { width: '80px' } }" class="right-board-form h-full !p-[30px]">
        <JnpfGroupTitle class="-mt-[20px] mb-[20px]" content="钉钉同步配置" />
        <a-row :gutter="20">
          <a-col :span="12" :offset="6" :pull="6">
            <a-form-item label="企业号Id">
              <a-input v-model:value="baseForm.dingAgentId" allow-clear placeholder="请输入AgentId" />
            </a-form-item>
          </a-col>
          <a-col :span="12" :offset="6" :pull="6">
            <a-form-item label="应用凭证">
              <a-input v-model:value="baseForm.dingSynAppKey" allow-clear placeholder="请输入AppKey" />
            </a-form-item>
          </a-col>
          <a-col :span="12" :offset="6" :pull="6">
            <a-form-item label="凭证密钥">
              <a-input v-model:value="baseForm.dingSynAppSecret" allow-clear placeholder="请输入AppSecret">
                <template #addonAfter>
                  <LoadingOutlined class="mr-[5px]" v-if="testDingLoading" />
                  <span class="cursor-pointer" @click="checkDing">连接测试</span>
                </template>
              </a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12" :offset="6" :pull="6">
            <a-form-item label="同步反馈">
              <div :class="{ 'mr-[-90px] flex': baseForm.dingDisabled }">
                <JnpfSelect v-model:value="baseForm.dingDepartment" :options="orgOptions" allow-clear show-search :disabled="!!baseForm.dingDisabled" />
                <a-button type="link" color="error" class="ml-[2px]" v-if="baseForm.dingDisabled" @click="handleRelieve">解除同步</a-button>
              </div>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label=" ">
              <div class="mb-[10px] mt-[-12px]">选择一个组织作为最高级组织进行数据同步,同步成功后该组织不可修改。</div>
              <a-table bordered :data-source="resultsList" :columns="resultsColumns" :pagination="false" size="small">
                <template #bodyCell="{ column, record }">
                  <template v-if="column.dataIndex === 'synFailCount'">
                    <p :class="{ 'link-text': record.synFailCount }" @click="handleFailCount(record, 2, record.synFailCount)">
                      {{ record[column.dataIndex] }}
                    </p>
                  </template>
                  <template v-if="column.dataIndex === 'unSynCount'">
                    <p :class="{ 'link-text': record.unSynCount }" @click="handleFailCount(record, 0, record.unSynCount)">
                      {{ record[column.dataIndex] }}
                    </p>
                  </template>
                  <template v-if="column.dataIndex === 'synDate'">
                    <p>{{ record.synDate ? dayjs(record.synDate).format('YYYY-MM-DD HH:mm:ss') : '' }}</p>
                  </template>
                  <template v-if="column.dataIndex === 'action'">
                    <a-button class="action-btn" type="link" @click="handleSync(record)" size="small">同步</a-button>
                  </template>
                </template>
              </a-table>
            </a-form-item>
          </a-col>
        </a-row>
        <a-form-item label="触发事件">
          <a-table bordered :data-source="eventsList" :columns="eventsColumns" :pagination="false" size="small">
            <template #bodyCell="{ column, record }">
              <template v-if="column.dataIndex === 'select'">
                <a-checkbox v-model:checked="record.select" />
              </template>
            </template>
          </a-table>
        </a-form-item>
        <a-form-item label=" ">
          <a-button type="primary" @click.prevent="handleSubmit" :loading="btnLoading">保存</a-button>
        </a-form-item>
      </a-form>
    </div>
    <SyncModal :type="2" :department-id="baseForm.dingDepartment" @register="registerModal" @update="updateSyncData" />
    <CountModal :type="2" @register="registerCountModal" />
  </div>
</template>