km-upload-img.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <div>
  3. <div :class="$style.coverimgs" @click="handleSetImg">
  4. <div v-if="value === ''" :class="$style.noimg">
  5. 暂无封面
  6. </div>
  7. <img
  8. v-else
  9. :src="(`api/flow-mobile/v1/task-form-process/download-attachments/` + value) | sdResource"
  10. :class="$style.uploadImg"
  11. />
  12. <div v-if="!readOnly" :class="$style.imgMask">设置封面</div>
  13. </div>
  14. <a-modal v-model="visible" title="封面设置" width="50%" @ok="handleOk">
  15. <a-tabs default-active-key="1">
  16. <a-tab-pane key="1" tab="本地上传">
  17. <sd-attachment
  18. accept=".gif,.png,.jpg,.jpeg"
  19. :max="1"
  20. list-type="picture-card"
  21. :group-id="groupId"
  22. :selected-keys.sync="uploadActiveCode"
  23. @change="change"
  24. />
  25. </a-tab-pane>
  26. <a-tab-pane key="2" tab="系统推荐" force-render>
  27. <a-empty v-if="systemImgData.length === 0" />
  28. <div v-else id="listPicture" class="ant-upload-list-picture-card">
  29. <div
  30. v-for="item in systemImgData"
  31. :key="item.code"
  32. class="ant-upload-list-picture-card-container"
  33. :class="{ [$style.checked]: activeCode && activeCode.includes(item.code) }"
  34. @click="handleImg(item)"
  35. ><div
  36. class="ant-upload-list-item ant-upload-list-item-done ant-upload-list-item-list-type-picture-card"
  37. ><div class="ant-upload-list-item-info">
  38. <a class="ant-upload-list-item-thumbnail">
  39. <img
  40. :src="
  41. (`api/flow-mobile/v1/task-form-process/download-attachments/` + item.code)
  42. | sdResource
  43. "
  44. class="ant-upload-list-item-image"/></a
  45. ></div>
  46. <span class="ant-upload-list-item-actions"
  47. ><a
  48. :href="
  49. (`api/flow-mobile/v1/task-form-process/download-attachments/` + item.code)
  50. | sdResource
  51. "
  52. target="_blank"
  53. @click.stop="() => {}"
  54. >
  55. <a-icon type="eye-o" />
  56. </a>
  57. </span>
  58. </div>
  59. </div>
  60. </div>
  61. </a-tab-pane>
  62. </a-tabs>
  63. </a-modal>
  64. </div>
  65. </template>
  66. <script>
  67. import PageService from '@/common/services/page-service'
  68. import KmKnowledageService from '../km-knowledage-service'
  69. import components from './_import-components/km-upload-img-import'
  70. export default {
  71. name: 'KmUploadImg',
  72. metaInfo: {
  73. title: 'OaUploadImg',
  74. },
  75. components,
  76. model: {
  77. prop: 'value',
  78. event: 'change',
  79. },
  80. props: {
  81. // 图片code
  82. value: {
  83. required: true,
  84. type: String,
  85. default: '',
  86. },
  87. // 自定义封面附件groupId
  88. groupId: {
  89. required: true,
  90. type: String,
  91. default: '',
  92. },
  93. /**
  94. * 只读
  95. */
  96. readOnly: {
  97. required: true,
  98. type: Boolean,
  99. default: false,
  100. },
  101. },
  102. data() {
  103. return {
  104. visible: false,
  105. systemImgData: [],
  106. uploadActiveCode: [], // 自定义上传的图片code
  107. activeCode: [], // 系统预置选中的图片coede
  108. }
  109. },
  110. created() {
  111. if (!this.readOnly) {
  112. this.queryCoverImg()
  113. }
  114. },
  115. methods: {
  116. // 获取系统预置的封面图片
  117. queryCoverImg() {
  118. const params = {
  119. columns: 'id,coverImage',
  120. maxResults: -1,
  121. startPosition: 0,
  122. expressions: [],
  123. formId: 'kmKnowledgeCover',
  124. }
  125. PageService.getList(params).then((res) => {
  126. if (res.data.data.length > 0) {
  127. this.docId = res.data.data[0].id
  128. this.queryFirstCoverImg(this.docId)
  129. this.showForm = true
  130. } else {
  131. this.docId = undefined
  132. this.showForm = true
  133. }
  134. })
  135. },
  136. queryFirstCoverImg(params) {
  137. KmKnowledageService.getCoverImgList({ id: params }).then((res) => {
  138. const coverAttachmentValue = res.data.pageFormData.pageFieldInfos.find((n) => {
  139. return n.name === 'coverImage'
  140. })
  141. if (coverAttachmentValue.attr.attachments.length !== 0) {
  142. this.systemImgData = coverAttachmentValue.attr.attachments
  143. if (this.value === '') {
  144. // 起草的时候默认给系统预置的第一个封面图
  145. // this.activeCode = coverAttachmentValue.attr.attachments[0].code
  146. this.activeCode.push(coverAttachmentValue.attr.attachments[0].code)
  147. this.$emit('input', this.activeCode[0])
  148. }
  149. } else {
  150. this.systemImgData = []
  151. }
  152. })
  153. },
  154. // 选择默认封面
  155. handleImg(item) {
  156. // 只要选择了默认封面 就清空自定义上传的activeCoed
  157. this.uploadActiveCode = []
  158. if (this.activeCode.includes(item.code)) {
  159. this.activeCode.splice(this.activeCode.indexOf(item.code), 1)
  160. } else {
  161. this.activeCode = []
  162. this.activeCode.push(item.code)
  163. }
  164. },
  165. // 上传自定义的封面
  166. change(attachments) {
  167. this.uploadActiveCode = []
  168. if (attachments.length > 0) {
  169. this.uploadActiveCode.push(attachments[0].code)
  170. }
  171. },
  172. handleSetImg() {
  173. // 只读模式不弹窗
  174. if (this.readOnly) return
  175. // 打开的时候判断下是不是自定义的封面 看看value给哪个active
  176. if (this.systemImgData.findIndex((item) => item.code === this.value) !== -1) {
  177. this.activeCode = [this.value]
  178. this.uploadActiveCode = []
  179. } else {
  180. this.activeCode = []
  181. this.uploadActiveCode = [this.value]
  182. }
  183. this.visible = true
  184. },
  185. handleOk() {
  186. // 选了封面才赋值
  187. if (this.uploadActiveCode.length > 0 || this.activeCode.length > 0) {
  188. if (this.uploadActiveCode.length > 0) {
  189. this.$emit('change', this.uploadActiveCode[0])
  190. } else {
  191. this.$emit('change', this.activeCode[0])
  192. }
  193. }
  194. this.visible = false
  195. },
  196. },
  197. }
  198. </script>
  199. <style module lang="scss">
  200. @use '@/common/design' as *;
  201. $img-line-height: 22px;
  202. .coverimgs {
  203. .noimg {
  204. padding-top: 40px;
  205. color: $text-color;
  206. text-align: center;
  207. }
  208. position: relative;
  209. display: block;
  210. height: 100px;
  211. margin: 0 auto;
  212. .upload-img {
  213. position: absolute;
  214. top: 50%;
  215. left: 50%;
  216. width: auto;
  217. max-width: 100%;
  218. height: auto;
  219. max-height: 100%;
  220. transform: translate3d(-50%, -50%, 0);
  221. }
  222. .img-mask {
  223. position: absolute;
  224. bottom: 0;
  225. left: 50%;
  226. width: 240px;
  227. height: 22px;
  228. line-height: $img-line-height;
  229. color: $white;
  230. text-align: center;
  231. background-color: $back-top-bg;
  232. transform: translate(-50%, 0);
  233. }
  234. }
  235. /* stylelint-disable */
  236. :global(#listPicture) {
  237. .checked {
  238. :global(.ant-upload-list-item-list-type-picture-card) {
  239. border: 2px solid $primary-5;
  240. }
  241. }
  242. }
  243. </style>