ScanFile.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-model="props.openScan"
  5. width="964px"
  6. top="20vh"
  7. title="扫描文档"
  8. @close="closeOpen"
  9. >
  10. <div class="main">
  11. <!-- 头部的总计和移动按钮 -->
  12. <div class="statistics">
  13. <el-checkbox v-model="checkedAll" @change="checkAllChange"
  14. >共{{ props.scannerFiles.length }}项</el-checkbox
  15. >
  16. <div class="">
  17. <el-button color="#2E6BC8" @click="toSave">
  18. <img src="@/assets/images/folder_white.png" alt="" />&nbsp; 移动到
  19. </el-button>
  20. </div>
  21. </div>
  22. <!-- 盒子区域 -->
  23. <div class="bigBox" id="bigBox">
  24. <div v-for="(item, index) in copyList" :key="item" class="one_box">
  25. <img :src="wangzhi + item.path" alt="" />
  26. <div class="top_check">
  27. <el-checkbox
  28. :checked="fileArr.some((par) => par == item.q)"
  29. @change="checkChange(item, index)"
  30. ></el-checkbox>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </el-dialog>
  36. </div>
  37. </template>
  38. <script setup>
  39. import {
  40. ref,
  41. computed,
  42. reactive,
  43. defineComponent,
  44. watch,
  45. toRaw,
  46. onMounted,
  47. defineExpose,
  48. onDeactivated,
  49. } from "vue";
  50. import Sortable from "sortablejs";
  51. import { ElMessage } from "element-plus";
  52. const props = defineProps({
  53. openScan: {
  54. type: Boolean,
  55. default: false,
  56. },
  57. scannerFiles: {
  58. type: Array,
  59. default: () => [],
  60. },
  61. });
  62. const checkedAll = ref(false); //是否全选
  63. const copyList = ref(props.scannerFiles);
  64. const total = ref(333); //总计数量
  65. const wangzhi = import.meta.env.VITE_APP_BASE_API;
  66. const fileArr = ref([]);
  67. const emit = defineEmits(["closeOpen", "saveScanFile"]);
  68. const closeOpen = () => {
  69. emit("closeOpen");
  70. };
  71. // const checkChange = (item,index) => {
  72. // console.log('item',item);
  73. // console.log('index',index);
  74. // let arr = fileArr.value;
  75. // if (arr.some((par) => par == item.q)) {
  76. // arr = arr.filter((par) => par != item.q);
  77. // } else {
  78. // arr.push(item.q);
  79. // }
  80. // // if (arr.some((par) => par == item.q)) {
  81. // // arr = arr.filter((par) => par != item.q);
  82. // // } else {
  83. // // arr.push({q:item.q,index:index});
  84. // // }
  85. // // 判断全选
  86. // if (arr.length == props.scannerFiles.length) {
  87. // checkedAll.value = true;
  88. // } else {
  89. // checkedAll.value = false;
  90. // }
  91. // fileArr.value = JSON.parse(JSON.stringify(arr));
  92. // console.log("fileArr", toRaw(fileArr.value));
  93. // };
  94. const checkChange = (item, index) => {
  95. // console.log("item", item);
  96. // console.log("index", index);
  97. let arr = copyList.value;
  98. copyList.value = arr.map((par) => {
  99. if (item.q == par.q) {
  100. if (par.checked) {
  101. par.checked = false;
  102. } else {
  103. par.checked = true;
  104. }
  105. }
  106. return par;
  107. });
  108. // console.log('chengeC',copyList.value);
  109. };
  110. const checkAllChange = () => {
  111. // console.log("checkedAll.value", checkedAll.value);
  112. fileArr.value = [];
  113. if (checkedAll.value) {
  114. //全选
  115. props.scannerFiles.forEach((item) => {
  116. fileArr.value.push(item.q);
  117. });
  118. const oldArr = JSON.parse(JSON.stringify(copyList.value))
  119. copyList.value = oldArr.map(item=>{
  120. item.checked = true
  121. return item
  122. })
  123. }else{
  124. const oldArr = JSON.parse(JSON.stringify(copyList.value))
  125. copyList.value = oldArr.map(item=>{
  126. item.checked = false
  127. return item
  128. })
  129. }
  130. // console.log("fileArr", fileArr.value);
  131. };
  132. const toSave = () => {
  133. // console.log("copyList", copyList.value);
  134. if(!copyList.value.some(item=>item.checked == true)){
  135. return ElMessage({ message: "请先勾选文件", type: "error" });
  136. }
  137. const arr = []
  138. copyList.value.forEach(item=>{
  139. if(item.checked){
  140. arr.push(item.q)
  141. }
  142. })
  143. // console.log('arr',arr);
  144. // console.log('chengeC',copyList.value);
  145. emit("saveScanFile", arr);
  146. };
  147. const rowDrop = () => {
  148. const el = document.getElementById("bigBox"); //找到想要拖拽的那一列
  149. Sortable.create(el, {
  150. //结束拖拽事件
  151. async onEnd({ newIndex, oldIndex }) {
  152. const newItem = copyList.value[newIndex];
  153. const oldItem = copyList.value[oldIndex];
  154. copyList.value[newIndex] = oldItem;
  155. copyList.value[oldIndex] = newItem;
  156. // console.log("2copyList.value", copyList.value);/
  157. },
  158. });
  159. };
  160. onMounted(async () => {
  161. setTimeout(() => {
  162. rowDrop();
  163. const arr = copyList.value;
  164. copyList.value = arr.map((item) => {
  165. item.checked = false;
  166. return toRaw(item);
  167. });
  168. console.log("copyList.value", copyList.value);
  169. }, 500);
  170. });
  171. </script>
  172. <style lang="scss" scoped>
  173. .main {
  174. width: 100%;
  175. }
  176. .statistics {
  177. width: 100%;
  178. height: 50px;
  179. border-bottom: 1px solid #c1cce3;
  180. padding: 0 16px;
  181. display: flex;
  182. justify-content: space-between;
  183. align-items: center;
  184. }
  185. .bigBox {
  186. margin-top: 16px;
  187. width: 100%;
  188. padding: 0 16px;
  189. max-height: 700px;
  190. display: flex;
  191. flex-wrap: wrap;
  192. justify-content: space-between;
  193. overflow-y: auto;
  194. .one_box {
  195. width: 300px;
  196. height: 220px;
  197. border: 1px solid #c1cce3;
  198. box-sizing: border-box;
  199. margin-bottom: 16px;
  200. border-radius: 4px 4px 4px 4px;
  201. box-shadow: 0px 2px 10px 1px rgba(199, 203, 216, 0.4);
  202. position: relative;
  203. img {
  204. width: 100%;
  205. height: 100%;
  206. object-fit: cover;
  207. }
  208. .top_check {
  209. position: absolute;
  210. top: -3%;
  211. right: 1%;
  212. }
  213. }
  214. }
  215. :deep(.el-dialog__body) {
  216. padding: 0 !important;
  217. }
  218. </style>