index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div>
  3. <el-card>
  4. <div style="padding: 8px">
  5. <el-button type="primary" @click="newArtwork()" v-preReClick>新增图稿</el-button>
  6. </div>
  7. <div
  8. v-infinite-scroll="load"
  9. class="infinite-list"
  10. style="overflow-y: auto; overflow-x: hidden; height: calc(100vh - 208px); display: flex; flex-wrap: wrap"
  11. :infinite-scroll-disabled="scrollDisabled"
  12. :infinite-scroll-immediate="false"
  13. :infinite-scroll-distance="100">
  14. <template v-if="tableData && tableData.length > 0">
  15. <div v-for="(item, index) in tableData" :key="index" style="margin: 0 40px 40px 0; text-align: center">
  16. <div v-if="item.imgUrl">
  17. <el-image
  18. style="cursor: pointer; border-radius: 5px; height: 26vh"
  19. :src="item.imgUrl"
  20. :zoom-rate="1.2"
  21. :preview-src-list="tableData.map((row) => row.imgUrl)"
  22. :initial-index="index"
  23. fit="cover" />
  24. </div>
  25. <div style="margin: 5px 0; white-space: nowrap; text-overflow: ellipsis">{{ item.artworkName }}</div>
  26. <div style="margin: 5px 0; display: flex; justify-content: space-between">
  27. <el-button type="primary" @click="clickUpdate(item)" text>编辑</el-button>
  28. <el-button type="danger" @click="clickDelete(item)" text>删除</el-button>
  29. </div>
  30. </div>
  31. </template>
  32. </div>
  33. </el-card>
  34. <el-dialog :title="modalType == 'add' ? '新增图稿' : '编辑图稿'" v-if="openDialog" v-model="openDialog" width="700">
  35. <el-form :model="formData.data" label-width="100px" :rules="rules" ref="submit">
  36. <el-form-item label="图稿名称:" prop="artworkName">
  37. <el-input v-model="formData.data.artworkName" placeholder="请输入图稿名称" :maxlength="300" />
  38. </el-form-item>
  39. <el-form-item label="事业部:" prop="departmentId" v-if="proxy.useUserStore().user.deptId === '100'">
  40. <el-select v-model="formData.data.departmentId" placeholder="请选择事业部" style="width: 100%" clearable>
  41. <el-option v-for="item in departmentList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item label="图稿文件:" required style="width: 100%">
  45. <el-upload
  46. v-model:fileList="fileList"
  47. action="https://winfaster.obs.cn-south-1.myhuaweicloud.com"
  48. :data="uploadData"
  49. :before-upload="uploadFile"
  50. :on-success="handleSuccess"
  51. :on-preview="onPreviewFile"
  52. :limit="1"
  53. style="width: 100%">
  54. <el-button style="background: #20b2aa; color: #fff; border: 1px solid #20b2aa">上传</el-button>
  55. </el-upload>
  56. </el-form-item>
  57. <el-form-item label="图稿图片:" required>
  58. <el-upload
  59. class="avatar-uploader"
  60. action="https://winfaster.obs.cn-south-1.myhuaweicloud.com"
  61. :data="uploadMainData"
  62. :show-file-list="false"
  63. :on-success="handleMainSuccess"
  64. :before-upload="uploadMainFile">
  65. <el-image v-if="formData.data.imgUrl" :src="formData.data.imgUrl" fit="scale-down" class="avatar" />
  66. <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
  67. </el-upload>
  68. </el-form-item>
  69. </el-form>
  70. <template #footer>
  71. <el-button @click="openDialog = false" size="large">取 消</el-button>
  72. <el-button type="primary" @click="submitForm()" size="large" v-preReClick>确 定</el-button>
  73. </template>
  74. </el-dialog>
  75. </div>
  76. </template>
  77. <script setup>
  78. import { ElMessage, ElMessageBox } from "element-plus";
  79. const { proxy } = getCurrentInstance();
  80. const departmentList = ref([]);
  81. const sourceList = ref({
  82. pagination: {
  83. total: 0,
  84. pageNum: 1,
  85. pageSize: 30,
  86. departmentId: proxy.useUserStore().user.deptId === "100" ? "" : proxy.useUserStore().user.deptId,
  87. },
  88. });
  89. const tableData = ref([]);
  90. const scrollDisabled = ref(false);
  91. const load = () => {
  92. proxy.post("/artworkLibrary/page", sourceList.value.pagination).then((res) => {
  93. tableData.value = tableData.value.concat(res.rows);
  94. sourceList.value.pagination.total = res.total;
  95. if (sourceList.value.pagination.total > sourceList.value.pagination.pageNum * sourceList.value.pagination.pageSize) {
  96. sourceList.value.pagination.pageNum++;
  97. scrollDisabled.value = false;
  98. } else {
  99. scrollDisabled.value = true;
  100. }
  101. });
  102. };
  103. load();
  104. const getDemandData = () => {
  105. proxy.post("/department/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  106. if (res.rows && res.rows.length > 0) {
  107. departmentList.value = res.rows.map((item) => {
  108. return {
  109. dictKey: item.id,
  110. dictValue: item.name,
  111. };
  112. });
  113. }
  114. });
  115. };
  116. getDemandData();
  117. const modalType = ref("add");
  118. const openDialog = ref(false);
  119. const formData = reactive({
  120. data: {},
  121. });
  122. const rules = ref({
  123. artworkName: [{ required: true, message: "请输入图稿名称", trigger: "blur" }],
  124. departmentId: [{ required: true, message: "请选择事业部", trigger: "change" }],
  125. });
  126. const uploadData = ref({});
  127. const fileList = ref([]);
  128. const uploadFile = async (file) => {
  129. const res = await proxy.post("/fileInfo/getSing", { fileName: file.name });
  130. uploadData.value = res.uploadBody;
  131. file.id = res.id;
  132. file.fileName = res.fileName;
  133. file.fileUrl = res.fileUrl;
  134. file.uploadState = true;
  135. return true;
  136. };
  137. const handleSuccess = (any, UploadFile) => {
  138. UploadFile.raw.uploadState = false;
  139. };
  140. const uploadMainData = ref({});
  141. const uploadMainFile = async (file) => {
  142. const res = await proxy.post("/fileInfo/getSing", { fileName: file.name });
  143. uploadMainData.value = res.uploadBody;
  144. file.id = res.id;
  145. file.fileName = res.fileName;
  146. file.fileUrl = res.fileUrl;
  147. return true;
  148. };
  149. const handleMainSuccess = (response, uploadFile) => {
  150. formData.data.imgId = uploadFile.raw.id;
  151. formData.data.imgName = uploadFile.raw.fileName;
  152. formData.data.imgUrl = uploadFile.raw.fileUrl;
  153. };
  154. const newArtwork = () => {
  155. fileList.value = [];
  156. modalType.value = "add";
  157. formData.data = {
  158. artworkName: "",
  159. imgId: "",
  160. imgName: "",
  161. imgUrl: "",
  162. fileId: "",
  163. fileName: "",
  164. fileUrl: "",
  165. };
  166. openDialog.value = true;
  167. };
  168. const submitForm = () => {
  169. proxy.$refs.submit.validate((valid) => {
  170. if (valid) {
  171. if (fileList.value && fileList.value.length > 0) {
  172. if (formData.data.imgUrl) {
  173. formData.data.fileId = fileList.value[0].raw.id;
  174. formData.data.fileName = fileList.value[0].raw.fileName;
  175. formData.data.fileUrl = fileList.value[0].raw.fileUrl;
  176. if (proxy.useUserStore().user.deptId !== "100") {
  177. formData.data.departmentId = proxy.useUserStore().user.deptId;
  178. }
  179. proxy.post("/artworkLibrary/" + modalType.value, formData.data).then(() => {
  180. ElMessage({
  181. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  182. type: "success",
  183. });
  184. openDialog.value = false;
  185. tableData.value = [];
  186. sourceList.value.pagination.pageNum = 1;
  187. load();
  188. });
  189. } else {
  190. return ElMessage("请上传图稿图片");
  191. }
  192. } else {
  193. return ElMessage("请上传图稿文件");
  194. }
  195. }
  196. });
  197. };
  198. const openFile = (path) => {
  199. window.open(path);
  200. };
  201. const clickUpdate = (row) => {
  202. modalType.value = "edit";
  203. formData.data = proxy.deepClone(row);
  204. fileList.value = [
  205. {
  206. raw: {
  207. id: row.fileId,
  208. fileName: row.fileName,
  209. fileUrl: row.fileUrl,
  210. },
  211. name: row.fileName,
  212. url: row.fileUrl,
  213. },
  214. ];
  215. openDialog.value = true;
  216. };
  217. const clickDelete = (row) => {
  218. ElMessageBox.confirm("你是否确认此操作", "提示", {
  219. confirmButtonText: "确定",
  220. cancelButtonText: "取消",
  221. type: "warning",
  222. })
  223. .then(() => {
  224. proxy.post("/artworkLibrary/delete", { id: row.id }).then(() => {
  225. ElMessage({ message: "删除成功", type: "success" });
  226. openDialog.value = false;
  227. tableData.value = [];
  228. sourceList.value.pagination.pageNum = 1;
  229. load();
  230. });
  231. })
  232. .catch(() => {});
  233. };
  234. </script>
  235. <style lang="scss" scoped>
  236. .avatar-uploader .avatar {
  237. width: 148px;
  238. height: 148px;
  239. display: block;
  240. background-color: black;
  241. }
  242. .avatar-uploader .el-upload {
  243. border: 1px dashed var(--el-border-color);
  244. border-radius: 6px;
  245. cursor: pointer;
  246. position: relative;
  247. overflow: hidden;
  248. transition: var(--el-transition-duration-fast);
  249. }
  250. .avatar-uploader .el-upload:hover {
  251. border-color: var(--el-color-primary);
  252. }
  253. .el-icon.avatar-uploader-icon {
  254. font-size: 28px;
  255. color: #8c939d;
  256. width: 148px;
  257. height: 148px;
  258. text-align: center;
  259. border: 1px dashed var(--el-border-color);
  260. }
  261. </style>