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
<script lang="ts" setup>
import { computed, reactive, toRefs } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
 
import { synAllOrganizeSysToDing, synAllOrganizeSysToQy, synAllUserSysToDing, synAllUserSysToQy } from '#/api/system/sysConfig';
import { $t } from '#/locales';
 
interface State {
  synData: any;
  upLoading: boolean;
  downLoading: boolean;
}
 
const props = defineProps({
  type: {
    // 1-企业微信 2-钉钉
    default: 1,
    type: Number,
  },
  departmentId: {
    default: '',
    type: String,
  },
});
const emit = defineEmits(['register', 'update']);
 
const state = reactive<State>({
  synData: {},
  upLoading: false,
  downLoading: false,
});
const { upLoading, downLoading } = toRefs(state);
const [registerModal, { closeModal }] = useModalInner(init);
const { createConfirm, createMessage } = useMessage();
 
const getName = computed(() => (props.type === 2 ? '阿里钉钉' : '企业微信'));
 
function init(data) {
  state.synData = data;
}
// 同步
function handleSync(type) {
  createConfirm({
    iconType: 'warning',
    title: $t('common.tipTitle'),
    content: '同步以后会丢失现有数据,是否继续?',
    onOk: () => {
      type == 0 ? (state.upLoading = true) : (state.downLoading = true);
      let method = state.synData.synType == '组织' ? synAllOrganizeSysToQy : synAllUserSysToQy;
      if (props.type === 2) {
        method = state.synData.synType == '组织' ? synAllOrganizeSysToDing : synAllUserSysToDing;
      }
      method(type, props.departmentId)
        .then((res) => {
          type == 0 ? (state.upLoading = false) : (state.downLoading = false);
          closeModal();
          if (res.msg === '正在进行同步,请稍等') return createMessage.success(res.msg);
          state.synData.recordTotal = res.data.recordTotal;
          state.synData.synDate = res.data.synDate;
          state.synData.synFailCount = res.data.synFailCount;
          state.synData.synSuccessCount = res.data.synSuccessCount;
          state.synData.synType = res.data.synType;
          state.synData.unSynCount = res.data.unSynCount;
          emit('update', state.synData);
          createMessage.success('同步成功');
        })
        .catch(() => {
          type == 0 ? (state.upLoading = false) : (state.downLoading = false);
        });
    },
  });
}
</script>
 
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="数据同步" :footer="null" :width="470" class="sync-dialog">
    <div class="add-item">
      <i class="add-icon syn-icon icon-ym icon-ym-upload"></i>
      <div class="add-txt">
        <p class="add-title">同步到{{ getName }}</p>
        <p class="add-desc">把系统数据同步到{{ getName }}</p>
        <p class="add-desc">同步后,会将{{ getName }}的原有数据删除</p>
      </div>
      <a-button type="primary" @click="handleSync(0)" :loading="upLoading" :disabled="downLoading">同步</a-button>
    </div>
    <div class="add-item !mb-[40px]">
      <i class="add-icons syn-icon icon-ym icon-ym-download"></i>
      <div class="add-txt">
        <p class="add-title">同步到系统</p>
        <p class="add-desc">把{{ getName }}同步到系统</p>
        <p class="add-desc">同步后,会将系统的原有数据删除</p>
      </div>
      <a-button type="primary" @click="handleSync(1)" :loading="downLoading" :disabled="upLoading">同步</a-button>
    </div>
  </BasicModal>
</template>
<style lang="scss" scoped>
.sync-dialog {
  .add-item {
    display: flex;
    align-items: center;
    width: 100%;
    height: 100px;
    margin-bottom: 20px;
    cursor: pointer;
 
    .add-icon {
      color: #08c0f8 !important;
      background: #75d8f791 !important;
    }
 
    .syn-icon {
      flex-shrink: 0;
      width: 56px;
      height: 56px;
      margin-right: 10px;
      font-size: 30px;
      line-height: 56px;
      color: #0eac5c;
      text-align: center;
      background: #cefae2;
      border-radius: 50%;
    }
 
    .add-txt {
      flex: 1;
      height: 56px;
 
      p {
        line-height: 25px;
      }
 
      .add-title {
        margin-bottom: 6px;
        font-size: 18px;
        font-weight: bold;
      }
 
      .add-desc {
        width: 220px;
        font-size: 12px;
        color: #8d8989;
      }
    }
  }
}
</style>