123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770 |
- const app=getApp();
- var utils=require("../../../utils/http");
- const util=require("../../../utils/util");
- let nowfid='',copytextarr=[],copyimgarr=[];
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- storeflag:false,
- wxfriendlist:[],
- imgUrl:app.globalData.imgUrl,
- friendpage:1,
- wxlabel:'',
- friendkeytext:'',
- companylabel:[],
- videoid:[],
- nowlabel:'',
- text:'养成良好的发圈习惯^.^',
- fromtype:'',
- filterId: '',
- tab: [{
- name: '全部',
- type: ''
- },{
- name: '分类',
- type: '3'
- }]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- let that = this;
- if (options.id) {
- that.setData({
- filterId: options.id
- })
- }
- this.friendtitfun();
- this.wxfriendfun();
- },
- dothis(){},
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- closetitleTap(){
- this.setData({
- storeflag:false
- })
- },
- setfromtap(e){
- this.setData({
- fromtype: e.currentTarget.dataset.type,
- storeflag:false,
- allfiltrate:false
- })
- if(this.data.fromtype===''){
- this.data.tab[1].name = '分类';
- this.setData({
- wxlabel:'',
- nowlabel:'',
- festival_id:'',
- tab: this.data.tab
- })
- } else {
- this.setData({
- allfiltrate:true
- })
- }
- this.wxfriendfun();
- },
- opentitleTap(){
- this.setData({
- storeflag:true
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- // var that=this;
- // const query = wx.createSelectorQuery()
- // query.select('.pagetop').boundingClientRect()
- // query.selectViewport().scrollOffset()
- // query.exec(function(res){
- // that.setData({
- // dayght:res[0].height
- // })
- // })
- },
- titleTap:function(e){
- this.data.tab[1].name = e.currentTarget.dataset.text;
- this.setData({
- wxlabel:e.currentTarget.dataset.tid,
- tab: this.data.tab,
- allfiltrate:false,
- fromtype: '3'
- })
- this.wxfriendfun();
- },
- friendtitfun:function(){
- var that=this;
- utils.$post({
- url: app.globalData.webUrl + 'api/daily_wechat/label_list',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{},
- success: function (res) {
- that.setData({
- companylabel:res.data
- })
- }
- })
- },
- wxfriendfun:function(e){
- var that=this;
- this.setData({
- friendpage:1
- })
- utils.$get({
- url: app.globalData.webUrl + 'api/daily_wechat/list',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- page:1,
- limit:10,
- festival_id:that.data.wxlabel,
- keyword:that.data.friendkeytext,
- from_type:that.data.fromtype=='3'?'':'',
- id: that.data.filterId
- },
- success: function (res) {
- setTimeout(function(){
- wx.hideLoading()
- },1000)
- if(res.data.code=='0'){
- // var arr=[ 'png','PNG','jpg','JPG', 'jpeg','JPEG', 'bmp','BMP', 'gif',"GIF","WEBP", 'webp', 'psd',"PSD", 'svg', 'tiff'];
-
- for(let i=0;i<res.data.data.length;i++){
- res.data.data[i].textflag=0;
- // if(res.data.data[i].type==2){
- // res.data.data[i].picture=res.data.data[i].picture.split(',');
- // }
- if(res.data.data[i].content.length>62){
- res.data.data[i].othercontent=res.data.data[i].content.substring(0,60)+'...';
- res.data.data[i].textflag=0;
- }else{
- res.data.data[i].othercontent=res.data.data[i].content;
- res.data.data[i].textflag=1;
- }
- }
- that.setData({
- wxfriendlist:res.data.data,
- datashow:true
- })
- }
- },
- fail(){
- wx.hideLoading()
- }
- })
- },
- previewImg:function(e){
- var that=this;
- var idx = e.target.dataset.src,current;
- var imglist=[];
-
- for(var i=0;i<that.data.wxfriendlist.length;i++){
- if(that.data.wxfriendlist[i].id==idx){
- imglist=that.data.wxfriendlist[i].picture;
- }
- }
- current=e.target.dataset.vsrc;
- wx.previewImage({
- current:current, // 当前显示图片的http链接
- urls: imglist, // 需要预览的图片http链接列表
- fail(res){
- console.log(res)
- }
- })
- },
- copy:function(e){
- var that=this;
-
- wx.setClipboardData({
- data: e.currentTarget.dataset.text,
- success (res) {
- let nowcopy=false;
- let friendArr=that.data.wxfriendlist;
- nowfid=e.currentTarget.dataset.fid;
- for(let i in copyimgarr){
- if(nowfid==copyimgarr[i]){
- that.addusenumfun();
- nowcopy=true;
- }
- }
- if(!friendArr[e.currentTarget.dataset.idx].picture){
- that.addusenumfun();
- }else if(!nowcopy){
- nowfid=e.currentTarget.dataset.fid;
- let flag=false;
- for(let i in copytextarr){
- if(nowfid==copytextarr[i]){
- flag=true;
- }
- }
- if(!flag){
- copytextarr.push(nowfid);
- }
- }
-
- }
- })
- },
- saveVideo:function(e){
- var that=this;
- wx.showLoading({
- title: '加载中',
- })
- let str1=e.currentTarget.dataset.vsrc;
- var str=str1.replace('http',"https");
- wx.getSetting({
- success(res) {
-
- if (!!res.authSetting['scope.writePhotosAlbum']) {
- that.savevideoToLocal(e.currentTarget.dataset.vsrc,e);
-
- }else{
-
- wx.hideLoading()
- wx.showModal({
- title: '提示',
- content: '您好,请先授权,再保存此图片。',
- showCancel: false,
- success(res) {
- if (res.confirm) {//重新授权弹框用户点击了确定
- wx.openSetting({//进入小程序授权设置页面
- success(settingdata) {
- if (!settingdata.authSetting['scope.writePhotosAlbum']) {
- wx.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- //这里是用户同意授权后的回调
- that.savevideoToLocal(e.currentTarget.dataset.vsrc,e);
- },
- fail(rs){
- console.log(rs)
- }
- })
- }else{
- wx.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- //这里是用户同意授权后的回调
- that.savevideoToLocal(e.currentTarget.dataset.vsrc,e);
- },
- fail(rs){
- console.log(rs)
- }
- })
- }
- },
- fail(res){
- wx.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- //这里是用户同意授权后的回调
- that.savevideoToLocal(e.currentTarget.dataset.vsrc,e);
- },
- })
- }
- })
- }
- },
- fail(res){
- that.savevideoToLocal(e.currentTarget.dataset.vsrc,e);
- }
- })
- }
- }
- })
- },
- savevideoToLocal:function(vsrc,e){
- let that=this;
- var friendArr=that.data.wxfriendlist;
- wx.showLoading({
- title: '加载中',
- })
- var str=vsrc.replace('http',"https");
- var num=0;
- wx.downloadFile({
- url: str, //仅为示例,并非真实的资源
- success (res) {
- if (res.statusCode === 200) {
- wx.saveVideoToPhotosAlbum({
- filePath: res.tempFilePath,
- success (res) {
- wx.hideLoading()
- num++;
- that.setData({
- num:num
- })
- that.setData({
- downloaded:true
- })
- setTimeout(function(){
- that.setData({
- downflag:false
- })
- },1200)
- let nowcopy=false;
-
- for(let i in copytextarr){
- if(nowfid==copytextarr[i]){
- that.addusenumfun();
- nowcopy=true;
- }
- }
- if(!nowcopy){
- nowfid=e.currentTarget.dataset.fid;
- let flag=false;
- for(let i in copyimgarr){
- if(nowfid==copyimgarr[i]){
- flag=true;
- }
- }
- if(!flag){
- copyimgarr.push(nowfid);
- }
- }
-
- wx.hideLoading()
- },
- fail(r){
- wx.hideLoading()
- that.setData({
- downflag:false
- })
- }
- })
- }else{
- wx.hideLoading()
- wx.showModal({
- title: '下载失败',
- content: '下载失败,重新下载!',
- showCancel: false,
- })
- that.setData({
- downflag:false
- })
- }
- },
- fail(r){
- wx.hideLoading();
- wx.showModal({
- title: '下载失败',
- content: '下载失败,重新下载!',
- showCancel: false,
- })
- that.setData({
- downflag:false
- })
- }
- })
- },
- saveImg:function(e){
- var that=this;
-
- wx.getSetting({
- success(res) {
-
- if (!!res.authSetting['scope.writePhotosAlbum']) {
- that.saveImgToLocal(e.currentTarget.dataset.img,e);
- }else{
-
- wx.hideLoading()
- wx.showModal({
- title: '提示',
- content: '您好,请先授权,再保存此图片。',
- showCancel: false,
- success(res) {
- if (res.confirm) {//重新授权弹框用户点击了确定
- wx.openSetting({//进入小程序授权设置页面
- success(settingdata) {
- if (!settingdata.authSetting['scope.writePhotosAlbum']) {
- wx.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- //这里是用户同意授权后的回调
- that.saveImgToLocal(e.currentTarget.dataset.img,e);
- },
- fail(rs){
- console.log(rs)
- }
- })
- }else{
- wx.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- //这里是用户同意授权后的回调
- that.saveImgToLocal(e.currentTarget.dataset.img,e);
- },
- fail(rs){
- console.log(rs)
- }
- })
- }
- },
- fail(res){
- wx.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- //这里是用户同意授权后的回调
- that.saveImgToLocal(e.currentTarget.dataset.img,e);
- },
- })
- }
- })
- }
- },
- fail(res){
- that.saveImgToLocal(e.currentTarget.dataset.img,e);
- }
- })
- }
- }
- })
- },
- saveImgToLocal:function(eimg,e){
- let that=this;
- var friendArr=that.data.wxfriendlist;
- wx.showLoading({
- title: '加载中',
- })
- for(var i=0;i<friendArr.length;i++){
- if(friendArr[i].id==eimg){
- that.setData({
- downlen:friendArr[i].picture.length,
- num:0,
- downflag:true,
- downloaded:false
- })
- var num=that.data.num;
- for(var j=0;j<friendArr[i].picture.length;j++){
- var str=friendArr[i].picture[j].replace('http',"https");
- wx.downloadFile({
- url: str, //仅为示例,并非真实的资源
- success (res) {
- if (res.statusCode === 200) {
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success (res) {
- num++;
- that.setData({
- num:num
- })
- if(num==that.data.downlen){
- let nowcopy=false;
- for(let i in copytextarr){
- if(nowfid==copytextarr[i]){
- that.addusenumfun();
- nowcopy=true;
- }
- }
- if(!nowcopy){
- nowfid=e.currentTarget.dataset.fid;
- let flag=false;
- for(let i in copyimgarr){
- if(nowfid==copyimgarr[i]){
- flag=true;
- }
- }
- if(!flag){
- copyimgarr.push(nowfid);
- }
- }
- that.setData({
- downloaded:true
- })
- setTimeout(function(){
- that.setData({
- downflag:false
- })
- },1200)
-
- }
- wx.hideLoading()
- },
- fail(r){
- wx.hideLoading()
- that.setData({
- downflag:false
- })
- }
- })
- }else{
- wx.hideLoading()
- wx.showModal({
- title: '下载失败',
- content: '下载失败,重新下载!',
- showCancel: false,
- })
- that.setData({
- downflag:false
- })
- }
- },
- fail(r){
- wx.hideLoading();
- wx.showModal({
- title: '下载失败',
- content: '下载失败,重新下载!',
- showCancel: false,
- })
- that.setData({
- downflag:false
- })
- }
- })
- }
- }
- }
- },
- addusenumfun(){
- const that=this;
- utils.$post({
- url: app.globalData.webUrl + 'api/daily_wechat/use_count',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- id:nowfid,
- },
- success: function (res) {
- if(res.data.code==0){
- let arr=that.data.wxfriendlist;
- for(let i in arr){
- if(arr[i].id==nowfid){
- arr[i].use_count=arr[i].use_count*1+1;
- that.setData({
- wxfriendlist:arr
- })
- }
- }
- copyimgarr=[];
- copytextarr=[];
- nowfid='';
- }
- }
- })
- },
- filtratetap:function(){
- this.setData({
- allfiltrate:true
- })
- },
- closetap:function(){
- this.setData({
- allfiltrate:false
- })
- },
- bindplay:function(e){
- var that=this;
- var videoid=that.data.videoid;
- var flag=false;
- videoid.push(e.currentTarget.dataset.vid);
- for(var i=0;i<videoid.length;i++){
- if(videoid[i]!=e.currentTarget.dataset.vid){
- const videoContext = that.selectComponent('#'+videoid[i]);
- videoContext.pause();
- videoid.splice(i, 1);
- flag=true;
- }
- }
-
- that.setData({
- videoid:videoid
- })
- },
- bindpause:function(e){
- var that=this;
- var videoid=that.data.videoid;
- const videoContext = that.selectComponent('#video'+e.currentTarget.dataset.vid);
- videoContext.pause();
- for(var i=0;i<videoid.length;i++){
- if(videoid[i]==e.currentTarget.dataset.vid){
- videoid.splice(i, 1);
- }
- }
- that.setData({
- videoid:videoid
- })
- },
- bindended:function(e){
- var that=this;
- var videoid=that.data.videoid;
- const videoContext = that.selectComponent('#video'+e.target.dataset.vid);
- videoContext.stop();
- for(var i=0;i<videoid.length;i++){
- if(videoid[i]==e.currentTarget.dataset.vid){
- videoid.splice(i, 1);
- }
- }
- videoid=[];
- that.setData({
- videoid:videoid
- })
- },
- onPageScroll: function (e) {
- var that=this;
- let screenHeight = wx.getSystemInfoSync().windowHeight
- let topBottomPadding = (screenHeight - 175) / 2
- const videoObserve = wx.createIntersectionObserver()
- videoObserve.relativeToViewport({
- bottom: -topBottomPadding,
- top: -topBottomPadding
- })
- .observe("#video"+that.data.videoid[0], (res) => {
- // console.log(res)
- var videoContext = that.selectComponent('#video'+that.data.videoid[0])
- let {
- intersectionRatio
- } = res
- if (intersectionRatio === 0) {
- //离开视界,因为视窗占比为0,停止播放
- if(videoContext){
- videoContext.pause()
- }
-
- }
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- var that=this;
- this.setData({
- friendpage:1
- })
- if (!that.data.wxlabel) {
- console.log(that.data.wxlabel)
- that.setData({
- fromtype: ''
- })
- }
- utils.$get({
- url: app.globalData.webUrl + 'api/daily_wechat/list',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- page:1,
- limit:10,
- festival_id:that.data.wxlabel,
- keyword:that.data.friendkeytext,
- from_type: that.data.fromtype=='3'?'':'',
- },
- success: function (res) {
- wx.stopPullDownRefresh()
- if(res.data.code=='0'){
- // var arr=[ 'png','PNG','jpg','JPG', 'jpeg','JPEG', 'bmp','BMP', 'gif',"GIF","WEBP", 'webp', 'psd',"PSD", 'svg', 'tiff'];
-
- for(let i=0;i<res.data.data.length;i++){
- res.data.data[i].textflag=0;
- // if(res.data.data[i].type==2){
- // res.data.data[i].picture=res.data.data[i].picture.split(',');
- // }
- if(res.data.data[i].content.length>62){
- res.data.data[i].othercontent=res.data.data[i].content.substring(0,60)+'...';
- res.data.data[i].textflag=0;
- }else{
- res.data.data[i].othercontent=res.data.data[i].content;
- res.data.data[i].textflag=1;
- }
- }
- that.setData({
- wxfriendlist:res.data.data,
- datashow:true
- })
- }
- },
- fail(){
- wx.hideLoading()
- }
- })
- },
- opentap(e){
- const that=this;
- let wxfriendlist=that.data.wxfriendlist;
- wxfriendlist[e.currentTarget.dataset.idx].textflag=wxfriendlist[e.currentTarget.dataset.idx].textflag==1?0:1;
- this.setData({
- wxfriendlist:wxfriendlist
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- var that=this;
- let friendpage=that.data.friendpage;
- friendpage=friendpage*1+1;
- this.setData({
- friendpage:friendpage
- })
- utils.$get({
- url: app.globalData.webUrl + 'api/daily_wechat/list',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- page:friendpage,
- limit:10,
- festival_id:that.data.wxlabel,
- keyword:that.data.friendkeytext,
- from_type:that.data.fromtype=='3'?'':'',
- },
- success: function (res) {
- if(res.data.code=='0'){
- for(let i=0;i<res.data.data.length;i++){
-
- if(res.data.data[i].content.length>62){
- res.data.data[i].othercontent=res.data.data[i].content.substring(0,60)+'...';
- res.data.data[i].textflag=0;
- }else{
- res.data.data[i].othercontent=res.data.data[i].content;
- res.data.data[i].textflag=1;
- }
- }
- let wxfriendlist=that.data.wxfriendlist;
- wxfriendlist=wxfriendlist.concat(res.data.data);
- that.setData({
- wxfriendlist:wxfriendlist
- })
- }
- },
- fail(){
- wx.hideLoading()
- }
- })
- },
- /**
- * 用户点击右上角分享
- */
-
- })
|