index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <div>
  3. <basic-container v-if="!basic">
  4. <avue-crud :data="data" ref="crud" :option="option" :key="key" @resetColumn="resetColumn"
  5. @saveColumn="saveColumn">
  6. <template slot="menuLeft">
  7. <el-button type="primary" size="small" icon="el-icon-edit" @click="addDetail" :disabled="disabled"
  8. v-if="display">上传
  9. </el-button>
  10. <slot name="c_button"></slot>
  11. </template>
  12. <template slot="url" slot-scope="{ row }">
  13. <el-input placeholder="请输入内容" size="small" v-if="row.$cellEdit" v-model="row.url"
  14. class="input-with-select">
  15. <el-button slot="append" @click="singleLineUpload(row)">附件</el-button>
  16. </el-input>
  17. <span v-else>{{ row.url }}</span>
  18. </template>
  19. <template slot-scope="scope" slot="menu">
  20. <el-button icon="el-icon-download" :size="scope.size" :type="scope.type" @click="download(scope)">查看
  21. </el-button>
  22. <el-button :type="scope.type" :size="scope.size" icon="el-icon-edit"
  23. @click.stop="rowCell(scope.row, scope.index)" :disabled="disabled">
  24. {{ scope.row.$cellEdit ? "保存" : "修改" }}
  25. </el-button>
  26. <el-button :type="scope.type" :size="scope.size" icon="el-icon-delete"
  27. @click.stop="rowDel(scope.row, scope.index)" :disabled="disabled">删除
  28. </el-button>
  29. </template>
  30. </avue-crud>
  31. <el-dialog title="上传附件" append-to-body :visible.sync="excelBox" width="555px"
  32. :close-on-click-modal="false"
  33. v-dialog-drag>
  34. <el-upload class="upload-demo" drag style="text-align: center" ref="upload"
  35. :action="incomingAction ? incomingAction : action" :headers="headers" :on-success="onSuccess"
  36. multiple
  37. :before-upload="beforeUpload">
  38. <i class="el-icon-upload"></i>
  39. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  40. <div class="el-upload__tip" slot="tip">
  41. 如上传文件过大,请耐心等待上传成功
  42. </div>
  43. </el-upload>
  44. </el-dialog>
  45. <el-dialog title="修改附件" append-to-body :visible.sync="excelTwo" width="555px"
  46. :close-on-click-modal="false"
  47. v-dialog-drag>
  48. <el-upload class="upload-demo" drag style="text-align: center"
  49. :action="incomingAction ? incomingAction : action" :headers="headers" :show-file-list="false"
  50. :on-success="onSuccessTwo" :before-upload="beforeUpload">
  51. <i class="el-icon-upload"></i>
  52. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  53. <div class="el-upload__tip" slot="tip">
  54. 如上传文件过大,请耐心等待上传成功
  55. </div>
  56. </el-upload>
  57. </el-dialog>
  58. <PreviewImage :visible.sync="innerVisible" :currentIndex="0" :previewImgList="[imgUrl]"/>
  59. </basic-container>
  60. <span v-else-if="true">
  61. <avue-crud :data="data" ref="crud" :option="option" :key="key" @resetColumn="resetColumn"
  62. @saveColumn="saveColumn">
  63. <template slot="menuLeft">
  64. <el-button type="primary" size="small" icon="el-icon-edit" @click="addDetail" :disabled="disabled">上传
  65. </el-button>
  66. </template>
  67. <template slot="url" slot-scope="{ row }">
  68. <el-input placeholder="请输入内容" size="small" v-if="row.$cellEdit" v-model="row.url"
  69. class="input-with-select">
  70. <el-button slot="append" @click="singleLineUpload(row)">附件</el-button>
  71. </el-input>
  72. <span v-else>{{ row.url }}</span>
  73. </template>
  74. <template slot-scope="scope" slot="menu">
  75. <el-button icon="el-icon-download" :size="scope.size" :type="scope.type" @click="download(scope)">查看
  76. </el-button>
  77. <el-button :type="scope.type" :size="scope.size" icon="el-icon-edit"
  78. @click.stop="rowCell(scope.row, scope.index)" :disabled="disabled">
  79. {{ scope.row.$cellEdit ? "保存" : "修改" }}
  80. </el-button>
  81. <el-button :type="scope.type" :size="scope.size" icon="el-icon-delete"
  82. @click.stop="rowDel(scope.row, scope.index)" :disabled="disabled">删除
  83. </el-button>
  84. </template>
  85. </avue-crud>
  86. <el-dialog title="上传附件" append-to-body :visible.sync="excelBox" width="555px" :close-on-click-modal="false"
  87. v-dialog-drag>
  88. <el-upload class="upload-demo" drag style="text-align: center" ref="upload" :action="action" :headers="headers"
  89. :on-success="onSuccess" multiple :before-upload="beforeUpload">
  90. <i class="el-icon-upload"></i>
  91. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  92. <div class="el-upload__tip" slot="tip">
  93. 如上传文件过大,请耐心等待上传成功
  94. </div>
  95. </el-upload>
  96. </el-dialog>
  97. <el-dialog title="修改附件" append-to-body :visible.sync="excelTwo" width="555px" :close-on-click-modal="false"
  98. v-dialog-drag>
  99. <el-upload class="upload-demo" drag style="text-align: center"
  100. :action="incomingAction ? incomingAction : action" :headers="headers" :show-file-list="false"
  101. :on-success="onSuccessTwo" :before-upload="beforeUpload">
  102. <i class="el-icon-upload"></i>
  103. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  104. <div class="el-upload__tip" slot="tip">
  105. 如上传文件过大,请耐心等待上传成功
  106. </div>
  107. </el-upload>
  108. </el-dialog>
  109. <!-- 新的查看图片弹窗-->
  110. <PreviewImage :visible.sync="innerVisible" :currentIndex="0" :previewImgList="[imgUrl]"/>
  111. </span>
  112. </div>
  113. </template>
  114. <script>
  115. import {getToken} from "@/util/auth";
  116. import {LTfujianDelete, sharedDeletion} from "@/api/user";
  117. import {updateListRemove} from "@/api/base/upload";
  118. import PreviewImage from '@/components/PreviewImage/index.vue'
  119. export default {
  120. name: "index",
  121. components: {PreviewImage},
  122. props: {
  123. data: {
  124. type: Object
  125. },
  126. incomingAction: {
  127. type: String
  128. },
  129. deleteUrl: {
  130. type: String
  131. },
  132. enumerationValue: {
  133. type: Number
  134. },
  135. typeUpload: {
  136. type: String
  137. },
  138. disabled: {
  139. type: Boolean
  140. },
  141. display: {
  142. type: Boolean
  143. },
  144. basic: {
  145. type: Boolean
  146. }
  147. },
  148. data() {
  149. return {
  150. excelBox: false,
  151. excelTwo: false,
  152. innerVisible: false,
  153. form: {},
  154. imgUrl: "",
  155. action: "/api/blade-resource/oss/endpoint/put-file",
  156. headers: {"Blade-Auth": "Bearer " + getToken()},
  157. option: {},
  158. key: 0,
  159. originalOptions: {
  160. dialogDrag: true,
  161. index: true,
  162. refreshBtn: false,
  163. cellBtn: false,
  164. cancelBtn: false,
  165. delBtn: false,
  166. editBtn: false,
  167. addBtn: false,
  168. align: "center",
  169. column: [
  170. {
  171. label: "文件名称",
  172. prop: "fileName",
  173. index: 1,
  174. width: 140,
  175. cell: true,
  176. overHidden: true
  177. },
  178. {
  179. label: "文件地址",
  180. prop: "url",
  181. index: 2,
  182. overHidden: true
  183. }, {
  184. type: "select",
  185. dicUrl: "/api/blade-system/dict-biz/dictionary?code=file_type",
  186. props: {
  187. label: "dictValue",
  188. value: "dictValue"
  189. },
  190. label: "文件属性",
  191. prop: "paymentType",
  192. search: false,
  193. index: 3,
  194. width: 140,
  195. overHidden: true,
  196. cell: true
  197. },
  198. {
  199. label: "备注",
  200. prop: "remarks",
  201. index: 4,
  202. cell: true,
  203. overHidden: true
  204. }
  205. ]
  206. },
  207. originalOptionsTwo: {
  208. dialogDrag: true,
  209. index: true,
  210. refreshBtn: false,
  211. cellBtn: false,
  212. cancelBtn: false,
  213. delBtn: false,
  214. editBtn: false,
  215. addBtn: false,
  216. align: "center",
  217. column: [
  218. {
  219. label: "文件名称",
  220. prop: "fileName",
  221. index: 1,
  222. width: 140,
  223. cell: true,
  224. overHidden: true
  225. },
  226. {
  227. label: "文件地址",
  228. prop: "url",
  229. index: 2,
  230. overHidden: true
  231. }, {
  232. type: "select",
  233. dicUrl: "/api/blade-system/dict-biz/dictionary?code=picture_type",
  234. props: {
  235. label: "dictValue",
  236. value: "dictKey"
  237. },
  238. label: "文件属性",
  239. prop: "version",
  240. search: false,
  241. index: 3,
  242. width: 140,
  243. overHidden: true,
  244. cell: true,
  245. },
  246. {
  247. label: "备注",
  248. prop: "remarks",
  249. index: 4,
  250. cell: true,
  251. overHidden: true
  252. }
  253. ]
  254. },
  255. // 基础信息轮胎附件
  256. originalOptionsTwo_LT: {
  257. dialogDrag: true,
  258. index: true,
  259. refreshBtn: false,
  260. cellBtn: false,
  261. cancelBtn: false,
  262. delBtn: false,
  263. editBtn: false,
  264. addBtn: false,
  265. align: "center",
  266. column: [
  267. {
  268. label: "文件名称",
  269. prop: "fileName",
  270. index: 1,
  271. width: 140,
  272. cell: true,
  273. overHidden: true
  274. },
  275. {
  276. label: "文件地址",
  277. prop: "url",
  278. index: 2,
  279. overHidden: true
  280. }, {
  281. type: "select",
  282. dicUrl: "/api/blade-system/dict-biz/dictionary?code=picture_type",
  283. props: {
  284. label: "dictValue",
  285. value: "dictKey"
  286. },
  287. label: "文件属性",
  288. prop: "mainImage",
  289. search: false,
  290. index: 3,
  291. width: 140,
  292. overHidden: true,
  293. cell: true,
  294. },
  295. {
  296. label: "备注",
  297. prop: "remarks",
  298. index: 4,
  299. cell: true,
  300. overHidden: true
  301. }
  302. ]
  303. },
  304. originalOptionsThree: {
  305. dialogDrag: true,
  306. index: true,
  307. refreshBtn: false,
  308. cellBtn: false,
  309. cancelBtn: false,
  310. delBtn: false,
  311. editBtn: false,
  312. addBtn: false,
  313. align: "center",
  314. column: [
  315. {
  316. label: "文件名称",
  317. prop: "fileName",
  318. index: 1,
  319. width: 140,
  320. cell: true,
  321. overHidden: true
  322. },
  323. {
  324. label: "文件地址",
  325. prop: "url",
  326. index: 2,
  327. overHidden: true
  328. },
  329. {
  330. label: "备注",
  331. prop: "remarks",
  332. index: 4,
  333. cell: true,
  334. overHidden: true
  335. }
  336. ]
  337. },
  338. uploadCount: 0
  339. };
  340. },
  341. async created() {
  342. console.log(this.enumerationValue)
  343. this.option = this.originalOptionsTwo_LT
  344. this.key++
  345. },
  346. methods: {
  347. //自定义列保存
  348. async saveColumn() {
  349. /**
  350. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  351. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  352. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  353. */
  354. const inSave = await this.saveColumnData(this.getColumnName(this.enumerationValue), this.option);
  355. if (inSave) {
  356. this.$message.success("保存成功");
  357. //关闭窗口
  358. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  359. }
  360. },
  361. //自定义列重置
  362. async resetColumn() {
  363. this.option = this.originalOptionsTwo_LT;
  364. this.$message.success("重置成功");
  365. },
  366. beforeUpload(file) {
  367. if (file.type == "image/jpeg" || file.type == "image/png" || file.type == "image/bmp") {
  368. const fileSize = file.size / 1024 / 1024
  369. if (fileSize > 5) {
  370. this.$message.error("请上传不能超过5M的图片");
  371. return false;
  372. }
  373. } else {
  374. const fileSize = file.size / 1024 / 1024
  375. if (fileSize > 10) {
  376. this.$message.error("请上传不能超过10M的文件");
  377. return false;
  378. }
  379. }
  380. },
  381. //新增上传成功
  382. onSuccess(response, file, fileList) {
  383. this.$refs.crud.rowCellAdd({
  384. fileName: response.data.originalName,
  385. url: response.data.link
  386. });
  387. this.uploadCount++;
  388. if (this.uploadCount === fileList.length) {
  389. this.$refs.upload.clearFiles();
  390. this.excelBox = false;
  391. this.uploadCount = 0;
  392. }
  393. },
  394. //修改上传成功
  395. onSuccessTwo(response) {
  396. this.form.fileName = response.data.originalName;
  397. this.form.url = response.data.link;
  398. this.data[this.form.$index] = this.form;
  399. this.excelTwo = false;
  400. },
  401. //单行上传
  402. singleLineUpload(row) {
  403. this.form = row;
  404. this.excelTwo = true;
  405. },
  406. //开启批量上传
  407. addDetail() {
  408. this.excelBox = true;
  409. },
  410. //下载附件
  411. download(scope) {
  412. if (scope.row.url) {
  413. if (
  414. scope.row.url.substring(scope.row.url.lastIndexOf(".")) ===
  415. ".jpg" ||
  416. scope.row.url.substring(scope.row.url.lastIndexOf(".")) ===
  417. ".png" ||
  418. scope.row.url.substring(scope.row.url.lastIndexOf(".")) ===
  419. ".jpeg" ||
  420. scope.row.url.substring(scope.row.url.lastIndexOf(".")) ===
  421. ".JPG" ||
  422. scope.row.url.substring(scope.row.url.lastIndexOf(".")) ===
  423. ".PNG" ||
  424. scope.row.url.substring(scope.row.url.lastIndexOf(".")) ===
  425. ".JPEG"
  426. ) {
  427. this.imgUrl = scope.row.url;
  428. this.innerVisible = true;
  429. } else {
  430. window.open(scope.row.url);
  431. }
  432. } else {
  433. this.$message.error("请上传附件");
  434. }
  435. },
  436. //修改触发
  437. rowCell(row, index) {
  438. if (row.$cellEdit == true) {
  439. this.$set(row, "$cellEdit", false);
  440. } else {
  441. this.$set(row, "$cellEdit", true);
  442. }
  443. // this.$refs.crud.rowCell(row, index)
  444. },
  445. rowDel(row, index) {
  446. this.$confirm("确定将选择数据删除?", {
  447. confirmButtonText: "确定",
  448. cancelButtonText: "取消",
  449. type: "warning"
  450. }).then(() => {
  451. console.log(row, 657)
  452. if (row.id) {
  453. if (this.typeUpload == "CK") {
  454. updateListRemove(row.id, this.deleteUrl).then(res => {
  455. if (res.data.success) {
  456. this.$message.success("操作成功!");
  457. this.data.splice(index, 1);
  458. }
  459. });
  460. } else if (this.typeUpload == "LT") {
  461. LTfujianDelete({ids: row.id}).then(res => {
  462. if (res.data.success) {
  463. this.$message.success("操作成功!");
  464. this.data.splice(index, 1);
  465. }
  466. })
  467. } else {
  468. sharedDeletion(this.deleteUrl, row.id).then(res => {
  469. if (res.data.success) {
  470. this.$message.success("操作成功!");
  471. this.data.splice(index, 1);
  472. }
  473. });
  474. }
  475. } else {
  476. this.data.splice(index, 1);
  477. }
  478. });
  479. }
  480. }
  481. };
  482. </script>
  483. <style scoped></style>