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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
<script setup lang="ts">
import type { ActionItem, BasicColumn } from '@jnpf/ui/vxeTable';
import type { FormInstance } from 'ant-design-vue';
 
import { onMounted, reactive, ref, toRefs, unref } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { getBase64WithFile, SignModal } from '@jnpf/ui';
import { useModal } from '@jnpf/ui/modal';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { useUserStore } from '@vben/stores';
 
import { CheckOutlined } from '@ant-design/icons-vue';
 
import { createSign, deleteSign, getSignList, updateDefaultSign, updateUserInfo } from '#/api/permission/userSetting';
import { delCommonWords, getCommonWordsList } from '#/api/system/commonWords';
import { $t } from '#/locales';
import { useBaseStore } from '#/store';
import Form from '#/views/templateCenter/commonWords/Form.vue';
 
interface State {
  activeKey: string;
  educationOptions: any[];
  certificatesTypeOptions: any[];
  genderOptions: any[];
  nationOptions: any[];
  signList: any[];
  userForm: any;
  userFormRule: any;
}
 
const props = defineProps({
  user: { type: Object, default: () => ({}) },
});
const emit = defineEmits(['updateInfo']);
const baseStore = useBaseStore();
const userStore = useUserStore();
const { createMessage } = useMessage();
const userFormElRef = ref<FormInstance>();
const signModalRef = ref(null);
const state = reactive<State>({
  activeKey: '1',
  educationOptions: [],
  certificatesTypeOptions: [],
  genderOptions: [],
  nationOptions: [],
  signList: [],
  userForm: {
    realName: '',
    signature: '',
    gender: 1,
    nation: '',
    nativePlace: '',
    certificatesType: '',
    certificatesNumber: '',
    education: '',
    birthday: null,
    telePhone: '',
    landline: '',
    urgentContacts: '',
    urgentTelePhone: '',
    postalAddress: '',
  },
  userFormRule: {
    realName: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
  },
});
const { activeKey, userForm, educationOptions, certificatesTypeOptions, genderOptions, nationOptions } = toRefs(state);
const columns: BasicColumn[] = [
  { title: '常用语', dataIndex: 'commonWordsText' },
  { title: '使用次数', dataIndex: 'usesNum', width: 80, align: 'center' },
  { title: '状态', dataIndex: 'enabledMark', width: 80, align: 'center', slots: { default: 'enabledMark' } },
];
const [registerForm, { openModal: openFormModal }] = useModal();
const [registerTable, { reload }] = useVxeTable({
  api: getCommonWordsList,
  searchInfo: { commonWordsType: 1 },
  columns,
  actionColumn: {
    width: 100,
    title: '操作',
    dataIndex: 'action',
  },
});
 
async function getOptions() {
  const educationRes = (await baseStore.getDictionaryData('Education')) as any;
  state.educationOptions = educationRes;
  const certificateTypeRes = (await baseStore.getDictionaryData('certificateType')) as any;
  state.certificatesTypeOptions = certificateTypeRes;
  const sexRes = (await baseStore.getDictionaryData('sex')) as any;
  state.genderOptions = sexRes;
  const nationRes = (await baseStore.getDictionaryData('Nation')) as any;
  state.nationOptions = nationRes;
}
function getInfo() {
  for (const key of Object.keys(state.userForm)) {
    state.userForm[key] = props.user[key];
  }
}
function getSign() {
  getSignList().then((res) => {
    state.signList = res.data || [];
  });
}
async function handleSubmit() {
  try {
    const values = await userFormElRef.value?.validate();
    if (!values) return;
    updateUserInfo(state.userForm).then((res) => {
      createMessage.success(res.msg);
      emit('updateInfo');
      userStore.setUserInfo({ userName: state.userForm.realName });
    });
  } catch {}
}
function openSignModal() {
  const signRef = unref(signModalRef) as any;
  signRef?.openModal();
}
function beforeUpload(file: File) {
  const isAccept = /image\/*/.test(file.type);
  if (!isAccept) {
    createMessage.error(`请上传图片`);
    return;
  }
  if (file.size / 1024 > 500) {
    createMessage.error('操作失败,图片大小超出500K');
    return;
  }
  getBase64WithFile(file).then(({ result: thumbUrl }) => {
    addSign(thumbUrl);
  });
  return false;
}
function addSign(signImg) {
  const query = {
    signImg,
    isDefault: 0,
  };
  createSign(query).then((res) => {
    createMessage.success(res.msg);
    getSign();
  });
}
function updateDefault(id, signImg) {
  updateDefaultSign(id)
    .then((res) => {
      createMessage.success(res.msg);
      userStore.setUserInfo({ signImg });
      getSign();
    })
    .catch((_) => {
      getSign();
    });
}
function delSign(id) {
  deleteSign(id).then((res) => {
    createMessage.success(res.msg);
    getSign();
  });
}
function getTableActions(record): ActionItem[] {
  return [
    {
      label: $t('common.editText'),
      onClick: addOrUpdateHandle.bind(null, record.id),
    },
    {
      label: $t('common.delText'),
      color: 'error',
      modelConfirm: {
        onOk: handleDelete.bind(null, record.id),
      },
    },
  ];
}
function addOrUpdateHandle(id = '') {
  openFormModal(true, { id, commonWordsType: 1 });
}
function handleDelete(id) {
  delCommonWords(id).then((res) => {
    createMessage.success(res.msg);
    reload();
  });
}
 
onMounted(() => {
  getOptions();
  getInfo();
  getSign();
});
</script>
 
<template>
  <a-tabs v-model:active-key="activeKey" class="userInfo-tabs">
    <a-tab-pane key="1" tab="个人资料">
      <a-form
        :colon="false"
        label-align="right"
        :model="userForm"
        :rules="state.userFormRule"
        ref="userFormElRef"
        :label-col="{ style: { width: '100px' } }"
        class="pt-[10px]">
        <a-row>
          <a-col :span="12">
            <a-form-item label="姓名" name="realName">
              <a-input v-model:value="userForm.realName" :maxlength="50" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="性别">
              <jnpf-select v-model:value="userForm.gender" :options="genderOptions" placeholder="请选择" :field-names="{ value: 'enCode' }" show-search />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="民族">
              <jnpf-select v-model:value="userForm.nation" :options="nationOptions" placeholder="请选择" show-search />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="籍贯">
              <a-input v-model:value="userForm.nativePlace" :maxlength="50" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="证件类型">
              <jnpf-select v-model:value="userForm.certificatesType" :options="certificatesTypeOptions" placeholder="请选择" show-search />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="证件号码">
              <a-input v-model:value="userForm.certificatesNumber" :maxlength="50" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="文化程度">
              <jnpf-select v-model:value="userForm.education" :options="educationOptions" placeholder="请选择" show-search />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="出生年月">
              <jnpf-date-picker v-model:value="userForm.birthday" placeholder="请选择" format="YYYY-MM-DD" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="办公电话">
              <a-input v-model:value="userForm.telePhone" :maxlength="20" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="办公座机">
              <a-input v-model:value="userForm.landline" :maxlength="50" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="紧急联系">
              <a-input v-model:value="userForm.urgentContacts" :maxlength="50" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="紧急电话">
              <a-input v-model:value="userForm.urgentTelePhone" :maxlength="50" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="通讯地址">
              <a-input v-model:value="userForm.postalAddress" :maxlength="300" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="自我介绍">
              <jnpf-textarea v-model:value="userForm.signature" :maxlength="300" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label=" ">
              <a-button type="primary" @click="handleSubmit">保存</a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-tab-pane>
    <a-tab-pane key="2" tab="个人签名">
      <a-row class="sign-list" :gutter="40">
        <a-col :span="6" class="sign-item add-sign">
          <div class="sign-item-main">
            <a-dropdown trigger="click">
              <i class="add-icon icon-ym icon-ym-btn-add" @click.prevent></i>
              <template #overlay>
                <a-menu>
                  <a-menu-item key="1" @click="openSignModal">在线签名</a-menu-item>
                  <a-menu-item key="3">
                    <a-upload :show-upload-list="false" accept="image/*" :before-upload="beforeUpload">
                      <div>图片上传</div>
                    </a-upload>
                  </a-menu-item>
                </a-menu>
              </template>
            </a-dropdown>
          </div>
        </a-col>
        <a-col :span="6" class="sign-item" :key="i" v-for="(item, i) in state.signList">
          <div :class="item.isDefault ? 'sign-item-main active' : 'sign-item-main'">
            <img :src="item.signImg" alt="" class="sign-img" />
            <div class="icon-checked" v-if="item.isDefault">
              <CheckOutlined />
            </div>
            <div v-if="!item.isDefault" class="add-button">
              <a-button size="small" @click="delSign(item.id)" class="mr-[10px]">删除</a-button>
              <a-button size="small" type="primary" @click="updateDefault(item.id, item.signImg)">设为默认</a-button>
            </div>
          </div>
        </a-col>
      </a-row>
    </a-tab-pane>
    <a-tab-pane key="3" tab="审批常用语" class="!p-0">
      <BasicVxeTable @register="registerTable">
        <template #tableTitle>
          <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="addOrUpdateHandle()">{{ $t('common.addText') }}</a-button>
        </template>
        <template #enabledMark="{ record }">
          <a-tag :color="record.enabledMark == 1 ? 'success' : 'error'">{{ record.enabledMark == 1 ? '启用' : '禁用' }}</a-tag>
        </template>
        <template #action="{ record }">
          <TableAction :actions="getTableActions(record)" />
        </template>
      </BasicVxeTable>
    </a-tab-pane>
  </a-tabs>
  <SignModal ref="signModalRef" submit-on-confirm @confirm="getSign" />
  <Form @register="registerForm" @reload="reload" />
</template>
<style lang="scss" scoped>
.userInfo-tabs {
  height: 100%;
 
  :deep(.ant-tabs-nav) {
    margin: 0;
  }
 
  :deep(.ant-tabs-content-holder) {
    height: calc(100% - 66px);
    overflow: auto;
 
    .ant-tabs-content {
      height: 100%;
    }
  }
 
  .ant-tabs-tabpane {
    padding: 10px;
    overflow-x: hidden;
  }
}
 
.sign-list {
  padding: 20px 50px 0;
 
  .sign-item {
    margin-bottom: 20px;
 
    .sign-item-main {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 160px;
      overflow: hidden;
      cursor: pointer;
      background-color: #fff;
      border-radius: 10px;
 
      .icon-checked {
        position: absolute;
        right: -1px;
        bottom: -1px;
        display: block;
        width: 16px;
        height: 16px;
        border: 16px solid var(--primary-color);
        border-top: 16px solid transparent !important;
        border-left: 16px solid transparent !important;
        border-bottom-right-radius: 10px;
 
        .anticon-check {
          position: absolute;
          top: -1px;
          left: -1px;
          font-size: 14px;
          color: #fff;
        }
      }
 
      &.active {
        color: var(--primary-color);
        border: 1px solid var(--primary-color);
        box-shadow: 0 0 6px rgb(6 58 108 / 26%);
      }
 
      &:hover {
        .add-button {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 100%;
          height: 100%;
          background-color: rgb(157 158 159 / 80%);
          border-radius: 10px;
        }
      }
 
      .add-button {
        position: absolute;
        display: none;
      }
 
      .add-icon {
        font-size: 50px;
        color: var(--text-color-secondary);
      }
 
      .sign-img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>