edit.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div class="edit-hot-layer">
  3. <div class="edit-hot-item">
  4. <h3 class="edit-title">
  5. 标注
  6. <ui-icon type="close" ctrl @click.stop="$emit('quit')" class="edit-close" />
  7. </h3>
  8. <!-- <StylesManage
  9. :styles="styles"
  10. :active="(getTaggingStyle(tagging.styleId) as TaggingStyle)"
  11. @change="style => tagging.styleId = style.id"
  12. @delete="deleteStyle"
  13. @uploadStyles="uploadStyles"
  14. /> -->
  15. <ui-input
  16. require
  17. class="input"
  18. width="100%"
  19. placeholder="请输入热点标题"
  20. type="text"
  21. v-model="tagging.title"
  22. maxlength="15"
  23. />
  24. <ui-input
  25. class="input"
  26. width="100%"
  27. height="158px"
  28. placeholder="特征描述:"
  29. type="richtext"
  30. v-model="tagging.desc"
  31. :maxlength="200"
  32. />
  33. <ui-input
  34. class="input preplace"
  35. width="100%"
  36. placeholder=""
  37. type="text"
  38. v-model="tagging.part"
  39. >
  40. <template #preIcon><span>遗留部位:</span></template>
  41. </ui-input>
  42. <ui-input
  43. class="input preplace"
  44. width="100%"
  45. placeholder=""
  46. type="text"
  47. v-model="tagging.method"
  48. >
  49. <template #preIcon><span>提取方法:</span></template>
  50. </ui-input>
  51. <ui-input
  52. class="input preplace"
  53. width="100%"
  54. type="text"
  55. placeholder=""
  56. v-model="tagging.principal"
  57. >
  58. <template #preIcon><span>提取人:</span></template>
  59. </ui-input>
  60. <ui-input
  61. class="input "
  62. type="file"
  63. width="100%"
  64. height="225px"
  65. preview
  66. placeholder="上传图片"
  67. othPlaceholder="支持JPG、PNG图片格式,单张不超过5MB,最多支持上传9张。"
  68. accept=".jpg, .png"
  69. :disable="true"
  70. :multiple="true"
  71. :maxSize="5 * 1024 * 1024"
  72. :maxLen="9"
  73. :modelValue="tagging.images"
  74. @update:modelValue="fileChange"
  75. >
  76. <template v-slot:valuable>
  77. <Images :tagging="tagging" :hideInfo="true">
  78. <template v-slot:icons="{ active }">
  79. <span @click="delImageHandler(active)" class="del-file">
  80. <ui-icon type="del" ctrl />
  81. </span>
  82. </template>
  83. </Images>
  84. </template>
  85. </ui-input>
  86. <div class="edit-hot" >
  87. <span @click="submitHandler" class="fun-ctrl">
  88. <ui-icon type="edit" />
  89. 确定
  90. </span>
  91. </div>
  92. </div>
  93. </div>
  94. </template>
  95. <script lang="ts" setup>
  96. // import StylesManage from './styles.vue'
  97. import Images from './images.vue'
  98. // import { LocalTaggingStyle } from './styles.vue'
  99. import { computed, ref } from 'vue';
  100. import { Dialog, Message } from 'bill/index';
  101. import {
  102. // taggingStyles,
  103. Tagging,
  104. Taggings,
  105. // TemploraryID,
  106. // getTaggingStyle,
  107. // TaggingStyle,
  108. // taggings
  109. } from '@/store'
  110. export type EditProps = {
  111. // taggingFiles: WeakMap<Tagging, Array<File>>
  112. // styleFile: WeakMap<TaggingStyle, File>
  113. data: Tagging
  114. }
  115. const props = defineProps<EditProps>()
  116. const emit = defineEmits<{ (e: 'quit'): void, (e: 'save', data: Tagging): void }>()
  117. const tagging = ref<Tagging>({...props.data, images: [...props.data.images]})
  118. const submitHandler = () => {
  119. if (!tagging.value.title.trim()) {
  120. Message.error('标注标题必须填写!')
  121. } else {
  122. emit('save', tagging.value)
  123. }
  124. }
  125. // const styles = computed(() =>
  126. // [...taggingStyles.value].sort((a, b) =>
  127. // a.default ? -1 : b.default ? 1 : a.id === TemploraryID ? -1 : b.id === TemploraryID ? 1 : 0
  128. // )
  129. // )
  130. // const deleteStyle = (style: TaggingStyle) => {
  131. // const index = taggingStyles.value.indexOf(style)
  132. // if (~index) {
  133. // taggingStyles.value.splice(index, 1)
  134. // for (const item of taggings.value) {
  135. // if (item.styleId === style.id) {
  136. // const defaultIcon = taggingStyles.value.find(({ default: isDefault }) => isDefault)?.id
  137. // if (defaultIcon) {
  138. // item.styleId = defaultIcon
  139. // }
  140. // }
  141. // }
  142. // }
  143. // }
  144. // const normalizeIcon = (icon: LocalTaggingStyle['icon'] | string): string => {
  145. // if (typeof icon === 'string') {
  146. // return icon
  147. // } else {
  148. // return icon.preview
  149. // }
  150. // }
  151. // const uploadStyles = (unStyles: Array<LocalTaggingStyle>) => {
  152. // const addStyles = unStyles.map(item => {
  153. // const style = {
  154. // ...item,
  155. // icon: normalizeIcon(item.icon),
  156. // }
  157. // props.styleFile.set(style, item.icon.file)
  158. // return style
  159. // })
  160. // styles.value.push(...addStyles)
  161. // tagging.value.styleId = addStyles[0].id
  162. // }
  163. type LocalImageFile = { file: File; preview: string } | Tagging['images'][number]
  164. const fileChange = (file: LocalImageFile | LocalImageFile[]) => {
  165. const files = Array.isArray(file) ? file : [file]
  166. tagging.value.images = files.map(atom => {
  167. if (typeof atom === 'string' || 'blob' in atom) {
  168. return atom
  169. } else {
  170. console.log(atom)
  171. return {
  172. blob: atom.file,
  173. url: atom.preview
  174. }
  175. }
  176. })
  177. }
  178. const delImageHandler = async (file: Tagging['images'][number]) => {
  179. const index = tagging.value.images.indexOf(file)
  180. if (~index && (await Dialog.confirm(`确定要删除此数据吗?`))) {
  181. tagging.value.images.splice(index, 1)
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .edit-hot-layer {
  187. position: fixed;
  188. inset: 0;
  189. background: rgba(0,0,0,0.3000);
  190. backdrop-filter: blur(4px);
  191. z-index: 2000;
  192. }
  193. .edit-hot-item {
  194. position: absolute;
  195. top: 50%;
  196. left: 50%;
  197. transform: translate(-50%, -50%);
  198. width: 400px;
  199. position: relative;
  200. padding: 20px;
  201. background: rgba(27, 27, 28, 0.8);
  202. box-shadow: 0px 0px 10px 0px rgba(0,0,0, 0.3);
  203. border-radius: 4px;
  204. .input {
  205. margin-bottom: 10px;
  206. }
  207. }
  208. .edit-close {
  209. position: absolute;
  210. cursor: pointer;
  211. top: calc((100% - 18px) / 2);
  212. right: 0;
  213. transform: translateY(-50%);
  214. }
  215. .edit-title {
  216. padding-bottom: 18px;
  217. margin-bottom: 18px;
  218. position: relative;
  219. &::after {
  220. content: '';
  221. position: absolute;
  222. left: -20px;
  223. right: -20px;
  224. height: 1px;
  225. bottom: 0;
  226. background-color: rgba(255, 255, 255, 0.16);;
  227. }
  228. }
  229. .edit-hot {
  230. margin-top: 20px;
  231. text-align: right;
  232. span {
  233. font-size: 14px;
  234. color: rgba(255, 255, 255, 0.6);
  235. cursor: pointer;
  236. }
  237. }
  238. </style>
  239. <style>
  240. .edit-hot-item .preplace input{
  241. padding-left: 76px !important;
  242. }
  243. .edit-hot-item .preplace .pre-icon {
  244. color: rgba(255,255,255,0.6000);
  245. width: 70px;
  246. text-align: right;
  247. }
  248. </style>