ny
23 小时以前 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
<script lang="ts" setup>
import { nextTick, onMounted, ref, unref, watch } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { ESign, SignListModal } from '@jnpf/ui';
import { buildUUID } from '@jnpf/utils';
 
import { useUserStore } from '@vben/stores';
 
import { Form } from 'ant-design-vue';
 
import { $t } from '#/locales';
 
defineProps({
  lineWidth: { type: Number, default: 3 },
  isDefault: { type: Number, default: 0 },
  submitOnConfirm: { type: Boolean, default: false },
  value: { type: String, default: '' },
});
const emit = defineEmits(['register', 'update:value', 'change', 'useSignNextChange']);
defineExpose({ openModal });
const hasDrew = ref(false);
const signImg = ref('');
const eSignRef = ref(null);
const useSignNext = ref(false);
const signListModalRef = ref(null);
const confirmLoading = ref(false);
const formItemContext = Form.useInjectFormItemContext();
const { createMessage } = useMessage();
const userStore = useUserStore();
const userInfo: any = userStore.getUserInfo;
 
watch(
  () => (getESign() as unknown as Recordable)?.hasDrew,
  (val) => {
    hasDrew.value = val;
  },
);
 
function openModal() {
  confirmLoading.value = false;
  nextTick(() => {
    handleReset();
  });
}
function getESign() {
  const eSign = unref(eSignRef);
  if (!eSign) return null;
  return eSign;
}
function handleReset() {
  signImg.value = '';
  emit('update:value', '');
  emit('change', '', '');
  nextTick(() => {
    hasDrew.value = false;
    (getESign() as unknown as Recordable)?.reset();
  });
}
function openSignListModal() {
  const signListRef = unref(signListModalRef) as any;
  signListRef?.openModal(signImg.value);
}
function onConfirm(value, signId) {
  signImg.value = value;
  emit('update:value', value);
  emit('change', value, signId);
  formItemContext.onFieldChange();
}
function onDrawEnd() {
  (getESign() as unknown as Recordable)
    .generate()
    .then((res) => {
      emit('update:value', res);
      emit('change', res, buildUUID());
    })
    .catch(() => {
      createMessage.warning($t('component.jnpf.sign.signPlaceholder'));
    });
}
function onUseSignNextChange() {
  emit('useSignNextChange', useSignNext.value);
}
 
onMounted(() => {
  signImg.value = userInfo.signImg;
  emit('update:value', signImg.value);
  emit('change', signImg.value, userInfo.signId);
  nextTick(() => {
    if (!signImg.value) handleReset();
  });
});
</script>
<template>
  <div class="approval-sign-main">
    <div class="sign-main">
      <template v-if="!signImg">
        <ESign ref="eSignRef" :height="300" :width="580" :line-width="lineWidth" @draw-end="onDrawEnd" />
        <div class="tip" v-show="!hasDrew">{{ $t('component.jnpf.sign.operateTip') }}</div>
      </template>
      <img class="sign-img" :src="signImg" v-else />
    </div>
    <div class="sign-btn">
      <a-checkbox class="left-btn" v-model:checked="useSignNext" @change="onUseSignNextChange">下次继续使用此签名</a-checkbox>
      <div class="right-btn">
        <a-button type="link" @click="handleReset">清除签名</a-button>
        <a-button type="link" @click="openSignListModal">调用签名</a-button>
      </div>
    </div>
  </div>
  <SignListModal ref="signListModalRef" @confirm="onConfirm" />
</template>
<style lang="scss">
.approval-sign-main {
  width: 500px;
  background-color: var(--app-content-background);
  border: 1px solid var(--border-color-base1);
 
  .sign-main {
    position: relative;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 300px;
    overflow: hidden;
 
    .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;
    }
  }
 
  .sign-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
 
  .sign-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 54px;
    margin: 0 10px;
    border-top: 1px solid var(--border-color-base);
 
    .ant-btn {
      padding: 4px 5px;
    }
  }
}
</style>