material.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <view class="material">
  3. <navbar :config="config"></navbar>
  4. <div class="zhan" :style="{ top:top + 'px' }"></div>
  5. <view class="background">
  6. <view class="content">
  7. <view v-if="itemList.length>=0">
  8. <view class="item" style="position: relative;" v-for="(item,index) in itemList" :key="item.id">
  9. <!-- <view class="image">
  10. <image src="../../../static/lidalogo.png" mode=""></image>
  11. </view> -->
  12. <view class="gratitude">
  13. <view class="top-box">
  14. <view class="title">
  15. {{item.title}}
  16. </view>
  17. <view class="iconfont " @click="downloadImg(item)">
  18. &#xe64b;
  19. </view>
  20. </view>
  21. <view class="detailed">
  22. {{item.detail}}
  23. </view>
  24. <view class="copy-file" @click="copy(item.detail)">
  25. 复制文案
  26. </view>
  27. <view class="file-image">
  28. <image v-if="item.type==0" :src="item.filePath" mode=""></image>
  29. <!-- <j-video v-if="item.type==1" class="jvideo" :url="item.filePath" width="374rpx">
  30. </j-video> -->
  31. <video v-if="item.type==1" class="jvideo" style="width: 374rpx;height: 450rpx;" :src="item.filePath" @fullscreenchange="fullscreenchange"></video>
  32. <view class="relative" v-if="item.type==2">
  33. <!-- <audio @error="audioErr" style="position: relative;" :src="item.filePath"
  34. duration="item.duration" :controls="true">
  35. </audio>
  36. <text class="absolute" v-if="item.type==2">{{item.duration|secondsFormat}}</text> -->
  37. <!-- <div @click="audioPlay(item,index)">播放</div> -->
  38. <image v-show="!item.play" @click="audioPlay(item,index)" :src="imgUrl+'/play.png'" mode=""></image>
  39. <image v-show="item.play" @click="audioPlay(item,index)" :src="imgUrl+'/pause.png'" mode=""></image>
  40. </view>
  41. <!-- <audio v-if="item.type==2" :src="item.filePath" :poster="" :name="" :author="" :action="" controls></audio> -->
  42. </view>
  43. </view>
  44. <!-- <uni-popup ref="popup" type="bottom">
  45. <view class="forward">
  46. <view class="top">
  47. <view class="text">
  48. 分享至
  49. </view>
  50. <view class="line">
  51. </view>
  52. </view>
  53. <view class="list">
  54. <view class="wx">
  55. <image src="" mode=""></image>
  56. </view>
  57. <view class="friend">
  58. </view>
  59. <view class="micro">
  60. </view>
  61. <view class="copylink">
  62. </view>
  63. </view>
  64. </view>
  65. </uni-popup> -->
  66. </view>
  67. <loadMore v-if="itemList.length>0" :status="status"></loadMore>
  68. <nodata v-else :config="{top:20,content:'暂无素材~'}"></nodata>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. let app = getApp()
  76. import jVideo from "../../../components/j-video/j-video.vue"
  77. import {
  78. material
  79. } from "../../../api/notice.js"
  80. export default {
  81. components: {
  82. jVideo
  83. },
  84. data() {
  85. return {
  86. config: {
  87. back: true, //false是tolbar页面 是则不写
  88. title: '宣传素材',
  89. color: '#fff',
  90. switchnextstep: true, //切换底部样式
  91. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  92. backgroundColor: [1, "#0B844A"],
  93. // fixed:false,
  94. statusBarFontColor: '#ffffff'
  95. },
  96. value: "只有我在意这个“研究”究竟是什么含义嘛只有我 在意这个“研究”究竟是什么含义嘛只有我在意这 个“研究”究竟是什么含义嘛",
  97. itemList: [],
  98. params: {
  99. page: 1,
  100. limit: 10
  101. },
  102. status: "more",
  103. audioCtx: null, // 音频上下文
  104. contextArr:[],
  105. duration: 0, // 音频总时长
  106. currentTime: 0, // 音频当前播放的时长
  107. top: 0,
  108. imgUrl: this.$mConfig.staticUrl
  109. }
  110. },
  111. onLoad() {
  112. this.audioCtx = uni.createInnerAudioContext()
  113. this.audioCtx.obeyMuteSwitch = false
  114. this.getList()
  115. this.top = app.globalData.barHeight + 44
  116. },
  117. //下拉刷新
  118. onPullDownRefresh() {
  119. this.params.page = 1
  120. this.itemList = []
  121. this.getList()
  122. },
  123. //上拉加载
  124. onReachBottom() {
  125. if (this.status == "more") {
  126. this.params.page++
  127. this.getList()
  128. }
  129. },
  130. filters:{
  131. secondsFormat(s) {
  132. var day = Math.floor(s / (24 * 3600)); // Math.floor()向下取整
  133. var hour = Math.floor((s - day * 24 * 3600) / 3600);
  134. var minute = Math.floor((s - day * 24 * 3600 - hour * 3600) / 60);
  135. var second = s - day * 24 * 3600 - hour * 3600 - minute * 60;
  136. if (hour) {
  137. return hour + ":" + minute + ":" + second;
  138. } else {
  139. if (second < 10) {
  140. if (minute < 10) {
  141. return "0" + minute + ":" + second + "0";
  142. } else {
  143. return minute + ":" + second + "0";
  144. }
  145. } else {
  146. return minute + ":" + second.toFixed(0);
  147. }
  148. }
  149. }
  150. },
  151. methods: {
  152. audioErr(e) {
  153. console.log(e)
  154. console.log('音频错误')
  155. },
  156. audioPlay(v,k) {
  157. this.contextArr.forEach((item,key) => {
  158. if(v.id == item.id) {
  159. if(!v.play) {
  160. item.audioCtx.play()
  161. this.itemList[k].play = true
  162. }else {
  163. item.audioCtx.pause()
  164. this.itemList[k].play = false
  165. }
  166. }
  167. })
  168. // if(!v.play) {
  169. // this.audioCtx.play()
  170. // this.itemList[k].play = true
  171. // }else {
  172. // this.audioCtx.pause()
  173. // this.itemList[k].play = false
  174. // }
  175. console.log(v.filePath)
  176. },
  177. fullscreenchange(e){
  178. },
  179. copy(code) {
  180. uni.setClipboardData({
  181. data: code,
  182. success: () => {
  183. uni.showToast({
  184. title: "复制成功",
  185. });
  186. },
  187. });
  188. },
  189. //下载图片
  190. downloadImg(item) {
  191. // console.log(item.filePath)
  192. uni.showModal({
  193. title: "是否下载素材",
  194. success: function(res) {
  195. if (res.confirm) {
  196. uni.showLoading({
  197. title: '加载中'
  198. });
  199. uni.downloadFile({
  200. url: item.filePath,
  201. success: (res) => {
  202. if (res.statusCode === 200) {
  203. if(item.type == 0) {
  204. uni.saveImageToPhotosAlbum({
  205. filePath: res.tempFilePath,
  206. success: function() {
  207. uni.hideLoading();
  208. uni.showToast({
  209. title: "保存成功",
  210. icon: "none"
  211. });
  212. console.log(res.tempFilePath)
  213. },
  214. fail: function(err) {
  215. uni.hideLoading();
  216. uni.showToast({
  217. title: "保存失败,请稍后重试",
  218. icon: "none"
  219. });
  220. console.log(err)
  221. }
  222. });
  223. }else if(item.type == 1) {
  224. uni.saveVideoToPhotosAlbum({
  225. filePath: res.tempFilePath,
  226. success: function() {
  227. uni.hideLoading();
  228. uni.showToast({
  229. title: "保存成功",
  230. icon: "none"
  231. });
  232. console.log(res.tempFilePath)
  233. },
  234. fail: function(err) {
  235. uni.hideLoading();
  236. uni.showToast({
  237. title: "保存失败,请稍后重试",
  238. icon: "none"
  239. });
  240. console.log(err)
  241. }
  242. });
  243. }else {
  244. uni.saveFile({
  245. tempFilePath: res.tempFilePath,
  246. success() {
  247. uni.hideLoading();
  248. uni.showToast({
  249. title: "保存成功",
  250. icon: "none"
  251. });
  252. },
  253. fail() {
  254. uni.hideLoading();
  255. uni.showToast({
  256. title: "保存失败,请稍后重试",
  257. icon: "none"
  258. });
  259. }
  260. })
  261. }
  262. }
  263. }
  264. })
  265. // downloadTask.onProgressUpdate((res)=>{
  266. // console.log("下载进度"+res.progress)
  267. // uni.showLoading({
  268. // title: '加载中'
  269. // });
  270. // })
  271. } else if (res.cancel) {
  272. console.log(777)
  273. }
  274. }
  275. })
  276. },
  277. //获取数据
  278. getList() {
  279. let _that = this;
  280. this.$http.get(material, this.params).then(res => {
  281. if (res && res.code == 200) {
  282. uni.stopPullDownRefresh()
  283. this.itemList = this.itemList.concat(res.page.list)
  284. if (res.page.totalPage <= res.page.currPage) {
  285. this.status = "noMore";
  286. } else {
  287. this.status = 'more'
  288. }
  289. let context = []
  290. _that.itemList.forEach(item => {
  291. if (item.type == 2) {
  292. context.push({
  293. id: item.id,
  294. audioCtx: uni.createInnerAudioContext(),
  295. src: item.filePath
  296. })
  297. context.forEach(vv => {
  298. vv.audioCtx.src = vv.src
  299. })
  300. _that.audioCtx.src = item.filePath;
  301. _that.audioCtx.startTime = 0
  302. // _that.audioCtx.autoplay = true;
  303. _that.audioCtx.onCanplay(() => {
  304. this.$set(item,"duration", _that.audioCtx.duration)
  305. console.log('开始播放' + item.duration);
  306. //alert(_that.audioCtx.duration + "---" + audioObj.filePath)
  307. });
  308. this.$set(item,"play", false)
  309. _that.contextArr = context
  310. }
  311. })
  312. console.log(this.contextArr)
  313. console.log('contextArr数组')
  314. }
  315. })
  316. },
  317. showlink() {
  318. this.$refs.popup[0].open()
  319. // this.$refs.popup.open()
  320. console.log(666)
  321. },
  322. doCopy() {
  323. },
  324. },
  325. onUnload() {
  326. this.audioCtx.destroy();
  327. this.audioCtx = null;
  328. }
  329. }
  330. </script>
  331. <style lang="scss" scoped>
  332. .jvideo {
  333. border-radius: 18rpx;
  334. }
  335. .zhan {
  336. background: #0B844A;
  337. height: 20px;
  338. width: 100%;
  339. position: fixed;
  340. }
  341. .background {
  342. // background: #0B844A;
  343. position: relative;
  344. z-index: 10;
  345. .content {
  346. overflow: hidden;
  347. background-color: #ffffff;
  348. border-radius: 40rpx 40rpx 0 0;
  349. .item {
  350. display: flex;
  351. padding: 40rpx 30rpx 40rpx 30rpx;
  352. margin-bottom: 41rpx;
  353. border-bottom: 10rpx solid #f5f5f5;
  354. overflow: hidden;
  355. .forward {
  356. // 弹出框
  357. height: 565rpx;
  358. background-color: #ffffff;
  359. border-radius: 50rpx 50rpx 0 0;
  360. .top {
  361. padding: 37rpx 0 12rpx 0;
  362. text-align: center;
  363. .text {
  364. font-size: 36rpx;
  365. font-weight: 700;
  366. color: #1A1A1A;
  367. margin-bottom: 12rpx;
  368. }
  369. .line {
  370. margin: 0 auto;
  371. width: 64rpx;
  372. height: 8rpx;
  373. background-color: #cccccc;
  374. }
  375. }
  376. }
  377. .image {
  378. image {
  379. width: 76rpx;
  380. height: 76rpx;
  381. }
  382. }
  383. .gratitude {
  384. // flex-grow: 1;
  385. width: 100%;
  386. .top-box {
  387. display: flex;
  388. width: 100%;
  389. }
  390. .title {
  391. width: 600rpx;
  392. flex-grow: 1;
  393. font-size: 28rpx;
  394. color: #1a1a1a;
  395. font-weight: 400;
  396. line-height: 40rpx;
  397. margin-bottom: 18rpx;
  398. flex-basis: 0;
  399. text-overflow: ellipsis;
  400. white-space: nowrap;
  401. overflow: hidden;
  402. }
  403. .iconfont {
  404. margin-left: 30rpx;
  405. font-size: 30rpx;
  406. color: #0B844A;
  407. // width: 50rpx;
  408. }
  409. .detailed {
  410. font-size: 28rpx;
  411. color: #999999;
  412. font-weight: 500;
  413. }
  414. .copy-file {
  415. margin-top: 18rpx;
  416. color: rgba(254, 144, 0, 1);
  417. text-decoration: underline;
  418. }
  419. .file-image {
  420. margin-top: 18rpx;
  421. image {
  422. width: 374rpx;
  423. height: 574rpx;
  424. border-radius: 18rpx;
  425. }
  426. .relative{
  427. position: relative;
  428. width: 100rpx;
  429. height: 100rpx;
  430. border: 1px solid #cccccc;
  431. display: flex;
  432. align-items: center;
  433. justify-content: center;
  434. .absolute{
  435. position: absolute;
  436. right: 30rpx;
  437. bottom: 30rpx;
  438. color: #888;
  439. font-size: 24rpx;
  440. }
  441. image {
  442. width: 50rpx;
  443. height: 50rpx;
  444. }
  445. }
  446. }
  447. }
  448. .link {
  449. position: absolute;
  450. right: 30rpx;
  451. top: 57rpx;
  452. // line-height: 76rpx;
  453. image {
  454. width: 43rpx;
  455. height: 41rpx;
  456. }
  457. }
  458. }
  459. }
  460. }
  461. </style>