new_photo.vue 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. <template>
  2. <div class="app-container">
  3. <div v-loading.fullscreen.lock="loadingFull" />
  4. <el-tabs v-model="classParams.type">
  5. <el-tab-pane label="图片" name="0" />
  6. <el-tab-pane label="视频" name="1" />
  7. </el-tabs>
  8. <div style="margin-bottom: 20px;">
  9. <el-input v-model="searchParams.search_name" placeholder="分类名称" style="width: 300px" />
  10. <el-select v-model="searchParams.activity_id" style="width: 300px" placeholder="关联活动">
  11. <el-option label="全部" value="" />
  12. <el-option
  13. v-for="item in season_list"
  14. :key="`${item.season}_${item.type}`"
  15. :label="item.name"
  16. :value="item.id"
  17. />
  18. </el-select>
  19. <el-button type="primary" @click="searchParams.page_index = 1; getClassList()">搜索</el-button>
  20. <el-button type="primary" @click="fileType = true; fileVis = true">添加目录</el-button>
  21. </div>
  22. <el-collapse v-model="classActived" accordion @change="toggleImgList">
  23. <el-collapse-item v-for="item in classList" :key="item.id" :name="JSON.stringify(item)">
  24. <template slot="title">
  25. <div class="photo_title_container">
  26. <p>{{ item.imgclass_name }}</p>
  27. <template v-if="+classParams.type === 0">
  28. <div v-if="item.is_old">
  29. <el-button type="text" @click.stop="submitDeleteClass(item.id)">删除目录</el-button>
  30. <el-button type="text" @click.stop="setEditClass(item)">修改目录</el-button>
  31. <el-button type="text" @click.stop="setUploadImg(item.id)">{{ +classParams.type === 0 ? '添加图片' : '添加视频' }}</el-button>
  32. <el-button type="text" @click.stop="setMachDeleteImg">批量删除</el-button>
  33. <el-button type="text" @click.stop="setSeleceAllImg(item)">
  34. {{ item.isSelectAll ? '已全选' : '全选' }}
  35. </el-button>
  36. </div>
  37. <div v-else>
  38. <el-button type="text" @click.stop="submitDeleteClass(item.id)">删除目录</el-button>
  39. <el-button type="text" @click.stop="setEditClass(item)">修改目录</el-button>
  40. <el-button type="text" @click.stop="addClassify(item)">添加分类</el-button>
  41. </div>
  42. </template>
  43. <template v-else>
  44. <div>
  45. <el-button type="text" @click.stop="submitDeleteClass(item.id)">删除目录</el-button>
  46. <el-button type="text" @click.stop="setEditClass(item)">修改目录</el-button>
  47. <el-button type="text" @click.stop="setUploadImg(item.id)">{{ +classParams.type === 0 ? '添加图片' : '添加视频' }}</el-button>
  48. <el-button type="text" @click.stop="setMachDeleteImg">批量删除</el-button>
  49. <el-button type="text" @click.stop="setSeleceAllImg(item)">
  50. {{ item.isSelectAll ? '已全选' : '全选' }}
  51. </el-button>
  52. </div>
  53. </template>
  54. <!-- <ul class="controls_container">
  55. <el-tooltip class="item" effect="dark" content="删除目录" placement="top">
  56. <li class="controls_item" @click.stop="submitDeleteClass(item.id)"><i class="el-icon-folder-delete" /></li>
  57. </el-tooltip>
  58. <el-tooltip class="item" effect="dark" content="修改目录" placement="top">
  59. <li class="controls_item" @click.stop="setEditClass(item)"><i class="el-icon-edit-outline" /></li>
  60. </el-tooltip>
  61. <el-tooltip class="item" effect="dark" :content="+classParams.type === 0 ? '添加图片' : '添加视频'" placement="top">
  62. <li class="controls_item" @click.stop="setUploadImg(item.id)"><i class="el-icon-plus" /></li>
  63. </el-tooltip>
  64. <el-tooltip class="item" effect="dark" content="批量删除" placement="top">
  65. <li class="controls_item" @click.stop="setMachDeleteImg"><i class="el-icon-delete" /></li>
  66. </el-tooltip>
  67. <el-tooltip class="item" effect="dark" content="全选" placement="top">
  68. <li class="controls_item" :class="item.isSelectAll ? 'controls_item_active' : ''" @click.stop="setSeleceAllImg(item)"><i class="el-icon-aim" /></li>
  69. </el-tooltip>
  70. </ul> -->
  71. </div>
  72. </template>
  73. <template v-if="+classParams.type === 0 && !item.is_old">
  74. <template v-if="showClassIfy">
  75. <!-- <ul class="controls_container">
  76. <el-tooltip class="item" effect="dark" content="返回" placement="top">
  77. <li class="controls_item" @click="showClassIfy = false"><i class="el-icon-refresh-left" /></li>
  78. </el-tooltip>
  79. </ul> -->
  80. <el-button type="text" @click="showClassIfy = false">返回</el-button>
  81. <el-button type="text" @click.stop="setClassifyUploadImg">上传图片</el-button>
  82. <el-button type="text" @click.stop="setMachDeleteImg">批量删除</el-button>
  83. <template v-if="classIfyImgList.length > 0">
  84. <div class="class_img_list">
  85. <div
  86. v-for="btem in classIfyImgList"
  87. :key="btem.id"
  88. class="class_img_item"
  89. >
  90. <el-image
  91. :src="btem.thumbnail"
  92. fit="fill"
  93. :preview-src-list="[btem.img_url]"
  94. class="class_img"
  95. />
  96. <div class="class_img_controls">
  97. <el-tooltip class="item" effect="dark" content="选择批量删除" placement="top">
  98. <el-checkbox v-model="deleteImgs[btem.id]" />
  99. </el-tooltip>
  100. <el-tooltip class="item" effect="dark" content="删除图片" placement="top">
  101. <i class="el-icon-delete-solid control_detele" @click="submitDeleteImgOne(btem.id)" />
  102. </el-tooltip>
  103. </div>
  104. </div>
  105. </div>
  106. <div class="flex_center">
  107. <pagination
  108. :total="classIfyImgTotal"
  109. :page.sync="classImgParmas.page_index"
  110. :limit.sync="classImgParmas.page_size"
  111. @pagination="updateShowImgs"
  112. @updata:limit="updateShowImgs"
  113. />
  114. </div>
  115. </template>
  116. <div v-else class="photo_no">
  117. <i class="el-icon-receiving" />
  118. <p class="text">该分类暂无图片</p>
  119. </div>
  120. </template>
  121. <template v-else>
  122. <div v-if="classifyList.length > 0" class="classList">
  123. <div
  124. v-for="cItem in classifyList"
  125. :key="cItem.id"
  126. class="classItem"
  127. @click="showClassIfyImg(cItem.id)"
  128. >
  129. <i class="el-icon-folder-opened classItem-icon" />
  130. <p class="classItem-name">{{ cItem.image_name }}</p>
  131. <div style="width: 100%">
  132. <el-button type="text" @click.stop="updateClassify(cItem)">修改</el-button>
  133. <el-button type="text" @click.stop="toDeleteClassify(cItem.id)">删除</el-button>
  134. </div>
  135. </div>
  136. </div>
  137. <div v-else class="photo_no">
  138. <i class="el-icon-receiving" />
  139. <p class="text">暂无分类</p>
  140. </div>
  141. </template>
  142. </template>
  143. <template v-else>
  144. <div v-if="classImgList.length > 0">
  145. <div class="class_img_list">
  146. <div
  147. v-for="btem in classImgList"
  148. :key="btem.id"
  149. class="class_img_item"
  150. >
  151. <el-image
  152. v-if="+classParams.type === 0"
  153. :src="btem.thumbnail"
  154. fit="fill"
  155. :preview-src-list="[btem.img_url]"
  156. class="class_img"
  157. />
  158. <div v-else>
  159. <video :src="btem.img_url" controls class="class_video" />
  160. </div>
  161. <div class="class_img_controls">
  162. <el-tooltip class="item" effect="dark" content="选择批量删除" placement="top">
  163. <el-checkbox v-model="deleteImgs[btem.id]" />
  164. </el-tooltip>
  165. <el-tooltip class="item" effect="dark" :content="+classParams.type ? '删除视频' : '删除图片'" placement="top">
  166. <i class="el-icon-delete-solid control_detele" @click="submitDeleteImgOne(btem.id)" />
  167. </el-tooltip>
  168. </div>
  169. </div>
  170. </div>
  171. <div class="flex_center">
  172. <pagination
  173. :total="classImgTotal"
  174. :page.sync="classImgParmas.page_index"
  175. :limit.sync="classImgParmas.page_size"
  176. @pagination="updateShowImgs"
  177. />
  178. </div>
  179. </div>
  180. <div v-else class="photo_no">
  181. <i class="el-icon-receiving" />
  182. <p class="text">暂无内容</p>
  183. </div>
  184. </template>
  185. </el-collapse-item>
  186. </el-collapse>
  187. <pagination
  188. :total="classTotal"
  189. :page.sync="searchParams.page_index"
  190. :limit.sync="searchParams.page_size"
  191. @pagination="getClassList"
  192. />
  193. <!-- 添加分类名 -->
  194. <el-dialog
  195. :title="fileType ? '添加目录' : '修改目录'"
  196. :visible.sync="fileVis"
  197. width="500px"
  198. :close-on-click-modal="false"
  199. :before-close="resetClassParams"
  200. >
  201. <el-form ref="classForm" label-width="80px" :model="classParams" :rules="classRule" :hide-required-asterisk="true">
  202. <el-form-item label="分类名称:" prop="title">
  203. <el-input v-model="classParams.title" type="text" />
  204. </el-form-item>
  205. <el-form-item label="关联活动:" prop="activity_id">
  206. <el-select v-model="classParams.activity_id" style="width: 100%">
  207. <el-option
  208. v-for="item in season_list"
  209. :key="`${item.season}_${item.type}`"
  210. :label="item.name"
  211. :value="item.id"
  212. />
  213. </el-select>
  214. </el-form-item>
  215. <el-form-item label="排序:" prop="sort">
  216. <el-input v-model="classParams.sort" type="text" placeholder="数字越大越靠上" />
  217. </el-form-item>
  218. <el-form-item>
  219. <el-button v-if="fileType" type="primary" size="small" @click="submitAddClass">添加</el-button>
  220. <el-button v-else type="primary" size="small" @click="submitEditClass">修改</el-button>
  221. <el-button size="small" @click="resetClassParams">取消</el-button>
  222. </el-form-item>
  223. </el-form>
  224. </el-dialog>
  225. <!-- 上传图片 -->
  226. <el-dialog
  227. :title="+classParams.type === 0 ? '上传图片' : '上传视频'"
  228. :visible.sync="imgVis"
  229. width="800px"
  230. :close-on-click-modal="false"
  231. :before-close="updateShowImgs"
  232. >
  233. <div v-if="+classParams.type === 0">
  234. <el-upload
  235. class="upload-demo"
  236. drag
  237. action=""
  238. multiple
  239. accept=".jpg, .jpeg, .png"
  240. :http-request="submitUploadImg"
  241. :show-file-list="false"
  242. >
  243. <i class="el-icon-upload" />
  244. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  245. <div slot="tip" class="el-upload__tip">只能上传jpg/jpeg/png文件, 且图片最大不超过3M</div>
  246. </el-upload>
  247. </div>
  248. <div v-else>
  249. <el-upload
  250. class="upload-demo"
  251. drag
  252. action=""
  253. accept=".mp4"
  254. :http-request="submitUploadVideo"
  255. :show-file-list="false"
  256. >
  257. <i class="el-icon-upload" />
  258. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  259. <div slot="tip" class="el-upload__tip">上传视频类型为: .mp4 后缀的文件类型, 且视频最大不超过45M</div>
  260. </el-upload>
  261. </div>
  262. <ul class="upload_list_container">
  263. <li v-for="(item, i) in uploadImgs" :key="`upload_img_${i}`" class="upload_item">
  264. <p class="img_name">{{ item.name }}</p>
  265. <el-progress :percentage="item.progress" style="width: 300px" />
  266. </li>
  267. </ul>
  268. </el-dialog>
  269. <!-- 添加/修改分类 -->
  270. <el-dialog
  271. :title="dialog.classifyType ? '添加分类' : '修改分类'"
  272. :visible.sync="dialog.classify"
  273. width="520px"
  274. :close-on-click-modal="false"
  275. :before-close="resetClassIfy"
  276. >
  277. <el-form ref="classifyForm" label-width="100px" :rules="classifyRules" :model="classifyForm">
  278. <el-form-item label="分类名称:" prop="image_name">
  279. <el-input v-model="classifyForm.image_name" type="text" />
  280. </el-form-item>
  281. <el-form-item label="排序:" prop="sort">
  282. <el-input v-model="classifyForm.sort" type="text" />
  283. </el-form-item>
  284. </el-form>
  285. <template slot="footer">
  286. <el-button @click="resetClassIfy">取消</el-button>
  287. <el-button type="primary" @click="toPublishClassify">{{ dialog.classifyType ? '添加' : '修改' }}</el-button>
  288. </template>
  289. </el-dialog>
  290. </div>
  291. </template>
  292. <script>
  293. import {
  294. addClass,
  295. getClassList,
  296. deleteClass,
  297. editClass,
  298. uploadImg,
  299. getClassImgList,
  300. deleteClassImg,
  301. uploadVideo,
  302. getChildClass,
  303. getChildImg,
  304. addUpdateFolder,
  305. deleteFolder,
  306. uploadClassifyImg,
  307. deleteFolderImg
  308. } from '@/api/photo'
  309. export default {
  310. data() {
  311. return {
  312. fileVis: false,
  313. fileType: true,
  314. loadingFull: false,
  315. imgVis: false,
  316. classParams: {
  317. activity_id: '',
  318. title: '',
  319. sort: '',
  320. type: '0',
  321. id: ''
  322. },
  323. searchParams: {
  324. page_index: 1,
  325. page_size: 10,
  326. search_name: '',
  327. activity_id: ''
  328. },
  329. classRule: {
  330. activity_id: [
  331. { required: true, message: '请选请关联活动', trigger: 'change' }
  332. ],
  333. title: [
  334. { required: true, message: '请填写分类名称', trigger: 'blur' }
  335. ],
  336. sort: [
  337. { required: true, message: '请填写排序大小', trigger: 'blur' }
  338. ]
  339. },
  340. classList: [],
  341. classTotal: 0,
  342. uploadClassId: '',
  343. uploadImgs: [],
  344. classActived: [],
  345. classImgParmas: {
  346. page_index: 1,
  347. page_size: 80
  348. },
  349. classImgList: [],
  350. classImgTotal: 0,
  351. deleteImgs: {},
  352. isSelectAll: false,
  353. classifyList: [],
  354. classifyTotal: 0,
  355. classifyImgParams: {
  356. id: '',
  357. page_index: 1,
  358. page_size: 80
  359. },
  360. showClassIfy: false,
  361. classIfyImgList: [],
  362. classIfyImgTotal: 0,
  363. dialog: {
  364. classify: false,
  365. classifyType: true
  366. },
  367. classifyForm: {
  368. image_name: '',
  369. sort: '',
  370. image_class_id: '',
  371. id: '',
  372. data: null
  373. },
  374. classifyRules: {
  375. image_name: [
  376. { required: true, message: '请填写分类名称', trigger: 'blur' }
  377. ],
  378. sort: [
  379. { required: true, message: '请填写排序', trigger: 'blur' }
  380. ]
  381. }
  382. }
  383. },
  384. computed: {
  385. season_list() {
  386. return this.$store.state.user.season_list
  387. }
  388. },
  389. watch: {
  390. 'classParams.type'() {
  391. this.getClassList()
  392. }
  393. },
  394. created() {
  395. this.getClassList()
  396. },
  397. methods: {
  398. // 删除分类
  399. toDeleteClassify(id) {
  400. this.$confirm('确认删除这个分类吗?', '提示', {
  401. confirmButtonText: '确定',
  402. cancelButtonText: '取消',
  403. type: 'warning'
  404. }).then(() => {
  405. this.loadingFull = true
  406. deleteFolder({ id }).then(res => {
  407. this.loadingFull = false
  408. if (res.code === 200) {
  409. this.$message.success('删除分类成功')
  410. this.toggleImgList(this.classifyForm.data)
  411. } else {
  412. this.$message.error(res.message || '删除分类失败')
  413. }
  414. }).catch(() => {
  415. this.loadingFull = false
  416. this.$message.error('删除分类失败')
  417. })
  418. }).catch(() => {})
  419. },
  420. addClassify(data) {
  421. this.classifyForm.data = JSON.stringify(data)
  422. this.classifyForm.image_class_id = data.id
  423. this.dialog.classify = true
  424. this.dialog.classifyType = true
  425. },
  426. // 重置分类
  427. resetClassIfy() {
  428. this.classifyForm.image_name = ''
  429. this.classifyForm.sort = ''
  430. this.classifyForm.image_class_id = ''
  431. this.classifyForm.id = ''
  432. this.dialog.classify = false
  433. this.dialog.classifyType = false
  434. },
  435. // 修改分类
  436. updateClassify(data) {
  437. this.classifyForm.id = data.id
  438. this.classifyForm.image_name = data.image_name
  439. this.classifyForm.sort = data.sort
  440. this.dialog.classify = true
  441. this.dialog.classifyType = false
  442. },
  443. // 增加修改分类
  444. toPublishClassify() {
  445. this.$refs.classifyForm.validate(valid => {
  446. if (valid) {
  447. const { id, image_class_id, sort, image_name, data } = this.classifyForm
  448. const params = this.dialog.classifyType ? {
  449. image_class_id, sort, image_name
  450. } : {
  451. id, image_name, sort
  452. }
  453. this.loadingFull = true
  454. addUpdateFolder(params).then(res => {
  455. this.loadingFull = false
  456. if (res.code === 200) {
  457. this.$message.success(this.classifyType ? '添加成功' : '修改成功')
  458. this.toggleImgList(data)
  459. this.resetClassIfy()
  460. } else {
  461. this.$message.error(res.message || this.classifyType ? '添加分类失败' : '修改分类失败')
  462. }
  463. }).catch(() => {
  464. this.loadingFull = false
  465. this.$message.error(this.classifyType ? '添加分类失败' : '修改分类失败')
  466. })
  467. } else {
  468. return false
  469. }
  470. })
  471. },
  472. // 重置添加分类
  473. resetClassParams() {
  474. this.classParams.activity_id = ''
  475. this.classParams.title = ''
  476. this.classParams.sort = ''
  477. this.classParams.id = ''
  478. this.fileVis = false
  479. this.fileType = true
  480. },
  481. // 获取分类列表
  482. getClassList() {
  483. const params = Object.assign({}, this.searchParams)
  484. params.type = this.classParams.type
  485. this.loadingFull = true
  486. getClassList(params).then(res => {
  487. this.loadingFull = false
  488. if (res.code === 200) {
  489. this.classList = res.data.list.map(item => {
  490. item.isSelectAll = false
  491. return item
  492. })
  493. this.classTotal = res.data.total
  494. } else {
  495. this.$message.error(res.message || '获取相册失败')
  496. }
  497. }).catch(() => {
  498. this.loadingFull = false
  499. this.$message.error('获取相册失败')
  500. })
  501. },
  502. // 添加分类
  503. submitAddClass() {
  504. this.$refs.classForm.validate((valid) => {
  505. if (valid) {
  506. this.loadingFull = true
  507. addClass(this.classParams).then(res => {
  508. this.loadingFull = false
  509. if (res.code === 200) {
  510. this.$message.success('添加分类成功')
  511. this.resetClassParams()
  512. this.getClassList()
  513. } else {
  514. this.$message.error(res.message || '添加分类失败')
  515. }
  516. }).catch(() => {
  517. this.loadingFull = false
  518. this.$message.error('添加分类失败')
  519. })
  520. } else {
  521. return false
  522. }
  523. })
  524. },
  525. // 删除分类
  526. submitDeleteClass(id) {
  527. this.$confirm('确认删除这个分类目录', '提示', {
  528. confirmButtonText: '确定',
  529. cancelButtonText: '取消',
  530. type: 'warning'
  531. }).then(() => {
  532. this.loadingFull = true
  533. deleteClass({ id }).then(res => {
  534. this.loadingFull = false
  535. if (res.code === 200) {
  536. this.$message.success('删除分类成功')
  537. this.getClassList()
  538. } else {
  539. this.$message.error(res.message || '删除分类失败')
  540. }
  541. }).catch((e) => {
  542. this.loadingFull = false
  543. this.$message.error('删除分类失败')
  544. })
  545. }).catch(() => {})
  546. },
  547. // 修改分类
  548. setEditClass(item) {
  549. const { imgclass_name, activity_id, sort, id } = item
  550. this.classParams.title = imgclass_name
  551. this.classParams.sort = sort
  552. this.classParams.activity_id = activity_id
  553. this.classParams.id = id
  554. this.fileType = false
  555. this.fileVis = true
  556. },
  557. submitEditClass() {
  558. this.$refs.classForm.validate((valid) => {
  559. if (valid) {
  560. this.loadingFull = true
  561. editClass(this.classParams).then(res => {
  562. this.loadingFull = false
  563. if (res.code === 200) {
  564. this.$message.success('修改分类成功')
  565. this.resetClassParams()
  566. this.getClassList()
  567. } else {
  568. this.$message.error(res.message || '修改分类成功')
  569. }
  570. }).catch(() => {
  571. this.loadingFull = false
  572. this.$message.error('修改分类成功')
  573. })
  574. } else {
  575. return false
  576. }
  577. })
  578. },
  579. // 显示分类图片
  580. showClassIfyImg(id) {
  581. this.uploadClassId = id
  582. this.classifyImgParams.id = id
  583. this.showClassIfy = true
  584. this.getClassifyImg()
  585. },
  586. // 获取分类图片
  587. getClassifyImg() {
  588. this.loadingFull = true
  589. getChildImg(this.classifyImgParams).then(res => {
  590. this.loadingFull = false
  591. if (res.code === 200) {
  592. this.classIfyImgList = res.data.list
  593. this.classIfyImgTotal = res.data.total
  594. } else {
  595. this.$message.error(res.message || '获取图片失败')
  596. }
  597. }).catch(() => {
  598. this.loadingFull = false
  599. this.$message.error('获取图片失败')
  600. })
  601. },
  602. resetShowImgs() {
  603. this.deleteImgs = {}
  604. this.classImgList = []
  605. this.classImgTotal = 0
  606. this.classIfyImgList = []
  607. this.showClassIfy = false
  608. this.classList.forEach(item => {
  609. this.$set(item, 'isSelectAll', false)
  610. })
  611. },
  612. // 获取图片列表
  613. toggleImgList(data) {
  614. if (!data) return false
  615. data = JSON.parse(data)
  616. this.resetShowImgs()
  617. if (!data.is_old && +this.classParams.type === 0) {
  618. this.loadingFull = true
  619. this.classifyForm.data = JSON.stringify(data)
  620. getChildClass({ id: data.id }).then(res => {
  621. this.loadingFull = false
  622. if (res.code === 200) {
  623. this.classifyList = res.data.list
  624. this.classifyTotal = res.data.total
  625. } else {
  626. this.$message.error(res.message || '获取分类失败')
  627. }
  628. }).catch(() => {
  629. this.loadingFull = false
  630. this.$message.error('获取分类失败')
  631. })
  632. } else {
  633. console.log(this.classImgParmas)
  634. const { page_index, page_size } = this.classImgParmas
  635. this.classifyForm.data = ''
  636. this.loadingFull = true
  637. getClassImgList({
  638. id: data.id,
  639. page_index,
  640. page_size
  641. }).then(res => {
  642. this.loadingFull = false
  643. if (res.code === 200) {
  644. this.classImgList = res.data.list
  645. this.classImgTotal = res.data.total
  646. } else {
  647. this.$message.error(res.message || '获取图片失败')
  648. }
  649. }).catch(() => {
  650. this.loadingFull = false
  651. this.$message.error('获取图片失败')
  652. })
  653. }
  654. },
  655. // 上传完成更新图片
  656. updateShowImgs({ page, limit }) {
  657. if (this.imgVis) {
  658. this.uploadImgs = []
  659. this.imgVis = false
  660. }
  661. if (+this.classParams.type === 1 && this.classifyForm.data) {
  662. if (page) {
  663. this.classifyImgParams.page_size = limit
  664. this.classifyImgParams.page_index = page
  665. }
  666. this.getClassifyImg()
  667. } else {
  668. if (this.classActived) {
  669. if (page) {
  670. this.classImgParmas.page_index = page
  671. this.classImgParmas.page_size = limit
  672. }
  673. this.toggleImgList(this.classActived)
  674. }
  675. }
  676. },
  677. // 上传分类图片
  678. setClassifyUploadImg(id) {
  679. this.imgVis = true
  680. },
  681. // 上传图片
  682. setUploadImg(id) {
  683. this.uploadClassId = id
  684. this.imgVis = true
  685. },
  686. submitUploadImg(params) {
  687. if (!this.uploadClassId) {
  688. this.$message.error('获取分类Id失败')
  689. this.imgVis = false
  690. return false
  691. }
  692. const file = params.file
  693. const { size } = file
  694. if (size > 1024 * 1024 * 3) {
  695. this.$message.error('图片体积最大为3M')
  696. return false
  697. }
  698. this.uploadImgs.push({
  699. file,
  700. name: file.name,
  701. progress: 0
  702. })
  703. if (this.classifyForm.data) {
  704. const formData = new FormData()
  705. formData.append('file', file)
  706. formData.append('id', this.uploadClassId)
  707. const _this = this
  708. const _i = this.uploadImgs.length - 1
  709. uploadClassifyImg(formData, ({ loaded, total }) => {
  710. const complete = (loaded / total * 100) | 0
  711. _this.uploadImgs[_i].progress = complete
  712. }).then(res => {
  713. if (res.code === 200) {
  714. this.$message.success('上传图片成功')
  715. } else {
  716. this.$message.error(res.message || '上传图片失败')
  717. }
  718. }).catch((e) => {
  719. this.$message.error('上传图片失败')
  720. })
  721. } else {
  722. this.uploadImg(file, this.uploadImgs.length - 1)
  723. }
  724. },
  725. uploadImg(file, i) {
  726. const _this = this
  727. const formData = new FormData()
  728. formData.append('file', file)
  729. formData.append('id', this.uploadClassId)
  730. formData.append('type', this.classParams.type)
  731. uploadImg(formData, ({ loaded, total }) => {
  732. const complete = (loaded / total * 100) | 0
  733. _this.uploadImgs[i].progress = complete
  734. }).then(res => {
  735. if (res.code === 200) {
  736. this.$message.success('上传图片成功')
  737. } else {
  738. this.$message.error(res.message || '上传图片失败')
  739. }
  740. }).catch((e) => {
  741. this.$message.error('上传图片失败')
  742. })
  743. },
  744. // 全选图片
  745. setSeleceAllImg(data) {
  746. data.isSelectAll = !data.isSelectAll
  747. if (data.isSelectAll) {
  748. this.classImgList.forEach(item => {
  749. this.$set(this.deleteImgs, item.id, true)
  750. })
  751. } else {
  752. const obj = Object.assign({}, this.deleteImgs)
  753. Object.keys(obj).forEach(id => {
  754. this.$set(this.deleteImgs, id, false)
  755. })
  756. }
  757. },
  758. // 批量删除
  759. setMachDeleteImg() {
  760. const obj = Object.assign({}, this.deleteImgs)
  761. const selectedArr = Object.keys(obj).filter(id => obj[id])
  762. if (selectedArr.length === 0) {
  763. this.$message.error('请至少选择一个')
  764. return false
  765. }
  766. this.$confirm('是否确认删除选择图片?', '提示', {
  767. confirmButtonText: '确定',
  768. cancelButtonText: '取消',
  769. type: 'warning'
  770. }).then(() => {
  771. this.submitDeleteImg(selectedArr)
  772. }).catch(() => {})
  773. },
  774. // 单个删除
  775. submitDeleteImgOne(id) {
  776. this.$confirm(`是否确认删除该${+this.classParams.type ? '视频' : '图片'}?`, '提示', {
  777. confirmButtonText: '确定',
  778. cancelButtonText: '取消',
  779. type: 'warning'
  780. }).then(() => {
  781. this.submitDeleteImg([id])
  782. }).catch(() => {})
  783. },
  784. // 提交删除
  785. submitDeleteImg(ids) {
  786. if (this.classifyForm.data) {
  787. deleteFolderImg({ ids }).then(res => {
  788. if (res.code === 200) {
  789. this.$message.success('删除图片成功')
  790. this.deleteImgs = {}
  791. this.getClassifyImg()
  792. } else {
  793. this.$message.error(res.message || '删除图片失败')
  794. }
  795. }).catch(() => {
  796. this.$message.error('删除图片失败')
  797. })
  798. } else {
  799. deleteClassImg({ ids }).then(res => {
  800. if (res.code === 200) {
  801. this.$message.success('删除图片成功')
  802. this.deleteImgs = {}
  803. this.updateShowImgs()
  804. } else {
  805. this.$message.error(res.message || '删除图片失败')
  806. }
  807. }).catch(() => {
  808. this.$message.error('删除图片失败')
  809. })
  810. }
  811. },
  812. // 上传视频
  813. submitUploadVideo(params) {
  814. const file = params.file
  815. const { size, type } = file
  816. if (size > 45 * 1024 * 1024) {
  817. this.$message.error('视频最大不超过45M')
  818. return false
  819. }
  820. const fileType = ['video/mp4']
  821. console.log(type)
  822. if (!fileType.includes(type)) {
  823. this.$message.error('上传视频类型不是mp4类型')
  824. return false
  825. }
  826. this.uploadImgs.push({
  827. file,
  828. name: file.name,
  829. progress: 0
  830. })
  831. this.uploadVideo(file, this.uploadImgs.length - 1)
  832. },
  833. uploadVideo(file, i) {
  834. const _this = this
  835. const formData = new FormData()
  836. formData.append('file', file)
  837. formData.append('id', this.uploadClassId)
  838. formData.append('type', this.classParams.type)
  839. uploadVideo(formData, ({ loaded, total }) => {
  840. const complete = (loaded / total * 100) | 0
  841. _this.uploadImgs[i].progress = complete
  842. }).then(res => {
  843. if (res.code === 200) {
  844. this.$message.success('上传视频成功')
  845. } else {
  846. this.$message.error(res.message || '上传视频失败')
  847. }
  848. }).catch(() => {
  849. this.$message.error('上传视频失败')
  850. })
  851. }
  852. }
  853. }
  854. </script>
  855. <style scoped lang="scss">
  856. /deep/ .el-tree-node__content {
  857. height: auto;
  858. }
  859. .photo_title_container {
  860. display: flex;
  861. justify-content: space-between;
  862. align-items: center;
  863. flex: 1;
  864. padding-right: 20px;
  865. // height: 48px;
  866. // line-height: 48px;
  867. }
  868. .controls_container {
  869. list-style: none;
  870. display: flex;
  871. align-items: center;
  872. justify-content: flex-start;
  873. padding: 0;
  874. .controls_item {
  875. width: 25px;
  876. height: 25px;
  877. display: flex;
  878. justify-content: center;
  879. align-items: center;
  880. background: #cccccc;
  881. color: #ffffff;
  882. margin-right: 10px;
  883. border-radius: 2px;
  884. font-size: 14px;
  885. cursor: pointer;
  886. &:hover {
  887. background: #409EFF !important;
  888. }
  889. }
  890. .controls_item_active {
  891. background: #409EFF !important;
  892. }
  893. }
  894. .photo_no {
  895. display: flex;
  896. align-items: center;
  897. justify-content: center;
  898. padding: 100px;
  899. font-size: 100px;
  900. display: flex;
  901. justify-content: center;
  902. align-items: center;
  903. flex-direction: column;
  904. color: #cccccc;
  905. .text {
  906. font-size: 18px;
  907. font-weight: 500;
  908. }
  909. }
  910. /deep/ .el-upload{
  911. width: 100%;
  912. .el-upload-dragger{
  913. width: 100%;
  914. }
  915. }
  916. .upload_list_container {
  917. list-style: none;
  918. padding: 0;
  919. max-height: 500px;
  920. overflow-y: scroll;
  921. .upload_item {
  922. list-style: none;
  923. margin-bottom: 15px;
  924. display: flex;
  925. justify-content: space-between;
  926. align-items: center;
  927. .img_name {
  928. flex: 1;
  929. overflow: hidden;
  930. text-overflow: ellipsis;
  931. white-space: nowrap;
  932. padding-right: 10px;
  933. margin: 0;
  934. }
  935. }
  936. }
  937. .class_img_list {
  938. display: flex;
  939. justify-content: flex-start;
  940. flex-wrap: wrap;
  941. .class_img_item {
  942. margin-right: 10px;
  943. margin-bottom: 10px;
  944. position: relative;
  945. .class_img {
  946. width: 100px;
  947. height: 100px;
  948. }
  949. .class_video {
  950. width: 400px;
  951. }
  952. .class_img_controls {
  953. display: flex;
  954. justify-content: space-between;
  955. align-items: center;
  956. .control_detele {
  957. font-size: 14px;
  958. }
  959. i {
  960. cursor: pointer;
  961. }
  962. }
  963. }
  964. }
  965. /deep/ .pagination-container{
  966. padding: 0;
  967. }
  968. .flex_center {
  969. display: flex;
  970. justify-content: center;
  971. align-items: center;
  972. }
  973. .classList {
  974. display: flex;
  975. align-items: center;
  976. justify-content: flex-start;
  977. flex-wrap: wrap;
  978. .classItem {
  979. display: flex;
  980. justify-content: center;
  981. align-items: flex-start;
  982. flex-direction: column;
  983. cursor: pointer;
  984. margin-right: 20px;
  985. margin-bottom: 20px;
  986. &-icon {
  987. width: 130px;
  988. height: 130px;
  989. background: #f5f7fa;
  990. border: 1px solid #f1f1f1;
  991. font-size: 100px;
  992. display: flex;
  993. align-items: center;
  994. justify-content: center;
  995. }
  996. &-name {
  997. line-height: 30px;
  998. height: 30px;
  999. text-align: center;
  1000. margin: 0;
  1001. font-size: 12px;
  1002. overflow: hidden;
  1003. text-overflow: ellipsis;
  1004. white-space: nowrap;
  1005. }
  1006. }
  1007. }
  1008. </style>