medialist.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <template>
  2. <view class="bg-white" style="width: 100%;height: 100vh;overflow: hidden;">
  3. <!-- 顶部 -->
  4. <cu-custom bgColor="bg-blue" :isBack="true">
  5. <block slot="backText">
  6. <text style="width: 360rpx;">{{titleName?titleName:'影像资料'}}</text>
  7. </block>
  8. <block slot="content"></block>
  9. <block slot="right">
  10. <view class="flex justify-center">
  11. <button class="margin-top-ssm cu-btn round line-blue text-white" v-if="manage" @tap="manage = false">
  12. <text>取消管理</text>
  13. </button>
  14. <template v-else>
  15. <button class="margin-top-ssm cu-btn round line-blue text-white" v-if="type==0" @tap="toSaveFile">
  16. <text class="cuIcon-camera btnicon-size"></text>
  17. <text>拍照</text><text v-if="nodeId">到当前节点</text>
  18. </button>
  19. <button class="margin-top-ssm cu-btn round line-blue text-white" v-if="type==1" @tap="toSaveFile">
  20. <text class="cuIcon-record btnicon-size"></text>
  21. <text>录像</text><text v-if="nodeId">到当前节点</text>
  22. </button>
  23. </template>
  24. </view>
  25. </block>
  26. </cu-custom>
  27. <view class="bg-white nav" v-if="nodeId">
  28. <view class="flex text-center">
  29. <view class="cu-item flex-sub" :class="index==TabCur?'text-blue cur':''" v-for="(item,index) in menuList" :key="index" @tap="tabSelect" :data-id="index">
  30. {{item.name}}({{item.num}})
  31. </view>
  32. </view>
  33. </view>
  34. <scroll-view :scroll-y="!previewShow" style="width: 100%;height: 100%;" lower-threshold="200" @scrolltolower="paging">
  35. <view v-for="(item,index) in showList" :key="item.name" @longtap="manage = true" v-if="showList.length">
  36. <view class="padding-sm text-bold color-black solid-bottom">
  37. {{item.name}}
  38. </view>
  39. <view v-for="(item2,index2) in item.list" :key="item2.id" class="flex solid-bottom padding-sm">
  40. <image class="image-type margin-right-sm" mode="aspectFit" :src="type==0?item2.fileUrl:item2.snapshot" @tap="previewImage(item2,index,index2)"></image>
  41. <view class="flex-sub flex align-center">
  42. <view class="flex-sub">
  43. <view class="text-bold text-xl color-black">{{item2.fileName}}</view>
  44. <view class="text-df">{{item2.description}}</view>
  45. </view>
  46. <checkbox-group @change="CheckboxChange" :data-index="index" :data-index2="index2">
  47. <checkbox class="sc75 blue" v-show="manage" :class="item2.checked?'checked':''" :checked="item2.checked?true:false"></checkbox>
  48. </checkbox-group>
  49. </view>
  50. </view>
  51. </view>
  52. <view v-else style="width: 100%;text-align: center;padding-top: 50rpx;">数据加载中</view>
  53. <view style="height: 360rpx;" v-if="nodeId"></view>
  54. <view style="height: 240rpx;" v-else></view>
  55. </scroll-view>
  56. <view class="botm padding bg-white flex justify-between" v-if="manage">
  57. <view>
  58. <checkbox-group @change="allChange">
  59. <checkbox class="sc75 blue" :class="isAll?'checked':''" :checked="isAll?true:false" value="all"></checkbox>
  60. <text class="padding-left-sm">全选</text>
  61. </checkbox-group>
  62. </view>
  63. <view>
  64. <button class="cu-btn round margin-right-sm" @tap="delMedias">删除选中</button>
  65. <button class="cu-btn round bg-blue" @tap="toEdit">编辑选中</button>
  66. </view>
  67. </view>
  68. <view class="preview-bg" v-if="previewShow">
  69. <view class="preview-close" :style="[{top:(CustomBar-40) + 'px'}]" @tap="hidePreview">
  70. <text class="lg text-white cuIcon-close text-bold"></text>
  71. </view>
  72. <view class="flex flex-direction" style="height: 100%;">
  73. <image mode="aspectFit" :src="previewObj.fileUrl" class="preview-content flex-sub" v-if="type == 0"></image>
  74. <video v-if="type == 1" :src="previewObj.fileUrl" class="preview-content flex-sub" :style="[{'margin-top':CustomBar + 'px'}]"></video>
  75. <scroll-view scroll-y class="preview-desc">
  76. <view class="">{{previewObj.fileName}}</view>
  77. <view class="preview-text">{{previewObj.description}}</view>
  78. <view class="">{{previewObj.filmingTime}} {{previewObj.shooter}}</view>
  79. </scroll-view>
  80. <view class="margin-top-sm text-right" style="height: 80rpx;">
  81. <button class="cu-btn round line-white margin-right-sm" @tap="toEdit([previewObj])">编辑</button>
  82. <button class="cu-btn round line-white margin-right-sm" @tap="delOne">删除</button>
  83. </view>
  84. </view>
  85. <!-- <view class="preview-desc2">
  86. <view class="">{{previewObj.fileName}}</view>
  87. <view class="preview-text">{{previewObj.description}}</view>
  88. <view class="">{{previewObj.filmingTime}} {{previewObj.shooter}}</view>
  89. </view> -->
  90. </view>
  91. </view>
  92. </template>
  93. <script>
  94. export default {
  95. data() {
  96. return {
  97. type:0,//1:video,0:picture
  98. tagId:'',
  99. nodeId:'',
  100. nodeName:'',
  101. titleName:'',
  102. pageSize:20,
  103. TabCur: 0,
  104. manage:false,
  105. isAll:false,
  106. menuList: [{
  107. name: '全部节点文件',
  108. num:0,
  109. }, {
  110. name: '当前节点文件',
  111. num:0,
  112. }],
  113. list:[],
  114. listNum:0,
  115. page:1,
  116. nowList:[],
  117. nowNum:0,
  118. nowPage:1,
  119. sonList:[],
  120. sonNum:0,
  121. sonPage:1,
  122. previewShow:false,
  123. previewObj:null,
  124. userInfo:null,
  125. project:null,
  126. }
  127. },
  128. computed:{
  129. showList(){
  130. if(!this.nodeId){
  131. return this.list;
  132. }else{
  133. if(this.TabCur == 0){
  134. return this.sonList;
  135. }else{
  136. return this.nowList;
  137. }
  138. }
  139. }
  140. },
  141. onLoad(e) {
  142. this.type=e.type;
  143. this.tagId=e.tagId;
  144. this.nodeId=e.nodeId;
  145. this.nodeName=e.nodeName;
  146. this.titleName=e.titleName;
  147. var userInfo = uni.getStorageSync("userInfo")
  148. if(userInfo){
  149. this.userInfo = userInfo;
  150. this.project = uni.getStorageSync("porject"+"_"+userInfo.id);
  151. }
  152. //监听选择工序
  153. uni.$on('uploadComplete',this.initData)
  154. },
  155. onShow() {
  156. this.initData();
  157. },
  158. onUnload(){
  159. uni.$off('uploadComplete',this.initData)
  160. },
  161. methods: {
  162. //划到底了
  163. paging(){
  164. //console.log('paging')
  165. let load = false;
  166. let listNUm = 0;
  167. if(this.nodeId){
  168. if(this.TabCur == 0){
  169. this.sonList.forEach((list)=>{
  170. list.list.forEach(()=>{
  171. listNUm++;
  172. })
  173. })
  174. if(listNUm < this.sonNum){
  175. load = true;
  176. this.sonPage++;
  177. }
  178. }else if(this.TabCur == 1){
  179. this.nowList.forEach((list)=>{
  180. list.list.forEach(()=>{
  181. listNUm++;
  182. })
  183. })
  184. if(listNUm < this.nowNum){
  185. load = true;
  186. this.nowPage++;
  187. }
  188. }
  189. }else{
  190. this.list.forEach((list)=>{
  191. list.list.forEach(()=>{
  192. listNUm++;
  193. })
  194. })
  195. if(listNUm < this.listNum){
  196. load = true;
  197. this.page++;
  198. }
  199. }
  200. if(load){
  201. this.loadTable();
  202. }
  203. },
  204. loadTable(isDel){
  205. if(this.nodeId){
  206. if(this.TabCur == 0){
  207. this.loadTable3(isDel);
  208. }else if(this.TabCur == 1){
  209. this.loadTable2(isDel);
  210. }
  211. }else{
  212. this.loadTable1(isDel);
  213. }
  214. },
  215. loadTable1(isDel){
  216. this.http.request('/app/multimedia/medialist', {
  217. tagId:this.tagId,
  218. nodeIdMedia:'',
  219. searchKey:'',
  220. orderKey:0,//0倒序,1顺序
  221. date:'',
  222. page:this.page,
  223. pageSize:this.pageSize,
  224. }).then((result)=>{
  225. if(result.result == 1){
  226. this.listNum = result.totalNum;
  227. for (let i = 0; i < result.datas.length; i++) {
  228. let dateIsIn = false;
  229. let jIndex = 0;
  230. for (let j = 0; j < this.list.length; j++) {
  231. if(result.datas[i].filmingTime == this.list[j].name){
  232. dateIsIn = true;
  233. jIndex = j;
  234. break;
  235. }
  236. }
  237. if(dateIsIn){
  238. //console.log(dateIsIn)
  239. this.list[jIndex].list.push(result.datas[i]);
  240. }else{
  241. this.list.push({
  242. name:result.datas[i].filmingTime,
  243. list:[result.datas[i]]
  244. })
  245. }
  246. }
  247. }else{
  248. if(isDel){
  249. this.listNum = 0;
  250. this.list = [];
  251. this.page = 1;
  252. }
  253. }
  254. })
  255. },
  256. loadTable2(isDel){
  257. this.http.request('/app/multimedia/medialist', {
  258. tagId:this.tagId,
  259. nodeIdMedia:'',
  260. searchKey:'',
  261. orderKey:0,//0倒序,1顺序
  262. date:'',
  263. page:this.nowPage,
  264. pageSize:this.pageSize,
  265. nodeId:this.nodeId,
  266. mode:0,
  267. }).then((result)=>{
  268. if(result.result == 1){
  269. this.nowNum = result.totalNum;
  270. this.menuList[1].num = this.nowNum;
  271. for (let i = 0; i < result.datas.length; i++) {
  272. let dateIsIn = false;
  273. let jIndex = 0;
  274. for (let j = 0; j < this.nowList.length; j++) {
  275. if(result.datas[i].filmingTime == this.nowList[j].name){
  276. dateIsIn = true;
  277. jIndex = j;
  278. break;
  279. }
  280. }
  281. if(dateIsIn){
  282. //console.log(dateIsIn)
  283. this.nowList[jIndex].list.push(result.datas[i]);
  284. }else{
  285. this.nowList.push({
  286. name:result.datas[i].filmingTime,
  287. list:[result.datas[i]]
  288. })
  289. }
  290. }
  291. }else{
  292. if(isDel){
  293. this.nowNum = 0;
  294. this.menuList[1].num = 0;
  295. this.nowList = [];
  296. this.nowPage = 1;
  297. this.TabCur = 0;
  298. }
  299. }
  300. })
  301. },
  302. loadTable3(isDel){
  303. this.http.request('/app/multimedia/medialist', {
  304. tagId:this.tagId,
  305. nodeIdMedia:'',
  306. searchKey:'',
  307. orderKey:0,//0倒序,1顺序
  308. date:'',
  309. page:this.sonPage,
  310. pageSize:this.pageSize,
  311. nodeId:this.nodeId,
  312. mode:1,
  313. }).then((result)=>{
  314. if(result.result == 1){
  315. this.sonNum = result.totalNum;
  316. this.menuList[0].num = this.sonNum;
  317. for (let i = 0; i < result.datas.length; i++) {
  318. let dateIsIn = false;
  319. let jIndex = 0;
  320. for (let j = 0; j < this.sonList.length; j++) {
  321. if(result.datas[i].filmingTime == this.sonList[j].name){
  322. dateIsIn = true;
  323. jIndex = j;
  324. break;
  325. }
  326. }
  327. if(dateIsIn){
  328. //console.log(dateIsIn)
  329. this.sonList[jIndex].list.push(result.datas[i]);
  330. }else{
  331. this.sonList.push({
  332. name:result.datas[i].filmingTime,
  333. list:[result.datas[i]]
  334. })
  335. }
  336. }
  337. }else{
  338. if(isDel){
  339. this.sonNum = 0;
  340. this.menuList[0].num = 0;
  341. this.sonList = [];
  342. this.sonPage = 1;
  343. }
  344. }
  345. })
  346. },
  347. //删除
  348. delMedias(){
  349. let ids = [];
  350. this.showList.forEach((list)=>{
  351. list.list.forEach((item)=>{
  352. if(item.checked){
  353. ids.push(item.id);
  354. }
  355. })
  356. })
  357. if(ids.length < 1){
  358. this.$prompt.none('请至少选中一个文件');
  359. return;
  360. }
  361. uni.showModal({
  362. title: '删除',
  363. content: '是否删除文件?',
  364. success:(res) => {
  365. if (res.confirm) {
  366. //console.log('用户点击确定');
  367. this.http.request('/app/multimedia/delMedia', {
  368. arr:ids.join(','),
  369. tagId:this.tagId,
  370. }).then((result)=>{
  371. if(result.result == 1){
  372. if(this.nodeId){
  373. if(this.TabCur == 0){
  374. this.sonList = [];
  375. this.sonPage = 1;
  376. }else if(this.TabCur == 1){
  377. this.nowList = [];
  378. this.nowPage = 1;
  379. }
  380. }else{
  381. this.list = [];
  382. this.page = 1;
  383. }
  384. this.loadTable(true);
  385. }
  386. })
  387. }
  388. }
  389. });
  390. },
  391. delOne(){
  392. this.previewShow = false;
  393. uni.showModal({
  394. title: '删除',
  395. content: '是否删除文件?',
  396. success:(res) => {
  397. if (res.confirm) {
  398. //console.log('用户点击确定');
  399. this.http.request('/app/multimedia/delMedia', {
  400. arr:[this.previewObj.id],
  401. tagId:this.tagId,
  402. }).then((result)=>{
  403. if(result.result == 1){
  404. let lsit = [];
  405. if(this.nodeId){
  406. if(this.TabCur == 0){
  407. lsit = this.sonList;
  408. }else if(this.TabCur == 1){
  409. lsit = this.nowList;
  410. }
  411. }else{
  412. lsit = this.list;
  413. }
  414. //debugger
  415. lsit[this.previewObj.index].list.splice(this.previewObj.index2,1);
  416. if(lsit[this.previewObj.index].list.length < 1){
  417. lsit.splice(this.previewObj.index,1);
  418. }
  419. }
  420. })
  421. }
  422. }
  423. });
  424. },
  425. toEdit(arr){
  426. let selects = [];
  427. if(arr instanceof Array){
  428. selects = arr;
  429. }else{
  430. this.showList.forEach((list)=>{
  431. list.list.forEach((item)=>{
  432. if(item.checked){
  433. selects.push(item);
  434. }
  435. })
  436. })
  437. if(selects.length < 1){
  438. this.$prompt.none('请至少选中一个文件');
  439. return;
  440. }
  441. }
  442. uni.setStorageSync('medialist', selects);
  443. let url = "/pages/multimedia/saveFile?type=" + this.type +"&tagId=" + this.tagId +"&handle=" + 'edit';
  444. if(this.nodeId){
  445. url += "&nodeId="+this.nodeId + "&nodeName=" + encodeURIComponent(this.nodeName);
  446. }
  447. uni.navigateTo({
  448. url: url
  449. })
  450. this.previewShow = false;
  451. },
  452. toSaveFile(){
  453. let url = "/pages/multimedia/saveFile?type=" + this.type +"&tagId=" + this.tagId +"&handle=" + 'add';
  454. if(this.nodeId){
  455. url += "&nodeId="+this.nodeId + "&nodeName=" + encodeURIComponent(this.nodeName);
  456. }
  457. uni.navigateTo({
  458. url: url
  459. })
  460. },
  461. // previewImage(url){
  462. // uni.previewImage({
  463. // current: 0, // 当前显示图片的链接/索引值
  464. // urls: [url], // 需要预览的图片链接列表,要求必须是数组
  465. // })
  466. // },
  467. previewImage(item,index,index2){
  468. this.previewShow = true;
  469. item.index = index;
  470. item.index2 = index2;
  471. this.previewObj = item;
  472. },
  473. hidePreview(){
  474. //console.log('hide')
  475. this.previewShow = false;
  476. },
  477. tabSelect(e) {
  478. this.TabCur = e.currentTarget.dataset.id;
  479. },
  480. allChange(e){
  481. let values = e.detail.value;
  482. if(values.length>0){
  483. this.isAll = true;
  484. }else{
  485. this.isAll = false;
  486. }
  487. this.showList.forEach((list)=>{
  488. list.list.forEach((item)=>{
  489. this.$set(item,'checked',this.isAll);
  490. })
  491. })
  492. },
  493. CheckboxChange(e){
  494. let values = e.detail.value;
  495. let item = this.showList[e.currentTarget.dataset.index].list[e.currentTarget.dataset.index2];
  496. // console.log(e)
  497. // console.log(item)
  498. if(values.length>0){
  499. this.$set(item,'checked',true);
  500. }else{
  501. this.$set(item,'checked',false);
  502. }
  503. },
  504. initPage(){
  505. this.list = [];
  506. this.page = 1;
  507. this.sonList = [];
  508. this.sonPage = 1;
  509. this.nowList = [];
  510. this.nowPage = 1;
  511. },
  512. initData(){
  513. this.initPage();
  514. if(this.nodeId){
  515. this.loadTable2();
  516. this.loadTable3();
  517. }else{
  518. this.loadTable1();
  519. }
  520. },
  521. },
  522. }
  523. </script>
  524. <style>
  525. .title-font{
  526. font-size: 30rpx;
  527. padding: 20rpx;
  528. }
  529. .color-black{
  530. color: #333333;
  531. }
  532. .icon-size{
  533. font-size: 60rpx;
  534. margin-right: 16rpx;
  535. }
  536. .btnicon-size{
  537. font-size: 36rpx;
  538. margin-right: 8rpx;
  539. }
  540. .image-type{
  541. background-color: #EEEEEE;
  542. width: 150rpx;
  543. height: 150rpx;
  544. }
  545. .botm{
  546. position: fixed;
  547. left: 0;
  548. bottom: 0;
  549. width: 100%;
  550. box-shadow: 2px 2px 10px rgb(26 26 26 / 50%);
  551. }
  552. .sc75{
  553. transform: scale(0.75, 0.75);
  554. }
  555. .preview-bg{
  556. background-color: #262626;
  557. width: 100%;
  558. height: 100%;
  559. position: fixed;
  560. left: 0;
  561. top: 0;
  562. z-index: 9999;
  563. }
  564. .preview-close{
  565. position: absolute;
  566. top: 0;
  567. right: 30rpx;
  568. font-size: 50rpx;
  569. z-index: 99;
  570. }
  571. .preview-content{
  572. margin: auto;
  573. width: 100%;
  574. height: 100%;
  575. }
  576. .preview-desc2{
  577. position: absolute;
  578. left: 0;
  579. bottom: 80rpx;
  580. z-index: 98;
  581. padding: 0 20rpx;
  582. color: #FFFFFF;
  583. pointer-events: none;
  584. text-shadow: 1px 1px 2px #000000;
  585. }
  586. .preview-desc{
  587. padding: 0 20rpx;
  588. color: #FFFFFF;
  589. height: 120rpx;
  590. }
  591. .preview-text{
  592. font-size: 22rpx;
  593. padding: 20rpx 0;
  594. }
  595. </style>