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
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
<script lang="ts" setup>
import { nextTick, ref, unref, watch } from 'vue';
 
import { ModalClose } from '@jnpf/ui/modal';
 
import { $t } from '@vben/locales';
import { useUserStore } from '@vben/stores';
 
import { globalShareState } from '@vben-core/shared/global-state';
 
import { Modal as AModal, message } from 'ant-design-vue';
 
import vueEsign from './eSign.vue';
 
const props = defineProps({
  isDefault: { default: 0, type: Number },
  lineWidth: { default: 3, type: Number },
  submitOnConfirm: { default: false, type: Boolean },
});
const emit = defineEmits(['register', 'confirm']);
defineExpose({ openModal });
const { createSign } = globalShareState.getApi();
const hasDrew = ref(false);
const esignRef = ref(null);
const visible = ref(false);
const confirmLoading = ref(false);
const userStore = useUserStore();
 
watch(
  () => (getESign() as unknown as Recordable)?.hasDrew,
  (val) => {
    hasDrew.value = val;
  },
);
 
function openModal() {
  visible.value = true;
  confirmLoading.value = false;
  nextTick(() => {
    handleReset();
  });
}
function handleCancel() {
  visible.value = false;
}
function getESign() {
  const esign = unref(esignRef);
  if (!esign) return null;
  return esign;
}
function handleReset() {
  hasDrew.value = false;
  (getESign() as unknown as Recordable).reset();
}
function handleSubmit() {
  (getESign() as unknown as Recordable)
    .generate()
    .then((res) => {
      if (!props.submitOnConfirm) {
        emit('confirm', res);
        visible.value = false;
        return;
      }
      confirmLoading.value = true;
      const query = {
        isDefault: props.isDefault,
        signImg: res,
      };
      createSign(query)
        .then((res) => {
          if (props.isDefault == 0) {
            message.success(res.msg);
          }
          if (props.isDefault == 1 || (props.isDefault == 0 && !userStore.getUserInfo?.signImg)) {
            userStore.setUserInfo({ signImg: query.signImg });
          }
          confirmLoading.value = false;
          visible.value = false;
          emit('confirm', query.signImg);
        })
        .catch(() => {
          confirmLoading.value = false;
        });
    })
    .catch(() => {
      message.warning($t('component.jnpf.sign.signPlaceholder'));
    });
}
</script>
<template>
  <AModal
    v-model:open="visible"
    :keyboard="false"
    :mask-closable="false"
    :title="$t('component.jnpf.sign.signPlaceholder')"
    :width="600"
    centered
    class="jnpf-sign-modal">
    <template #closeIcon>
      <ModalClose :can-fullscreen="false" @cancel="handleCancel" />
    </template>
    <template #footer>
      <a-button @click="handleReset">{{ $t('common.cleanText') }}</a-button>
      <a-button :loading="confirmLoading" type="primary" @click="handleSubmit">{{ $t('common.okText') }}</a-button>
    </template>
    <div class="sign-main">
      <vue-esign ref="esignRef" :height="300" :line-width="lineWidth" :width="580" />
      <div v-show="!hasDrew" class="tip">{{ $t('component.jnpf.sign.operateTip') }}</div>
    </div>
  </AModal>
</template>
<style lang="scss">
.dark,
.dark[data-theme='custom'],
.dark[data-theme='default'] {
  .jnpf-sign-modal {
    .sign-main {
      background-color: #fff;
    }
  }
}
 
.jnpf-sign-modal {
  .ant-modal-body {
    padding: 10px !important;
  }
 
  .sign-main {
    position: relative;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 300px;
    overflow: hidden;
    background-color: var(--app-content-background);
    border: 1px solid var(--border-color-base1);
 
    .tip {
      position: absolute;
      top: 0;
      right: 0;
      left: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 300px;
      font-size: 16px;
      color: var(--text-color-secondary);
      text-align: center;
      pointer-events: none;
    }
  }
}
</style>