edit.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. @uploadStyle="uploadStyle"
  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. :maxlength="60"
  40. >
  41. <template #preIcon><span>遗留部位:</span></template>
  42. </ui-input>
  43. <ui-input
  44. class="input preplace"
  45. width="100%"
  46. placeholder=""
  47. type="text"
  48. v-model="tagging.method"
  49. :maxlength="60"
  50. >
  51. <template #preIcon><span>提取方法:</span></template>
  52. </ui-input>
  53. <ui-input
  54. class="input preplace"
  55. width="100%"
  56. type="text"
  57. placeholder=""
  58. v-model="tagging.principal"
  59. :maxlength="60"
  60. >
  61. <template #preIcon><span>提取人:</span></template>
  62. </ui-input>
  63. <ui-input
  64. class="input "
  65. type="file"
  66. width="100%"
  67. height="225px"
  68. require
  69. preview
  70. placeholder="上传图片"
  71. othPlaceholder="支持JPG、PNG图片格式,单张不超过5MB,最多支持上传9张。"
  72. accept=".jpg, .png"
  73. :disable="true"
  74. :multiple="true"
  75. :maxSize="5 * 1024 * 1024"
  76. :maxLen="9"
  77. :modelValue="tagging.images"
  78. @update:modelValue="fileChange"
  79. >
  80. <template v-slot:valuable>
  81. <Images :tagging="tagging" :hideInfo="true">
  82. <template v-slot:icons="{ active }">
  83. <span @click="delImageHandler(active)" class="del-file">
  84. <ui-icon type="del" ctrl />
  85. </span>
  86. </template>
  87. </Images>
  88. </template>
  89. </ui-input>
  90. <div class="edit-hot" >
  91. <a @click="submitHandler">
  92. <ui-icon type="nav-edit" />
  93. 确定
  94. </a>
  95. </div>
  96. </div>
  97. </div>
  98. </template>
  99. <script lang="ts" setup>
  100. import StylesManage from './styles.vue'
  101. import Images from './images.vue'
  102. import { computed, ref } from 'vue';
  103. import { Dialog, Message } from 'bill/index';
  104. import {
  105. taggingStyles,
  106. Tagging,
  107. getTaggingStyle,
  108. TaggingStyle,
  109. taggings,
  110. isTemploraryID
  111. } from '@/store'
  112. export type EditProps = {
  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 if (!tagging.value.images.length) {
  122. Message.error('至少上传一张图片!')
  123. } else {
  124. emit('save', tagging.value)
  125. }
  126. }
  127. const styles = computed(() =>
  128. [...taggingStyles.value].sort((a, b) =>
  129. a.default ? -1 : b.default ? 1 :
  130. a.lastUse ? -1 : b.lastUse ? 1 : isTemploraryID(a.id) ? -1 : isTemploraryID(b.id) ? 1 : 0
  131. )
  132. )
  133. const deleteStyle = (style: TaggingStyle) => {
  134. const index = taggingStyles.value.indexOf(style)
  135. if (~index) {
  136. taggingStyles.value.splice(index, 1)
  137. for (const item of taggings.value) {
  138. if (item.styleId === style.id) {
  139. const defaultIcon = taggingStyles.value.find(({ default: isDefault }) => isDefault)?.id
  140. if (defaultIcon) {
  141. item.styleId = defaultIcon
  142. }
  143. }
  144. }
  145. }
  146. }
  147. const uploadStyle = (style: TaggingStyle) => {
  148. taggingStyles.value.push(style)
  149. tagging.value.styleId = style.id
  150. }
  151. type LocalImageFile = { file: File; preview: string } | Tagging['images'][number]
  152. const fileChange = (file: LocalImageFile | LocalImageFile[]) => {
  153. const files = Array.isArray(file) ? file : [file]
  154. tagging.value.images = files.map(atom => {
  155. if (typeof atom === 'string' || 'blob' in atom) {
  156. return atom
  157. } else {
  158. return {
  159. blob: atom.file,
  160. url: atom.preview
  161. }
  162. }
  163. })
  164. }
  165. const delImageHandler = async (file: Tagging['images'][number]) => {
  166. const index = tagging.value.images.indexOf(file)
  167. if (~index && (await Dialog.confirm(`确定要删除此数据吗?`))) {
  168. tagging.value.images.splice(index, 1)
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .edit-hot-layer {
  174. position: fixed;
  175. inset: 0;
  176. background: rgba(0,0,0,0.3000);
  177. backdrop-filter: blur(4px);
  178. z-index: 2000;
  179. padding: 20px;
  180. overflow-y: auto;
  181. }
  182. .edit-hot-item {
  183. margin: 100px auto 20px;
  184. width: 400px;
  185. padding: 20px;
  186. background: rgba(27, 27, 28, 0.8);
  187. box-shadow: 0px 0px 10px 0px rgba(0,0,0, 0.3);
  188. border-radius: 4px;
  189. .input {
  190. margin-bottom: 10px;
  191. }
  192. }
  193. .edit-close {
  194. position: absolute;
  195. cursor: pointer;
  196. top: calc((100% - 18px) / 2);
  197. right: 0;
  198. transform: translateY(-50%);
  199. }
  200. .edit-title {
  201. padding-bottom: 18px;
  202. margin-bottom: 18px;
  203. position: relative;
  204. &::after {
  205. content: '';
  206. position: absolute;
  207. left: -20px;
  208. right: -20px;
  209. height: 1px;
  210. bottom: 0;
  211. background-color: rgba(255, 255, 255, 0.16);;
  212. }
  213. }
  214. .edit-hot {
  215. margin-top: 20px;
  216. text-align: right;
  217. span {
  218. font-size: 14px;
  219. color: rgba(255, 255, 255, 0.6);
  220. cursor: pointer;
  221. }
  222. }
  223. </style>
  224. <style>
  225. .edit-hot-item .preplace input{
  226. padding-left: 76px !important;
  227. }
  228. .edit-hot-item .preplace .pre-icon {
  229. color: rgba(255,255,255,0.6000);
  230. width: 70px;
  231. text-align: right;
  232. }
  233. </style>
  234. <style>
  235. .edit-hot-layer .input.ui-input .text.suffix input {
  236. padding-right: 60px;
  237. }
  238. </style>