123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517 |
- <template>
- <view class="material">
- <navbar :config="config"></navbar>
- <div class="zhan" :style="{ top:top + 'px' }"></div>
- <view class="background">
- <view class="content">
- <view v-if="itemList.length>=0">
- <view class="item" style="position: relative;" v-for="(item,index) in itemList" :key="item.id">
- <!-- <view class="image">
- <image src="../../../static/lidalogo.png" mode=""></image>
- </view> -->
- <view class="gratitude">
- <view class="top-box">
- <view class="title">
- {{item.title}}
- </view>
- <view class="iconfont " @click="downloadImg(item)">
- 
- </view>
- </view>
- <view class="detailed">
- {{item.detail}}
- </view>
- <view class="copy-file" @click="copy(item.detail)">
- 复制文案
- </view>
- <view class="file-image">
- <image v-if="item.type==0" :src="item.filePath" mode=""></image>
- <!-- <j-video v-if="item.type==1" class="jvideo" :url="item.filePath" width="374rpx">
- </j-video> -->
- <video v-if="item.type==1" class="jvideo" style="width: 374rpx;height: 450rpx;" :src="item.filePath" @fullscreenchange="fullscreenchange"></video>
- <view class="relative" v-if="item.type==2">
- <!-- <audio @error="audioErr" style="position: relative;" :src="item.filePath"
- duration="item.duration" :controls="true">
- </audio>
- <text class="absolute" v-if="item.type==2">{{item.duration|secondsFormat}}</text> -->
- <!-- <div @click="audioPlay(item,index)">播放</div> -->
- <image v-show="!item.play" @click="audioPlay(item,index)" :src="imgUrl+'/play.png'" mode=""></image>
- <image v-show="item.play" @click="audioPlay(item,index)" :src="imgUrl+'/pause.png'" mode=""></image>
-
- </view>
-
-
-
- <!-- <audio v-if="item.type==2" :src="item.filePath" :poster="" :name="" :author="" :action="" controls></audio> -->
- </view>
- </view>
- <!-- <uni-popup ref="popup" type="bottom">
- <view class="forward">
- <view class="top">
- <view class="text">
- 分享至
- </view>
- <view class="line">
- </view>
- </view>
- <view class="list">
- <view class="wx">
- <image src="" mode=""></image>
- </view>
- <view class="friend">
- </view>
- <view class="micro">
- </view>
- <view class="copylink">
- </view>
- </view>
- </view>
- </uni-popup> -->
- </view>
- <loadMore v-if="itemList.length>0" :status="status"></loadMore>
- <nodata v-else :config="{top:20,content:'暂无素材~'}"></nodata>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- let app = getApp()
- import jVideo from "../../../components/j-video/j-video.vue"
- import {
- material
- } from "../../../api/notice.js"
- export default {
- components: {
- jVideo
- },
- data() {
- return {
- config: {
- back: true, //false是tolbar页面 是则不写
- title: '宣传素材',
- color: '#fff',
- switchnextstep: true, //切换底部样式
- //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
- backgroundColor: [1, "#0B844A"],
- // fixed:false,
- statusBarFontColor: '#ffffff'
- },
- value: "只有我在意这个“研究”究竟是什么含义嘛只有我 在意这个“研究”究竟是什么含义嘛只有我在意这 个“研究”究竟是什么含义嘛",
- itemList: [],
- params: {
- page: 1,
- limit: 10
- },
- status: "more",
- audioCtx: null, // 音频上下文
- contextArr:[],
- duration: 0, // 音频总时长
- currentTime: 0, // 音频当前播放的时长
- top: 0,
- imgUrl: this.$mConfig.staticUrl
- }
- },
- onLoad() {
- this.audioCtx = uni.createInnerAudioContext()
- this.audioCtx.obeyMuteSwitch = false
- this.getList()
- this.top = app.globalData.barHeight + 44
-
- },
- //下拉刷新
- onPullDownRefresh() {
- this.params.page = 1
- this.itemList = []
- this.getList()
- },
- //上拉加载
- onReachBottom() {
- if (this.status == "more") {
- this.params.page++
- this.getList()
- }
- },
- filters:{
- secondsFormat(s) {
- var day = Math.floor(s / (24 * 3600)); // Math.floor()向下取整
- var hour = Math.floor((s - day * 24 * 3600) / 3600);
- var minute = Math.floor((s - day * 24 * 3600 - hour * 3600) / 60);
- var second = s - day * 24 * 3600 - hour * 3600 - minute * 60;
- if (hour) {
- return hour + ":" + minute + ":" + second;
- } else {
- if (second < 10) {
- if (minute < 10) {
- return "0" + minute + ":" + second + "0";
- } else {
- return minute + ":" + second + "0";
- }
- } else {
- return minute + ":" + second.toFixed(0);
- }
- }
- }
-
- },
- methods: {
- audioErr(e) {
- console.log(e)
- console.log('音频错误')
- },
- audioPlay(v,k) {
- this.contextArr.forEach((item,key) => {
- if(v.id == item.id) {
- if(!v.play) {
- item.audioCtx.play()
- this.itemList[k].play = true
- }else {
- item.audioCtx.pause()
- this.itemList[k].play = false
- }
- }
- })
- // if(!v.play) {
- // this.audioCtx.play()
- // this.itemList[k].play = true
- // }else {
- // this.audioCtx.pause()
- // this.itemList[k].play = false
- // }
- console.log(v.filePath)
-
- },
- fullscreenchange(e){
-
- },
- copy(code) {
- uni.setClipboardData({
- data: code,
- success: () => {
- uni.showToast({
- title: "复制成功",
- });
- },
- });
- },
- //下载图片
- downloadImg(item) {
- // console.log(item.filePath)
- uni.showModal({
- title: "是否下载素材",
- success: function(res) {
- if (res.confirm) {
- uni.showLoading({
- title: '加载中'
- });
- uni.downloadFile({
- url: item.filePath,
- success: (res) => {
- if (res.statusCode === 200) {
- if(item.type == 0) {
- uni.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: function() {
- uni.hideLoading();
- uni.showToast({
- title: "保存成功",
- icon: "none"
- });
- console.log(res.tempFilePath)
- },
- fail: function(err) {
- uni.hideLoading();
- uni.showToast({
- title: "保存失败,请稍后重试",
- icon: "none"
- });
- console.log(err)
- }
- });
- }else if(item.type == 1) {
- uni.saveVideoToPhotosAlbum({
- filePath: res.tempFilePath,
- success: function() {
- uni.hideLoading();
- uni.showToast({
- title: "保存成功",
- icon: "none"
- });
- console.log(res.tempFilePath)
- },
- fail: function(err) {
- uni.hideLoading();
- uni.showToast({
- title: "保存失败,请稍后重试",
- icon: "none"
- });
- console.log(err)
- }
- });
- }else {
- uni.saveFile({
- tempFilePath: res.tempFilePath,
- success() {
- uni.hideLoading();
- uni.showToast({
- title: "保存成功",
- icon: "none"
- });
- },
- fail() {
- uni.hideLoading();
- uni.showToast({
- title: "保存失败,请稍后重试",
- icon: "none"
- });
- }
- })
- }
-
- }
- }
- })
- // downloadTask.onProgressUpdate((res)=>{
- // console.log("下载进度"+res.progress)
- // uni.showLoading({
- // title: '加载中'
- // });
- // })
- } else if (res.cancel) {
- console.log(777)
- }
- }
- })
- },
- //获取数据
- getList() {
- let _that = this;
- this.$http.get(material, this.params).then(res => {
- if (res && res.code == 200) {
- uni.stopPullDownRefresh()
- this.itemList = this.itemList.concat(res.page.list)
- if (res.page.totalPage <= res.page.currPage) {
- this.status = "noMore";
- } else {
- this.status = 'more'
- }
- let context = []
- _that.itemList.forEach(item => {
- if (item.type == 2) {
- context.push({
- id: item.id,
- audioCtx: uni.createInnerAudioContext(),
- src: item.filePath
- })
- context.forEach(vv => {
- vv.audioCtx.src = vv.src
- })
- _that.audioCtx.src = item.filePath;
- _that.audioCtx.startTime = 0
- // _that.audioCtx.autoplay = true;
- _that.audioCtx.onCanplay(() => {
-
- this.$set(item,"duration", _that.audioCtx.duration)
-
- console.log('开始播放' + item.duration);
- //alert(_that.audioCtx.duration + "---" + audioObj.filePath)
- });
- this.$set(item,"play", false)
- _that.contextArr = context
- }
- })
- console.log(this.contextArr)
- console.log('contextArr数组')
- }
- })
- },
- showlink() {
- this.$refs.popup[0].open()
- // this.$refs.popup.open()
- console.log(666)
- },
- doCopy() {
- },
- },
- onUnload() {
- this.audioCtx.destroy();
- this.audioCtx = null;
- }
- }
- </script>
- <style lang="scss" scoped>
- .jvideo {
- border-radius: 18rpx;
- }
- .zhan {
- background: #0B844A;
- height: 20px;
- width: 100%;
- position: fixed;
- }
- .background {
- // background: #0B844A;
- position: relative;
- z-index: 10;
- .content {
- overflow: hidden;
- background-color: #ffffff;
- border-radius: 40rpx 40rpx 0 0;
- .item {
- display: flex;
- padding: 40rpx 30rpx 40rpx 30rpx;
- margin-bottom: 41rpx;
- border-bottom: 10rpx solid #f5f5f5;
- overflow: hidden;
- .forward {
- // 弹出框
- height: 565rpx;
- background-color: #ffffff;
- border-radius: 50rpx 50rpx 0 0;
- .top {
- padding: 37rpx 0 12rpx 0;
- text-align: center;
- .text {
- font-size: 36rpx;
- font-weight: 700;
- color: #1A1A1A;
- margin-bottom: 12rpx;
- }
- .line {
- margin: 0 auto;
- width: 64rpx;
- height: 8rpx;
- background-color: #cccccc;
- }
- }
- }
- .image {
- image {
- width: 76rpx;
- height: 76rpx;
- }
- }
- .gratitude {
- // flex-grow: 1;
-
- width: 100%;
- .top-box {
- display: flex;
-
- width: 100%;
- }
- .title {
- width: 600rpx;
- flex-grow: 1;
- font-size: 28rpx;
- color: #1a1a1a;
- font-weight: 400;
- line-height: 40rpx;
- margin-bottom: 18rpx;
- flex-basis: 0;
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
-
- }
- .iconfont {
- margin-left: 30rpx;
- font-size: 30rpx;
- color: #0B844A;
- // width: 50rpx;
- }
- .detailed {
- font-size: 28rpx;
- color: #999999;
- font-weight: 500;
- }
- .copy-file {
- margin-top: 18rpx;
- color: rgba(254, 144, 0, 1);
- text-decoration: underline;
- }
-
- .file-image {
- margin-top: 18rpx;
- image {
- width: 374rpx;
- height: 574rpx;
- border-radius: 18rpx;
-
- }
- .relative{
- position: relative;
- width: 100rpx;
- height: 100rpx;
- border: 1px solid #cccccc;
- display: flex;
- align-items: center;
- justify-content: center;
- .absolute{
- position: absolute;
- right: 30rpx;
- bottom: 30rpx;
- color: #888;
- font-size: 24rpx;
- }
- image {
- width: 50rpx;
- height: 50rpx;
- }
- }
- }
- }
- .link {
- position: absolute;
- right: 30rpx;
- top: 57rpx;
- // line-height: 76rpx;
- image {
- width: 43rpx;
- height: 41rpx;
- }
- }
- }
- }
- }
- </style>
|