zhengyiming
20 小时以前 55119aeab85c9dc310ab8bc3de3091a20fa9a684
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
<template>
  <div>
    <el-divider content-position="left">系统模板参数</el-divider>
    <div class="tool-box">
      <el-tag
        v-for="(item, index) in templateParamList"
        :key="item.code"
        @click="() => addTemplateParam(item)"
        :draggable="true"
        @dragend="(ev) => addTemplateParam(item, ev)"
        class="tag-item"
        type="info"
      >
        {{ item.label }}
      </el-tag>
      <!-- <el-input
        v-if="inputVisible"
        ref="InputRef"
        v-model="inputValue"
        class="add-tag-input"
        size="small"
        @keyup.enter="handleInputConfirm"
        @blur="handleInputConfirm"
      />
      <el-button v-else class="add-tag-btn" size="small" @click="showInput" icon="Plus">
        新增
      </el-button> -->
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { InputInstance } from 'element-plus';
import { useTemplateDetailContext } from '../hooks/context';
import useSelect from '../hooks/select';
import { TemplateParam } from '@/fabric-editor/customObject';
import { Message } from '@bole-core/core';
 
defineOptions({
  name: 'systemTemplateDataParamSetting',
});
 
const { fabric, canvasEditor } = useSelect();
 
const { templateParamList, templateEditState } = useTemplateDetailContext();
 
const state = reactive({
  isDrawingLineMode: false,
  lineType: false as boolean | string,
});
 
// 默认属性
const defaultPosition = { shadow: '', fontFamily: 'arial' };
 
const addTemplateParam = (
  item: API.SelectOptionStringGetDictionaryDataSelectQueryResultOption,
  event?: DragEvent
) => {
  cancelDraw();
  const templateParam = new TemplateParam(item.label, {
    ...defaultPosition,
    fontSize: 24,
    fill: '#333333',
    textBackgroundColor: '#ffe084',
    editable: false,
 
    templateParamType: EnumContractTemplateValueType.Text,
    recorder: EnumContractTemplateValueRecorder.Creator,
    userType: EnumUserType.Personal,
    required: true,
    label: item.label,
    name: item.data?.field3,
 
    templateDataParamId: '',
    pageNum: templateEditState.currentImageIndex,
  });
 
  console.log('templateParam: ', templateParam);
  canvasEditor.addBaseType(templateParam, { center: true, event });
};
 
const endConflictTools = () => {
  canvasEditor.discardPolygon();
  canvasEditor.endDraw();
  canvasEditor.endTextPathDraw();
};
 
const ensureObjectSelEvStatus = (evented: boolean, selectable: boolean) => {
  canvasEditor.canvas.forEachObject((obj) => {
    if (obj.id !== 'workspace') {
      obj.selectable = selectable;
      obj.evented = evented;
    }
  });
};
 
const inputValue = ref('');
const inputVisible = ref(false);
const InputRef = ref<InputInstance>();
 
function handleClose(item: API.GetContractTemplateQueryResultValue) {
  templateParamList.value = templateParamList.value.filter((i) => i.label !== item.label);
}
 
const showInput = () => {
  inputVisible.value = true;
  nextTick(() => {
    InputRef.value!.input!.focus();
  });
};
 
const handleInputConfirm = () => {
  if (inputValue.value) {
    if (templateParamList.value.some((x) => x.label === inputValue.value)) {
      Message.warnMessage('已存在相同标签');
      return;
    }
    // templateParamList.value.push({
    //   label: inputValue.value,
    //   type: EnumContractTemplateValueType.Text,
    //   recorder: EnumContractTemplateValueRecorder.Creator,
    //   userType: EnumUserType.Personal,
    //   name: '',
    //   required: true,
    //   id: '',
    // });
  }
  inputVisible.value = false;
  inputValue.value = '';
};
 
// 退出绘制状态
const cancelDraw = () => {
  if (!state.isDrawingLineMode) return;
  state.isDrawingLineMode = false;
  state.lineType = '';
  canvasEditor.setMode(false);
  endConflictTools();
  ensureObjectSelEvStatus(true, true);
};
 
onDeactivated(() => {
  cancelDraw();
});
</script>
 
<style lang="scss" scoped>
@use '@/style/common.scss' as *;
 
.tool-box {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  --bole-pro-form-input-height: 0px;
 
  .tag-item {
    cursor: pointer;
  }
 
  .add-tag-btn {
    width: 60px;
    height: auto !important;
  }
 
  .add-tag-input {
    width: 60px;
    min-height: 0 !important;
  }
 
  /* span {
    margin-left: 2px;
    padding: 5px 0;
    text-align: center;
    background: #f6f6f6;
    flex: 1;
    cursor: pointer;
 
    &:hover {
      background: #edf9ff;
 
      svg {
        fill: getCssVar('color', 'primary');
      }
    }
  } */
}
</style>