materialManage.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <template>
  2. <el-dialog :title="fileType === 1 ? `图片素材` : `视频素材`" :visible.sync="visible" width="1100px"
  3. :before-close="dialogBeforeClose" :close-on-click-modal="false" :close-on-press-escape="false"
  4. class="material-wrapper">
  5. <div class="material-cont clearfix">
  6. <div class="material-side image-side">
  7. <div class="pictrue-tabs">{{ fileType === 1 ? "我的图片" : "我的视频" }}</div>
  8. <div class="side-btns">
  9. <div class="file-upload">
  10. <!-- <el-upload class="upload-demo" action="/api/sys/oss/upload" :on-success="imageUploadSuccess"
  11. :show-file-list="false">
  12. <el-button size="small" type="primary">{{ fileType === 1 ? "上传图片" : "上传视频" }}</el-button>
  13. </el-upload> -->
  14. <el-upload class="upload-demo" :action="uploadurl" :on-success="imageUploadSuccess"
  15. :show-file-list="false">
  16. <el-button size="small" type="primary">{{ fileType === 1 ? "上传图片" : "上传视频" }}</el-button>
  17. </el-upload>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="material-list image-list" element-loading-text="加载中" v-loading="dataListLoading">
  22. <div>
  23. <!-- <el-input clearable v-model="dataForm.title" placeholder="请输入素材名称" size="mini"
  24. style="margin-bottom: 14px; width: 200px; margin-right: 10px;"></el-input>
  25. <el-button type="primary" @click="getDataList" size="mini">搜索</el-button> -->
  26. <div v-if="dataList.length > 0">
  27. <ul class="list-box image-box clearfix" v-if="fileType === 1">
  28. <li class="image-item list-item" @click="chooseMediaByIndexHandle(index)"
  29. :class="{ active: isAllOption }" v-for="(item, index) in dataList" :key="index">
  30. <div class="del-btn" v-if="item.checked">✕</div>
  31. <span class="checked-item" v-if="item.checked"></span>
  32. <img class="bg-img" :src="item.url" alt="" />
  33. <div class="inline-text-editor"><input maxlength="50" readonly="readonly"
  34. v-model="item.title"></div>
  35. </li>
  36. </ul>
  37. <ul class="list-box video-box clearfix" v-if="fileType === 2">
  38. <li class="video-item list-item" @click="chooseMediaByIndexHandle(index)"
  39. :class="{ active: isAllOption }" v-for="(item, index) in dataList" :key="index">
  40. <div class="del-btn" v-if="item.checked">✕</div>
  41. <span class="checked-item" v-if="item.checked"></span>
  42. <video :src="item.src" poster=""></video>
  43. <div class="inline-text-editor"><input maxlength="50" readonly="readonly"
  44. :value="item.title"></div>
  45. <div class="video-info clearfix">
  46. <div class="video-info-left" v-if="false">1280*720</div>
  47. <div class="video-info-right" v-if="false">5.65MB</div>
  48. </div>
  49. <div class="video-duration" v-if="false">00:50</div>
  50. </li>
  51. </ul>
  52. </div>
  53. <div class="resourceNone" v-else>
  54. <img src="@/assets/images/resouceNone.png"
  55. style="display: block;;width:400px;margin:20px auto 0" alt="" />
  56. <p style="text-align: center;">Sorry,没有搜到相关内容</p>
  57. </div>
  58. <div class="list-footer clearfix" v-if="page > 1 || dataList.length > 0">
  59. <div class="list-ctrl">
  60. <el-button size="small" @click="batchOptions" v-if="!isAllOption">批量操作</el-button>
  61. <el-button type="primary" @click="completeMediaHandle" size="small" v-if="isAllOption">完成
  62. </el-button>
  63. <el-button size="small" @click="deleteMediaHandle" class="ctrl-del" v-if="isAllOption">删除
  64. </el-button>
  65. <el-checkbox v-model="checked" @change="chooseMediaHandle" v-if="isAllOption">全选
  66. </el-checkbox>
  67. </div>
  68. <div class="list-page">
  69. <el-pagination :current-page="page" :page-sizes="[15, 30, 75, 150]" :page-size="limit"
  70. :total="total" layout="total, sizes, prev, pager, next, jumper"
  71. @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
  72. </el-pagination>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </el-dialog>
  79. </template>
  80. <script>
  81. import service from "@/utlis/axios";
  82. var that = null
  83. export default {
  84. name: 'materialManage',
  85. props: {
  86. fileType: {
  87. type: Number,
  88. required: true
  89. },
  90. itemOrSrc: {
  91. type: String,
  92. },
  93. onSuccess: {
  94. type: Function,
  95. required: true
  96. }
  97. },
  98. data: function () {
  99. return {
  100. uploadurl:process.env.NODE_ENV == 'development'?'/api/sys/oss/upload':'/sys/oss/upload',
  101. visible: false,
  102. mixinViewModuleOptions: {
  103. getDataListURL: '/material/page',
  104. },
  105. dataForm: {
  106. fileType: 1,
  107. title: ''
  108. },
  109. dataList: [],
  110. page: 1, // 当前页码
  111. limit: 15, // 每页数
  112. total: 0, // 总条数
  113. dataListLoading: false, // 数据列表,loading状态
  114. dataListSelections: [], // 数据列表,多选项
  115. isAllOption: false,
  116. checked: false
  117. }
  118. },
  119. beforeCreate: function () {
  120. that = this;
  121. },
  122. created: function () {
  123. that.dataForm.fileType = that.fileType;
  124. that.visible = true;
  125. that.query()
  126. },
  127. methods: {
  128. imageUploadSuccess: function (json) {
  129. that.getDataList();
  130. },
  131. query: function () {
  132. that.dataListLoading = true;
  133. service.get("/sys/oss/page", {
  134. params: {
  135. page: that.page,
  136. limit: that.limit,
  137. fileType: that.dataForm.fileType,
  138. }
  139. }).then((res) => {
  140. that.dataListLoading = false;
  141. if (res.data.code != 0) {
  142. that.dataList = [];
  143. that.total = 0;
  144. return that.$message.error(res.data.data.msg);
  145. }
  146. that.dataList = res.data.data.list;
  147. that.total = res.data.data.total;
  148. }).catch(function () {
  149. that.dataListLoading = false;
  150. });
  151. },
  152. // 分页, 每页条数
  153. pageSizeChangeHandle: function (val) {
  154. that.page = 1;
  155. that.limit = val;
  156. that.query();
  157. },
  158. // 分页, 当前页
  159. pageCurrentChangeHandle: function (val) {
  160. that.page = val;
  161. that.query();
  162. },
  163. getDataList: function () {
  164. that.page = 1;
  165. that.query();
  166. },
  167. dialogBeforeClose: function () {
  168. that.visible = false;
  169. that.$parent.materialVisible = false;
  170. },
  171. batchOptions: function () {
  172. that.dataList = that.dataList.map(s => {
  173. s.checked = true;
  174. return s;
  175. })
  176. that.checked = true;
  177. that.isAllOption = true;
  178. },
  179. chooseMediaByIndexHandle: function (index) {
  180. if (that.isAllOption) { //操作
  181. that.$set(that.dataList[index], 'checked', !that.dataList[index].checked);
  182. that.$forceUpdate();
  183. } else { //选择图片
  184. that.visible = false;
  185. if (that.itemOrSrc && that.itemOrSrc == 'item') {
  186. that.onSuccess.call(this, that.dataList[index]);
  187. } else {
  188. that.onSuccess.call(this, that.dataList[index].src);
  189. }
  190. }
  191. },
  192. chooseMediaHandle: function () {
  193. //全部操作
  194. that.dataList = that.dataList.map(s => {
  195. s.checked = that.checked;
  196. return s;
  197. })
  198. },
  199. completeMediaHandle: function () {
  200. that.dataList = that.dataList.map(s => {
  201. s.checked = false;
  202. return s;
  203. })
  204. that.checked = false;
  205. that.isAllOption = false;
  206. },
  207. deleteMediaHandle: function () {
  208. if (!that.dataList.some(ss => ss.checked)) {
  209. return that.$message.error('未选择文件');
  210. }
  211. that.$confirm('删除?', '删除', {
  212. confirmButtonText: '确认',
  213. cancelButtonText: '取消',
  214. type: 'warning'
  215. }).then(function () {
  216. service.delete('/sys/oss', { 'data': that.dataList.filter(item=> {return item.checked==true}).map(item => item.id) })
  217. .then(function (res) {
  218. if (res.data.code !== 0) return that.$message.error(res.data.msg);
  219. that.$message({
  220. message: '操作成功',
  221. type: 'success',
  222. duration: 500,
  223. onClose: function () {
  224. that.query();
  225. }
  226. });
  227. }).catch(function () {
  228. });
  229. }).catch(function () {
  230. });
  231. }
  232. }
  233. }
  234. </script>
  235. <style scoped>
  236. .clearfix:after {
  237. visibility: hidden;
  238. display: block;
  239. font-size: 0;
  240. content: " ";
  241. height: 0;
  242. }
  243. .clearfix:after {
  244. content: "";
  245. display: table;
  246. clear: both;
  247. }
  248. /* 弹窗 */
  249. .el-dialog__wrapper .el-dialog .el-dialog__header {
  250. padding-top: 16px;
  251. padding-bottom: 16px;
  252. border-bottom: 1px solid #dcdcdc;
  253. }
  254. /* 图片素材 */
  255. .material-wrapper .el-dialog__body {
  256. padding: 0 !important;
  257. }
  258. .material-side {
  259. float: left;
  260. position: relative;
  261. width: 180px;
  262. text-align: center;
  263. border-right: 1px solid #eaeff4;
  264. box-sizing: border-box;
  265. padding-right: 20px;
  266. }
  267. .material-side.image-side {
  268. height: 640px;
  269. }
  270. .pictrue-tabs {
  271. width: 160px;
  272. height: 50px;
  273. line-height: 50px;
  274. padding-left: 24px;
  275. text-align: left;
  276. background: #edf1ff;
  277. box-sizing: border-box;
  278. }
  279. .material-side .side-btns {
  280. position: absolute;
  281. bottom: 0;
  282. left: 0;
  283. width: 100%;
  284. padding-bottom: 14px;
  285. }
  286. .file-upload {
  287. display: inline-block;
  288. }
  289. .material-side .side-btns .el-button {
  290. display: block;
  291. width: 132px;
  292. margin: 10px auto;
  293. border-radius: 16px;
  294. }
  295. .material-list {
  296. float: left;
  297. width: 820px;
  298. box-sizing: border-box;
  299. overflow: hidden;
  300. }
  301. .material-list.image-list {
  302. padding: 24px 18px;
  303. }
  304. .material-list .list-box.image-box {
  305. height: 510px;
  306. }
  307. .material-list .list-box.video-box {
  308. height: 450px;
  309. }
  310. .material-list .list-box .list-item {
  311. position: relative;
  312. box-sizing: border-box;
  313. cursor: pointer;
  314. }
  315. .material-list .list-box .image-item {
  316. float: left;
  317. display: block;
  318. width: 130px;
  319. height: 130px;
  320. margin: 0 6px 40px;
  321. background: #e0e0e0;
  322. }
  323. .material-list .list-box .image-item .bg-img {
  324. width: 100%;
  325. height: 100%;
  326. box-sizing: border-box;
  327. background-size: contain;
  328. background-repeat: no-repeat;
  329. background-position: 50%;
  330. }
  331. .material-list .list-box .video-item {
  332. float: left;
  333. display: block;
  334. width: 130px;
  335. height: 130px;
  336. margin: 0 6px 40px;
  337. background: #e0e0e0;
  338. }
  339. .material-list .list-box .video-item video {
  340. display: block;
  341. width: 100%;
  342. height: 100%;
  343. box-sizing: border-box;
  344. }
  345. .inline-text-editor input {
  346. display: block;
  347. width: 100%;
  348. height: 20px;
  349. margin: 5px 0;
  350. line-height: 20px;
  351. border: 1px solid transparent;
  352. outline: none;
  353. font-size: 14px;
  354. color: #53586b;
  355. white-space: nowrap;
  356. text-overflow: ellipsis;
  357. overflow: hidden;
  358. }
  359. .material-list .list-box .list-item .del-btn {
  360. z-index: 10;
  361. position: absolute;
  362. top: 5px;
  363. right: 5px;
  364. display: none;
  365. width: 14px;
  366. height: 14px;
  367. color: #fff;
  368. font-size: 12px;
  369. text-align: center;
  370. line-height: 13px;
  371. background: rgba(0, 0, 0, .4);
  372. border-radius: 18px;
  373. cursor: pointer;
  374. }
  375. .material-list .list-box .list-item:hover .del-btn {
  376. display: block;
  377. }
  378. .material-list .list-box .list-item.active .checked-item {
  379. position: absolute;
  380. top: 0;
  381. left: 0;
  382. display: block;
  383. height: 40px;
  384. width: 40px;
  385. background: url(../assets/images/check_gou.png) no-repeat;
  386. }
  387. .material-list .list-box .list-item.active .bg-img,
  388. .material-list .list-box .list-item.active video {
  389. border: 2px solid #409eff;
  390. }
  391. .material-list .list-box .video-item .video-info {
  392. width: 100%;
  393. font-size: 12px;
  394. color: #999;
  395. }
  396. .material-list .list-box .video-item .video-info-left {
  397. float: left;
  398. width: 50%;
  399. text-align: left;
  400. }
  401. .material-list .list-box .video-item .video-info-right {
  402. float: left;
  403. width: 50%;
  404. text-align: right;
  405. }
  406. .material-list .list-box .video-item .video-duration {
  407. position: absolute;
  408. bottom: 8px;
  409. right: 8px;
  410. padding: 5px 9px;
  411. font-size: 12px;
  412. text-align: center;
  413. color: #fff;
  414. background: #000;
  415. border-radius: 2px;
  416. opacity: .7;
  417. }
  418. .material-list .list-footer {
  419. margin-top: 8px;
  420. }
  421. .material-list .list-footer .list-ctrl {
  422. float: left;
  423. width: 230px;
  424. height: 32px;
  425. }
  426. .material-list .list-footer .list-ctrl .el-button {
  427. padding: 9px 24px;
  428. }
  429. .material-list .list-footer .list-ctrl .ctrl-del {
  430. margin: 0 6px;
  431. }
  432. .material-list .list-footer .list-page {
  433. float: right;
  434. width: 542px;
  435. text-align: right;
  436. }
  437. </style>