new_photo.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  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. console.log(e)
  742. this.$message.error('上传图片失败')
  743. })
  744. },
  745. // 全选图片
  746. setSeleceAllImg(data) {
  747. data.isSelectAll = !data.isSelectAll
  748. if (data.isSelectAll) {
  749. this.classImgList.forEach(item => {
  750. this.$set(this.deleteImgs, item.id, true)
  751. })
  752. } else {
  753. const obj = Object.assign({}, this.deleteImgs)
  754. Object.keys(obj).forEach(id => {
  755. this.$set(this.deleteImgs, id, false)
  756. })
  757. }
  758. },
  759. // 批量删除
  760. setMachDeleteImg() {
  761. const obj = Object.assign({}, this.deleteImgs)
  762. const selectedArr = Object.keys(obj).filter(id => obj[id])
  763. if (selectedArr.length === 0) {
  764. this.$message.error('请至少选择一个')
  765. return false
  766. }
  767. this.$confirm('是否确认删除选择图片?', '提示', {
  768. confirmButtonText: '确定',
  769. cancelButtonText: '取消',
  770. type: 'warning'
  771. }).then(() => {
  772. this.submitDeleteImg(selectedArr)
  773. }).catch(() => {})
  774. },
  775. // 单个删除
  776. submitDeleteImgOne(id) {
  777. this.$confirm(`是否确认删除该${+this.classParams.type ? '视频' : '图片'}?`, '提示', {
  778. confirmButtonText: '确定',
  779. cancelButtonText: '取消',
  780. type: 'warning'
  781. }).then(() => {
  782. this.submitDeleteImg([id])
  783. }).catch(() => {})
  784. },
  785. // 提交删除
  786. submitDeleteImg(ids) {
  787. if (this.classifyForm.data) {
  788. deleteFolderImg({ ids }).then(res => {
  789. if (res.code === 200) {
  790. this.$message.success('删除图片成功')
  791. this.deleteImgs = {}
  792. this.getClassifyImg()
  793. } else {
  794. this.$message.error(res.message || '删除图片失败')
  795. }
  796. }).catch(() => {
  797. this.$message.error('删除图片失败')
  798. })
  799. } else {
  800. deleteClassImg({ ids }).then(res => {
  801. if (res.code === 200) {
  802. this.$message.success('删除图片成功')
  803. this.deleteImgs = {}
  804. this.updateShowImgs()
  805. } else {
  806. this.$message.error(res.message || '删除图片失败')
  807. }
  808. }).catch(() => {
  809. this.$message.error('删除图片失败')
  810. })
  811. }
  812. },
  813. // 上传视频
  814. submitUploadVideo(params) {
  815. const file = params.file
  816. const { size, type } = file
  817. if (size > 45 * 1024 * 1024) {
  818. this.$message.error('视频最大不超过45M')
  819. return false
  820. }
  821. const fileType = ['video/mp4']
  822. console.log(type)
  823. if (!fileType.includes(type)) {
  824. this.$message.error('上传视频类型不是mp4类型')
  825. return false
  826. }
  827. this.uploadImgs.push({
  828. file,
  829. name: file.name,
  830. progress: 0
  831. })
  832. this.uploadVideo(file, this.uploadImgs.length - 1)
  833. },
  834. uploadVideo(file, i) {
  835. const _this = this
  836. const formData = new FormData()
  837. formData.append('file', file)
  838. formData.append('id', this.uploadClassId)
  839. formData.append('type', this.classParams.type)
  840. uploadVideo(formData, ({ loaded, total }) => {
  841. const complete = (loaded / total * 100) | 0
  842. _this.uploadImgs[i].progress = complete
  843. }).then(res => {
  844. if (res.code === 200) {
  845. this.$message.success('上传视频成功')
  846. } else {
  847. this.$message.error(res.message || '上传视频失败')
  848. }
  849. }).catch(() => {
  850. this.$message.error('上传视频失败')
  851. })
  852. }
  853. }
  854. }
  855. </script>
  856. <style scoped lang="scss">
  857. /deep/ .el-tree-node__content {
  858. height: auto;
  859. }
  860. .photo_title_container {
  861. display: flex;
  862. justify-content: space-between;
  863. align-items: center;
  864. flex: 1;
  865. padding-right: 20px;
  866. // height: 48px;
  867. // line-height: 48px;
  868. }
  869. .controls_container {
  870. list-style: none;
  871. display: flex;
  872. align-items: center;
  873. justify-content: flex-start;
  874. padding: 0;
  875. .controls_item {
  876. width: 25px;
  877. height: 25px;
  878. display: flex;
  879. justify-content: center;
  880. align-items: center;
  881. background: #cccccc;
  882. color: #ffffff;
  883. margin-right: 10px;
  884. border-radius: 2px;
  885. font-size: 14px;
  886. cursor: pointer;
  887. &:hover {
  888. background: #409EFF !important;
  889. }
  890. }
  891. .controls_item_active {
  892. background: #409EFF !important;
  893. }
  894. }
  895. .photo_no {
  896. display: flex;
  897. align-items: center;
  898. justify-content: center;
  899. padding: 100px;
  900. font-size: 100px;
  901. display: flex;
  902. justify-content: center;
  903. align-items: center;
  904. flex-direction: column;
  905. color: #cccccc;
  906. .text {
  907. font-size: 18px;
  908. font-weight: 500;
  909. }
  910. }
  911. /deep/ .el-upload{
  912. width: 100%;
  913. .el-upload-dragger{
  914. width: 100%;
  915. }
  916. }
  917. .upload_list_container {
  918. list-style: none;
  919. padding: 0;
  920. max-height: 500px;
  921. overflow-y: scroll;
  922. .upload_item {
  923. list-style: none;
  924. margin-bottom: 15px;
  925. display: flex;
  926. justify-content: space-between;
  927. align-items: center;
  928. .img_name {
  929. flex: 1;
  930. overflow: hidden;
  931. text-overflow: ellipsis;
  932. white-space: nowrap;
  933. padding-right: 10px;
  934. margin: 0;
  935. }
  936. }
  937. }
  938. .class_img_list {
  939. display: flex;
  940. justify-content: flex-start;
  941. flex-wrap: wrap;
  942. .class_img_item {
  943. margin-right: 10px;
  944. margin-bottom: 10px;
  945. position: relative;
  946. .class_img {
  947. width: 100px;
  948. height: 100px;
  949. }
  950. .class_video {
  951. width: 400px;
  952. }
  953. .class_img_controls {
  954. display: flex;
  955. justify-content: space-between;
  956. align-items: center;
  957. .control_detele {
  958. font-size: 14px;
  959. }
  960. i {
  961. cursor: pointer;
  962. }
  963. }
  964. }
  965. }
  966. /deep/ .pagination-container{
  967. padding: 0;
  968. }
  969. .flex_center {
  970. display: flex;
  971. justify-content: center;
  972. align-items: center;
  973. }
  974. .classList {
  975. display: flex;
  976. align-items: center;
  977. justify-content: flex-start;
  978. flex-wrap: wrap;
  979. .classItem {
  980. display: flex;
  981. justify-content: center;
  982. align-items: flex-start;
  983. flex-direction: column;
  984. cursor: pointer;
  985. margin-right: 20px;
  986. margin-bottom: 20px;
  987. &-icon {
  988. width: 130px;
  989. height: 130px;
  990. background: #f5f7fa;
  991. border: 1px solid #f1f1f1;
  992. font-size: 100px;
  993. display: flex;
  994. align-items: center;
  995. justify-content: center;
  996. }
  997. &-name {
  998. line-height: 30px;
  999. height: 30px;
  1000. text-align: center;
  1001. margin: 0;
  1002. font-size: 12px;
  1003. overflow: hidden;
  1004. text-overflow: ellipsis;
  1005. white-space: nowrap;
  1006. }
  1007. }
  1008. }
  1009. </style>