edit.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. >
  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. <a @click="submitHandler">
  88. <ui-icon type="nav-edit" />
  89. 确定
  90. </a>
  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 { computed, ref } from 'vue';
  99. import { Dialog, Message } from 'bill/index';
  100. import {
  101. taggingStyles,
  102. Tagging,
  103. getTaggingStyle,
  104. TaggingStyle,
  105. taggings,
  106. isTemploraryID
  107. } from '@/store'
  108. export type EditProps = {
  109. data: Tagging
  110. }
  111. const props = defineProps<EditProps>()
  112. const emit = defineEmits<{ (e: 'quit'): void, (e: 'save', data: Tagging): void }>()
  113. const tagging = ref<Tagging>({...props.data, images: [...props.data.images]})
  114. const submitHandler = () => {
  115. if (!tagging.value.title.trim()) {
  116. Message.error('标注标题必须填写!')
  117. } else if (!tagging.value.images.length) {
  118. Message.error('至少上传一张图片!')
  119. } else {
  120. emit('save', tagging.value)
  121. }
  122. }
  123. const styles = computed(() =>
  124. [...taggingStyles.value].sort((a, b) =>
  125. a.default ? -1 : b.default ? 1 : isTemploraryID(a.id) ? -1 : isTemploraryID(b.id) ? 1 : 0
  126. )
  127. )
  128. const deleteStyle = (style: TaggingStyle) => {
  129. const index = taggingStyles.value.indexOf(style)
  130. if (~index) {
  131. taggingStyles.value.splice(index, 1)
  132. for (const item of taggings.value) {
  133. if (item.styleId === style.id) {
  134. const defaultIcon = taggingStyles.value.find(({ default: isDefault }) => isDefault)?.id
  135. if (defaultIcon) {
  136. item.styleId = defaultIcon
  137. }
  138. }
  139. }
  140. }
  141. }
  142. const uploadStyle = (style: TaggingStyle) => {
  143. taggingStyles.value.push(style)
  144. tagging.value.styleId = style.id
  145. }
  146. type LocalImageFile = { file: File; preview: string } | Tagging['images'][number]
  147. const fileChange = (file: LocalImageFile | LocalImageFile[]) => {
  148. const files = Array.isArray(file) ? file : [file]
  149. tagging.value.images = files.map(atom => {
  150. if (typeof atom === 'string' || 'blob' in atom) {
  151. return atom
  152. } else {
  153. return {
  154. blob: atom.file,
  155. url: atom.preview
  156. }
  157. }
  158. })
  159. }
  160. const delImageHandler = async (file: Tagging['images'][number]) => {
  161. const index = tagging.value.images.indexOf(file)
  162. if (~index && (await Dialog.confirm(`确定要删除此数据吗?`))) {
  163. tagging.value.images.splice(index, 1)
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .edit-hot-layer {
  169. position: fixed;
  170. inset: 0;
  171. background: rgba(0,0,0,0.3000);
  172. backdrop-filter: blur(4px);
  173. z-index: 2000;
  174. padding: 20px;
  175. overflow-y: auto;
  176. }
  177. .edit-hot-item {
  178. margin: 100px auto 20px;
  179. width: 400px;
  180. padding: 20px;
  181. background: rgba(27, 27, 28, 0.8);
  182. box-shadow: 0px 0px 10px 0px rgba(0,0,0, 0.3);
  183. border-radius: 4px;
  184. .input {
  185. margin-bottom: 10px;
  186. }
  187. }
  188. .edit-close {
  189. position: absolute;
  190. cursor: pointer;
  191. top: calc((100% - 18px) / 2);
  192. right: 0;
  193. transform: translateY(-50%);
  194. }
  195. .edit-title {
  196. padding-bottom: 18px;
  197. margin-bottom: 18px;
  198. position: relative;
  199. &::after {
  200. content: '';
  201. position: absolute;
  202. left: -20px;
  203. right: -20px;
  204. height: 1px;
  205. bottom: 0;
  206. background-color: rgba(255, 255, 255, 0.16);;
  207. }
  208. }
  209. .edit-hot {
  210. margin-top: 20px;
  211. text-align: right;
  212. span {
  213. font-size: 14px;
  214. color: rgba(255, 255, 255, 0.6);
  215. cursor: pointer;
  216. }
  217. }
  218. </style>
  219. <style>
  220. .edit-hot-item .preplace input{
  221. padding-left: 76px !important;
  222. }
  223. .edit-hot-item .preplace .pre-icon {
  224. color: rgba(255,255,255,0.6000);
  225. width: 70px;
  226. text-align: right;
  227. }
  228. </style>