index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="upload-warp picture-card">
  3. <div v-if="!base64Image" class="flex col uplaod-btn" @click="openImage">
  4. <el-icon>
  5. <Plus />
  6. </el-icon>
  7. <div class="add-text">添加</div>
  8. </div>
  9. <div v-if="base64Image" class="image-out">
  10. <img class="el-upload-list__item-thumbnail" :src="'file:///'+base64Image" alt="" />
  11. <span class="el-upload-list__item-actions">
  12. <span @click="handlePictureCardPreview(base64Image)">
  13. <el-icon><zoom-in /></el-icon>
  14. </span>
  15. <span v-if="!disabled" class="mar-left-10" @click="handleRemove()">
  16. <el-icon>
  17. <Delete />
  18. </el-icon>
  19. </span>
  20. </span>
  21. </div>
  22. </div>
  23. <!-- <img v-if="base64Image" :src="base64Image">
  24. <div class="input" v-if="filePath">{{filePath}}</div> -->
  25. <!--
  26. <el-upload class="upload-warp" action="#" list-type="picture-card" :http-request="upload">
  27. <div class="flex col">
  28. <el-icon>
  29. <Plus />
  30. </el-icon>
  31. <div class="add-text">添加</div>
  32. </div>
  33. <template #file="{ file }">
  34. <div>
  35. <img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
  36. <span class="el-upload-list__item-actions">
  37. <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
  38. <el-icon><zoom-in /></el-icon>
  39. </span>
  40. <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleDownload(file)">
  41. <el-icon>
  42. <Download />
  43. </el-icon>
  44. </span>
  45. <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
  46. <el-icon>
  47. <Delete />
  48. </el-icon>
  49. </span>
  50. </span>
  51. </div>
  52. </template>
  53. </el-upload>-->
  54. <el-dialog v-model="dialogVisible">
  55. <img class="w-full" :src="dialogImageUrl" alt="Preview Image" />
  56. </el-dialog>
  57. </template>
  58. <script lang="ts" setup>
  59. import { ref, defineEmits } from 'vue'
  60. import { Delete, Download, Plus, ZoomIn } from '@element-plus/icons-vue'
  61. import type { UploadFile } from 'element-plus'
  62. import { imagesUpload } from '@/utils/appconfig'
  63. import { ElMessage } from 'element-plus'
  64. import * as userApi from '@/apis/user'
  65. import client from "@/stores/modules/client";
  66. import icpList from '@/utils/ipc'
  67. const clientStore = client();
  68. // 定义自定义事件
  69. const emit = defineEmits(['input']);
  70. interface Props {
  71. value: string
  72. hasDel?: boolean
  73. hasSize?: boolean
  74. width?: number
  75. height?: number
  76. fileSize?: number
  77. styleWidth?: string
  78. accept?: string[]
  79. }
  80. const props = withDefaults(defineProps<Props>(), {
  81. value: '',
  82. hasDel: true,
  83. hasSize: true,
  84. width: 0,
  85. height: 0,
  86. fileSize: imagesUpload.fileSize,
  87. styleWidth: '160',
  88. accept: () => imagesUpload.accept
  89. })
  90. const dialogImageUrl = ref('')
  91. const dialogVisible = ref(false)
  92. const disabled = ref(false)
  93. const handleRemove = () => {
  94. filePath.value = ''
  95. base64Image.value = ''
  96. emit('input' , '' )
  97. }
  98. const handlePictureCardPreview = (base64Image) => {
  99. dialogImageUrl.value = base64Image!
  100. dialogVisible.value = true
  101. }
  102. const handleDownload = (file: UploadFile) => {
  103. console.log(file)
  104. }
  105. const base64Image = ref('')
  106. const filePath = ref('')
  107. function openImage() {
  108. clientStore.ipc.removeAllListeners(icpList.utils.openImage);
  109. clientStore.ipc.send(icpList.utils.openImage);
  110. clientStore.ipc.on(icpList.utils.openImage, async (event, result) => {
  111. filePath.value = result.filePath
  112. base64Image.value = result.filePath
  113. clientStore.ipc.removeAllListeners(icpList.utils.openImage);
  114. emit('input' ,result.filePath)
  115. })
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. // .upload-warp {
  120. // ::v-deep {
  121. // .el-upload--picture-card {
  122. // background-color: #fff;
  123. // .el-icon,
  124. // .add-text {
  125. // color: #2957FF;
  126. // }
  127. // }
  128. // }
  129. // }
  130. .uplaod-btn {
  131. width: 120px;
  132. height: 120px;
  133. cursor: pointer;
  134. background: #fff;
  135. border-radius: 6px;
  136. border: 1px dashed #B3B4B5;
  137. .el-icon,
  138. .add-text {
  139. color: #2957FF;
  140. font-size: 14px;
  141. }
  142. &:hover {
  143. border: 1px dashed #2957FF;
  144. }
  145. }
  146. .image-out {
  147. width: 120px;
  148. height: 120px;
  149. position: relative;
  150. border: 1px solid var(--el-border-color);
  151. border-radius: 6px;
  152. overflow: hidden;
  153. .el-upload-list__item-thumbnail {
  154. width: 100%;
  155. height: 100%;
  156. object-fit: contain;
  157. }
  158. .el-upload-list__item-actions{
  159. position: absolute;
  160. width: 100%;
  161. height: 100%;
  162. left: 0;
  163. top: 0;
  164. cursor: default;
  165. display: inline-flex;
  166. justify-content: center;
  167. align-items: center;
  168. color: #fff;
  169. opacity: 0;
  170. font-size: 20px;
  171. background-color: var(--el-overlay-color-lighter);
  172. transition: opacity var(--el-transition-duration);
  173. span{
  174. display: none;
  175. cursor: pointer;
  176. }
  177. &:hover{
  178. opacity: 1;
  179. span{
  180. display: inline-flex;
  181. cursor: pointer;
  182. width: 20px;
  183. }
  184. }
  185. // .el-upload-list__item-preview,
  186. // .el-upload-list__item-delete{
  187. // }
  188. }
  189. }
  190. </style>