完善canvas图片绘制

master
chen 2021-12-09 13:02:47 +08:00
parent 245d0886b1
commit b05c3a3132
22 changed files with 602 additions and 164 deletions

View File

@ -9,7 +9,8 @@
"pages/ranking/ranking", "pages/ranking/ranking",
"pages/picture/picture", "pages/picture/picture",
"pages/personal/personal", "pages/personal/personal",
"pages/auth/auth" "pages/auth/auth",
"pages/works/works"
], ],
"tabBar": { "tabBar": {
"custom": true, "custom": true,

View File

@ -1,5 +1,6 @@
var host = "https://vote.daiguanyun.com"; // var host = "https://vote.daiguanyun.com";
var host = "http://192.168.2.15:8810"; // var host = "http://192.168.2.15:8810";
var host = "https://fenggu.scdxtc.cn";
var config = { var config = {
host:host, host:host,
getopenid: host + "/index/getOpenId", getopenid: host + "/index/getOpenId",
@ -18,6 +19,8 @@ var config = {
search: host + '/index/search', search: host + '/index/search',
getBottleCategories: host + '/index/getBottleCategories',//酒瓶标题 getBottleCategories: host + '/index/getBottleCategories',//酒瓶标题
composeBottle: host + '/index/composeBottle',//保存图片 composeBottle: host + '/index/composeBottle',//保存图片
getBottleWidgets: host + '/index/getBottleWidgets',//查询作品 getBottleWidgets: host + '/index/getBottleWidgets',//查询脸庞
myBottleReleaseList: host + '/index/myBottleReleaseList',//查询自己的作品
publishMyBottle: host + '/index/publishMyBottle',//分享作品
} }
module.exports = config; module.exports = config;

BIN
img/background/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 914 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 891 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

View File

@ -17,66 +17,23 @@ Page({
*/ */
data: { data: {
isLogin: false, //是否授权 isLogin: false, //是否授权
funBox:true,//功能框 funBox: true, //功能框
itemList: [], itemList: [],
showBtn: false, //按钮 showBtn: false, //按钮
showBox: false, //弹框 showBox: false, //弹框
titlelist: ['脸谱', '背景', '按钮', '川剧', '人物', '文字', '装饰'], // titlelist: ['脸谱', '背景', '按钮', '川剧', '人物', '文字', '装饰'],
titlelist: [],
titleIndex: '-1', titleIndex: '-1',
allList: [ allList: [
'../../img/background/3.png', '../../img/background/1.png',
'../../img/background/3.png',
'../../img/background/3.png',
'../../img/background/3.png',
'../../img/background/3.png',
'../../img/background/3.png',
'../../img/background/3.png',
'../../img/background/3.png',
], ],
allIndex: '-1', allIndex: '-1',
faceImg: [ isOk: false,
'../../img/face/3.png', isNo: false,
'../../img/face/4.png', closeTime: null,
'../../img/face/3.png', titleVal:'',
'../../img/face/3.png', showTitle:false,
], times:0
operaImg: [
'../../img/opera/3.png',
'../../img/opera/4.png',
'../../img/opera/5.png',
'../../img/opera/5.png',
'../../img/opera/4.png',
'../../img/opera/3.png',
],
backgroundImg: [
'../../img/background/2.png',
'../../img/background/3.png',
'../../img/background/2.png',
'../../img/background/3.png',
],
buttonImg: [
'../../img/button/2.png',
'../../img/button/1.png',
'../../img/button/2.png',
'../../img/button/1.png',
],
personageImg: [
'../../img/personage/1.png',
'../../img/personage/2.png',
'../../img/personage/3.png',
],
wordImg: [
'../../img/word/1.png',
'../../img/word/2.png',
'../../img/word/3.png',
],
decorateImg: [
'../../img/decorate/1.png',
'../../img/decorate/2.png',
'../../img/decorate/3.png',
],
isOk:false,
isNo:false
}, },
chooseTitle(e) { chooseTitle(e) {
let that = this; let that = this;
@ -85,46 +42,11 @@ Page({
allIndex: '-1' allIndex: '-1'
}) })
} }
that.setData({ this.setData({
titleIndex: e.currentTarget.dataset.index, titleIndex: e.currentTarget.dataset.index,
showBox: true,
showBtn: true showBtn: true
}) })
if (that.data.titlelist[that.data.titleIndex] == "脸谱") { this.getBottleWidgets(that.data.titlelist[that.data.titleIndex].id);
that.setData({
allList: that.data.faceImg
})
}
if (that.data.titlelist[that.data.titleIndex] == "川剧") {
that.setData({
allList: that.data.operaImg
})
}
if (that.data.titlelist[that.data.titleIndex] == "背景") {
that.setData({
allList: that.data.backgroundImg
})
}
if (that.data.titlelist[that.data.titleIndex] == "按钮") {
that.setData({
allList: that.data.buttonImg
})
}
if (that.data.titlelist[that.data.titleIndex] == "人物") {
that.setData({
allList: that.data.personageImg
})
}
if (that.data.titlelist[that.data.titleIndex] == "文字") {
that.setData({
allList: that.data.wordImg
})
}
if (that.data.titlelist[that.data.titleIndex] == "装饰") {
that.setData({
allList: that.data.decorateImg
})
}
}, },
chooseImg(e) { chooseImg(e) {
let that = this; let that = this;
@ -133,14 +55,38 @@ Page({
showBox: false, showBox: false,
showBtn: false showBtn: false
}) })
if (that.data.titleIndex == 1) { if (that.data.titleIndex == 0) {
this.setBackGroundImg({ wx.getStorage({ //获取本地缓存
url: that.data.backgroundImg[that.data.allIndex] key: that.data.allList[that.data.allIndex].img,
}); success: function(res) {
console.log(res);
that.setBackGroundImg({
url: res.data
});
},
})
} else { } else {
that.setDropItem({ wx.getStorage({ //获取本地缓存
url: that.data.allList[that.data.allIndex] key: that.data.allList[that.data.allIndex].img,
}); success: function(res) {
that.setDropItem({
url: res.data
});
},
})
}
},
titleInput(e){
this.setData({
titleVal:e.detail.value
})
},
submit(){
if(this.data.titleVal==''){
wx.showToast({title:'请输入标题',icon:'none'})
} else {
wx.showToast({title:'设置标题成功',icon:'none'})
this.setData({showTitle:false})
} }
}, },
onShow: function() { onShow: function() {
@ -161,16 +107,16 @@ Page({
this.sysData = sysData; this.sysData = sysData;
// 设置画布宽高this.sysData.windowWidth为屏幕的宽度 // 设置画布宽高this.sysData.windowWidth为屏幕的宽度
this.setData({ this.setData({
canvasWidth: this.sysData.windowWidth *canvasPre, // 如果觉得不清晰的话,可以把所有组件、宽高放大一倍 canvasWidth: this.sysData.windowWidth *
canvasPre, // 如果觉得不清晰的话,可以把所有组件、宽高放大一倍
canvasHeight: this.sysData.windowWidth * canvasPre * hCw, canvasHeight: this.sysData.windowWidth * canvasPre * hCw,
backGroundWidth: this.sysData.windowWidth, backGroundWidth: this.sysData.windowWidth,
backGroundHeight: this.sysData.screenHeight backGroundHeight: this.sysData.screenHeight
}) })
} }
}) })
this.setBackGroundImg({ this.setBackGroundImg({
url: this.data.backgroundImg[0] url: '../../img/background/1.png'
}); });
this.getBottleCategories(); this.getBottleCategories();
}, },
@ -191,7 +137,6 @@ Page({
}, },
// 设置背景图片 // 设置背景图片
setBackGroundImg(imgData) { setBackGroundImg(imgData) {
console.log(imgData);
let data = {}; // 存储图片信息 let data = {}; // 存储图片信息
// 获取图片信息网络图片需先配置download域名才能生效 // 获取图片信息网络图片需先配置download域名才能生效
wx.getImageInfo({ wx.getImageInfo({
@ -200,7 +145,6 @@ Page({
// 初始化数据 // 初始化数据
let maxWidth = this.data.backGroundWidth, let maxWidth = this.data.backGroundWidth,
maxHeight = this.data.backGroundHeight; // 设置最大宽高 maxHeight = this.data.backGroundHeight; // 设置最大宽高
console.log(maxWidth, maxHeight);
if (res.width > maxWidth || res.height > maxHeight) { // 原图宽或高大于最大值就执行 if (res.width > maxWidth || res.height > maxHeight) { // 原图宽或高大于最大值就执行
if (res.width / res.height > maxWidth / maxHeight) { // 判断比例使用最大值的宽或高作为基数计算 if (res.width / res.height > maxWidth / maxHeight) { // 判断比例使用最大值的宽或高作为基数计算
data.width = maxWidth; data.width = maxWidth;
@ -222,6 +166,7 @@ Page({
data.scale = 1; // scale缩放 data.scale = 1; // scale缩放
data.rotate = 1; // 旋转角度 data.rotate = 1; // 旋转角度
data.active = false; // 选中状态 data.active = false; // 选中状态
data.angle = 0;
items[0] = data; // 每增加一张图片数据增加一条信息 items[0] = data; // 每增加一张图片数据增加一条信息
this.setData({ this.setData({
itemList: items itemList: items
@ -259,7 +204,8 @@ Page({
data.scale = 1; // scale缩放 data.scale = 1; // scale缩放
data.rotate = 1; // 旋转角度 data.rotate = 1; // 旋转角度
data.active = false; // 选中状态 data.active = false; // 选中状态
console.log(data); data.angle = 0;
console.log(data, 123);
items[items.length] = data; // 每增加一张图片数据增加一条信息 items[items.length] = data; // 每增加一张图片数据增加一条信息
this.setData({ this.setData({
itemList: items itemList: items
@ -287,7 +233,7 @@ Page({
} }
this.setData({ this.setData({
showBox: false, showBox: false,
funBox:false funBox: false
}) })
}, },
// 拖动图片 // 拖动图片
@ -307,17 +253,20 @@ Page({
this.setData({ this.setData({
itemList: items, itemList: items,
showBtn: true, showBtn: true,
funBox:false funBox: false
}) })
} }
}, },
// 放开图片 // 放开图片
WraptouchEnd() { WraptouchEnd() {
this.synthesis(); // 调用合成图方法 this.synthesis(); // 调用合成图方法
this.setData({ clearTimeout(this.data.closeTime);
showBtn: false, this.data.closeTime = setTimeout(() => {
funBox:true this.setData({
}) showBtn: false,
funBox: true
})
}, 1000)
}, },
// 点击伸缩图标 // 点击伸缩图标
oTouchStart(e) { oTouchStart(e) {
@ -342,12 +291,14 @@ Page({
items[index]._tx = e.touches[0].clientX; items[index]._tx = e.touches[0].clientX;
items[index]._ty = e.touches[0].clientY; items[index]._ty = e.touches[0].clientY;
//移动的点到圆心的距离 //移动的点到圆心的距离
items[index].disPtoO = this.getDistancs(items[index].x, items[index].y, items[index]._tx, items[index]._ty - 10) items[index].disPtoO = this.getDistancs(items[index].x, items[index].y, items[index]._tx, items[
index]._ty - 10)
items[index].scale = items[index].disPtoO / items[index].r; items[index].scale = items[index].disPtoO / items[index].r;
//移动后位置的角度 //移动后位置的角度
items[index].angleNext = this.countDeg(items[index].x, items[index].y, items[index]._tx, items[index]._ty) items[index].angleNext = this.countDeg(items[index].x, items[index].y, items[index]._tx, items[
index]._ty)
//角度差 //角度差
items[index].new_rotate = items[index].angleNext - items[index].anglePre; items[index].new_rotate = items[index].angleNext - items[index].anglePre;
@ -358,7 +309,8 @@ Page({
//用过移动后的坐标赋值为移动前坐标 //用过移动后的坐标赋值为移动前坐标
items[index].tx = e.touches[0].clientX; items[index].tx = e.touches[0].clientX;
items[index].ty = e.touches[0].clientY; items[index].ty = e.touches[0].clientY;
items[index].anglePre = this.countDeg(items[index].x, items[index].y, items[index].tx, items[index].ty) items[index].anglePre = this.countDeg(items[index].x, items[index].y, items[index].tx, items[index]
.ty)
//赋值setData渲染 //赋值setData渲染
this.setData({ this.setData({
@ -369,7 +321,7 @@ Page({
getDistancs(cx, cy, pointer_x, pointer_y) { getDistancs(cx, cy, pointer_x, pointer_y) {
this.setData({ this.setData({
showBtn: true, showBtn: true,
funBox:false funBox: false
}) })
var ox = pointer_x - cx; var ox = pointer_x - cx;
var oy = pointer_y - cy; var oy = pointer_y - cy;
@ -422,7 +374,20 @@ Page({
openMask() { openMask() {
this.synthesis(); this.synthesis();
this.setData({ this.setData({
showCanvas: true showCanvas: true,
showTitle:true
})
},
downLoadImg(netUrl, storageKeyUrl) {
wx.getImageInfo({
src: netUrl, //请求的网络图片路径
success: function(res) {
//请求成功后将会生成一个本地路径即res.path,然后将该路径缓存到storageKeyUrl关键字中
wx.setStorage({
key: storageKeyUrl,
data: res.path,
});
}
}) })
}, },
synthesis() { // 合成图片 synthesis() { // 合成图片
@ -431,15 +396,16 @@ Page({
// 画背景色(白色) // 画背景色(白色)
maskCanvas.setFillStyle('#fff'); maskCanvas.setFillStyle('#fff');
maskCanvas.fillRect(0, 0, this.data.canvasWidth, this.data.backGroundHeight); maskCanvas.fillRect(0, 0, this.data.canvasWidth, this.data.backGroundHeight);
console.log(this.data.canvasWidth, this.data.backGroundHeight);
items.forEach((currentValue, index) => { items.forEach((currentValue, index) => {
maskCanvas.save(); maskCanvas.save();
maskCanvas.translate(0, 0); maskCanvas.translate(0, 0);
maskCanvas.beginPath(); maskCanvas.beginPath();
maskCanvas.translate(currentValue.x, currentValue.y); // 圆心坐标 maskCanvas.translate(currentValue.x, currentValue.y); // 圆心坐标
maskCanvas.rotate(currentValue.angle * Math.PI / 180); maskCanvas.rotate(currentValue.angle * Math.PI / 180);
maskCanvas.translate(-(currentValue.width * currentValue.scale / 2), -(currentValue.height *currentValue.scale / 2)) maskCanvas.translate(-(currentValue.width * currentValue.scale / 2), -(currentValue.height *
maskCanvas.drawImage(currentValue.image, 0, 0, currentValue.width * currentValue.scale,currentValue.height * currentValue.scale); currentValue.scale / 2))
maskCanvas.drawImage(currentValue.image, 0, 0, currentValue.width * currentValue.scale,
currentValue.height * currentValue.scale);
maskCanvas.restore(); maskCanvas.restore();
}) })
// reserve 参数为 false则在本次调用绘制之前 native 层会先清空画布再继续绘制 // reserve 参数为 false则在本次调用绘制之前 native 层会先清空画布再继续绘制
@ -470,23 +436,28 @@ Page({
title: '保存成功', title: '保存成功',
icon: "success" icon: "success"
}) })
this.saveImgEv(this.data.canvasTemImg);
}, },
fail: res => { fail: res => {
wx.openSetting({
success: settingdata => {
if (settingdata.authSetting['scope.writePhotosAlbum']) {
console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
} else {
console.log('获取权限失败,给出不给权限就无法正常使用的提示')
}
},
fail: error => {
console.log(error)
}
})
wx.showModal({ wx.showModal({
title: '提示', title: '提示',
content: '保存失败,请确保相册权限已打开', content: '保存失败,请确保相册权限已打开',
success: (e) => {
if (e.confirm) {
wx.openSetting({
success: settingdata => {
if (settingdata.authSetting['scope.writePhotosAlbum']) {
console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
} else {
console.log('获取权限失败,给出不给权限就无法正常使用的提示')
}
},
fail: error => {
console.log(error)
}
})
}
}
}) })
} }
}) })
@ -496,30 +467,113 @@ Page({
}) })
} }
}, },
// 保存图片接口
saveImgEv(imgSrc) {
wx.uploadFile({
url: urlPath.composeBottle,
filePath: imgSrc,
name: 'image',
formData: {
'name': this.data.titleVal
},
header: {
"Content-Type": "multipart/form-data",
'token': wx.getStorageSync('token')
},
success: (data)=> {
if(data.statusCode==200){
wx.showToast({
title:'保存成功',
icon:'none'
})
this.setData({
showCanvas:false
})
}
},
fail: function(data) {
console.log(data);
}
})
},
// 分享图片
shareImg() { shareImg() {
if (wx.getStorageSync('token')) { if (wx.getStorageSync('token')) {
wx.downloadFile({ if(this.data.times==0){
url: this.data.canvasTemImg, wx.showToast({
success: (res) => { title:'正在调起分享',
wx.showShareImageMenu({ duration:5000
path: res.tempFilePath })
}) this.setData({
} times:this.data.times++
}) })
wx.uploadFile({
url: urlPath.composeBottle,
filePath: this.data.canvasTemImg,
name: 'image',
formData: {
'name': this.data.titleVal
},
header: {
"Content-Type": "multipart/form-data",
'Content-Type': 'application/json',
'token': wx.getStorageSync('token')
},
success: (res)=> {
let newRes = JSON.parse(res.data);
if(newRes.code==0){
wx.downloadFile({
url: 'https://fenggu.scdxtc.cn' + newRes.data.src,
success: (res) => {
wx.showShareImageMenu({
path: res.tempFilePath,
success:(res)=>{
this.shareEv(newRes.data.id);
}
})
}
})
}
},
fail: function(data) {
console.log(data);
}
})
}
} else { } else {
this.setData({ this.setData({
isLogin: true isLogin: true
}) })
} }
}, },
// 分享事件
shareEv(id) {
wx.request({
url: urlPath.publishMyBottle,
data: {id: id},
header: {'token': wx.getStorageSync('token')},
method: 'post',
success: (res) => {
if (res.data.code == 0) {
wx.showToast({title: '分享作品成功'})
}
}
});
},
// 关闭授权
chooseBtn(e) { chooseBtn(e) {
let loginIndex = e.currentTarget.dataset.index; let loginIndex = e.currentTarget.dataset.index;
this.setData({ this.setData({
isOk:false, isOk: false,
isNo:false isNo: false
})
loginIndex == 1 ? this.setData({
isOk: true
}) : this.setData({
isNo: true
}) })
loginIndex==1 ? this.setData({isOk:true}) : this.setData({isNo:true})
}, },
// 确认授权
shouq(e) { shouq(e) {
wx.getUserProfile({ //获取用户昵称 wx.getUserProfile({ //获取用户昵称
desc: '用于完善会员资料', desc: '用于完善会员资料',
@ -528,43 +582,106 @@ Page({
userInfo: res.userInfo, userInfo: res.userInfo,
isLogin: false isLogin: false
}) })
wx.showToast({title:'授权成功',icon:'none'}) wx.showToast({
this.setData({isOk:false}) title: '授权成功',
wx.login({//调用授权登录 icon: 'none'
})
this.setData({
isOk: false
})
wx.login({ //调用授权登录
success: res => { success: res => {
wx.request({ wx.request({
url: urlPath.getopenid, url: urlPath.getopenid,
method:'post', method: 'post',
data: { data: {
code: res.code, code: res.code,
wx_ame:this.data.userInfo.nickName, wx_name: this.data.userInfo.nickName,
avater:this.data.userInfo.avatarUrl, avater: this.data.userInfo.avatarUrl,
}, },
success(res) { success(res) {
console.log(res,1234); console.log(res, 1234);
if (res.data.code == 0) { if (res.data.code == 0) {
wx.setStorageSync('token', res.data.data.token); wx.setStorageSync('token', res.data.data
wx.setStorageSync('openid', res.data.data.openid); .token);
wx.setStorageSync('user', res.data.data.user); wx.setStorageSync('openid', res.data.data
.openid);
wx.setStorageSync('user', res.data.data
.user);
} }
} }
}); });
} }
}) })
}, },
fail:(res)=>{ fail: (res) => {
wx.showToast({title:'授权失败',icon:'none'}) wx.showToast({
this.setData({isOk:false}) title: '授权失败',
icon: 'none'
})
this.setData({
isOk: false
})
} }
}) })
}, },
getBottleCategories(){ getBottleCategories() {
wx.request({ wx.request({
url: urlPath.getBottleCategories, url: urlPath.getBottleCategories,
data: {}, success: (res) => {
success(res) { if (res.data.code == 0) {
console.log(res); if (res.data.data.length) {
this.setData({
titlelist: res.data.data
})
}
}
} }
}); });
},
getBottleWidgets(id) {
wx.request({
url: urlPath.getBottleWidgets,
method: 'post',
data: {
category_id: id,
size: 60
},
success: (res) => {
if (res.data.code == 0) {
if (res.data.data.length) {
let newArr = [];
res.data.data.forEach(item => {
let url = 'https://fenggu.scdxtc.cn' + item.img;
this.downLoadImg(url, 'https://fenggu.scdxtc.cn' + item.img);
let obj = {
id: item.id,
name: item.name,
img: 'https://fenggu.scdxtc.cn' + item.img
}
newArr.push(obj)
})
this.setData({
allList: newArr,
showBox: true
})
} else {
wx.showToast({
title:'无内容',
icon:'none'
})
this.setData({
showBox: false
})
}
}
}
});
},
checkWorkEv() {
wx.navigateTo({
url: '/pages/works/works'
})
} }
}) })

View File

@ -27,6 +27,14 @@
<button bindtap='disappearCanvas'>关闭</button> <button bindtap='disappearCanvas'>关闭</button>
</view> </view>
</view> </view>
<!-- 输入框 -->
<view wx:if="{{showTitle}}" class="content-box">
<view class="input-box">
<text>请为作品添加标题</text>
<input type="text" value="{{titleVal}}" bind:input="titleInput" placeholder="请收入作品标题" />
<view bindtap='submit'>确定</view>
</view>
</view>
<!-- 画布 --> <!-- 画布 -->
<canvas class='maskCanvas' canvas-id="maskCanvas" style='width:{{canvasWidth}}px; height:{{canvasHeight}}px;'></canvas> <canvas class='maskCanvas' canvas-id="maskCanvas" style='width:{{canvasWidth}}px; height:{{canvasHeight}}px;'></canvas>
<!-- 右下角操作按钮 --> <!-- 右下角操作按钮 -->
@ -35,19 +43,19 @@
<image src="../../img/download-icon.png" bindtap="openMask"></image> <image src="../../img/download-icon.png" bindtap="openMask"></image>
</view> </view>
<!-- 我的作品 --> <!-- 我的作品 -->
<navigator wx:if="{{funBox}}" url="/pages/works/works" hover-class="" class="works-btn">我的作品</navigator>
<view wx:if="{{funBox}}" class="choose-box {{showBox?'showBox':''}}"> <view wx:if="{{funBox}}" class="choose-box {{showBox?'showBox':''}}">
<view> <view>
<scroll-view scroll-x="true"> <scroll-view scroll-x="true">
<view class="scrollView title-box"> <view class="scrollView title-box">
<view wx:for="{{titlelist}}" class="{{titleIndex==index?'titleActive':''}}" data-index="{{index}}" bindtap="chooseTitle" wx:key="index">{{item}}</view> <view wx:for="{{titlelist}}" class="{{titleIndex==index?'titleActive':''}}" data-index="{{index}}" data-id="{{item.id}}" bindtap="chooseTitle" wx:key="index">{{item.name}}</view>
</view> </view>
</scroll-view> </scroll-view>
</view> </view>
<view> <view>
<scroll-view scroll-x="true"> <scroll-view scroll-x="true">
<view class="scrollView img-box"> <view class="scrollView img-box">
<view wx:for="{{allList}}" data-index="{{index}}" bindtap="chooseImg" wx:key="index"><image class="{{allIndex==index?'allActive':''}}" mode="widthFix" src="{{item}}" lazy-load></image></view> <view wx:for="{{allList}}" data-index="{{index}}" bindtap="chooseImg" wx:key="index"><image class="{{allIndex==index?'allActive':''}}" mode="widthFix" src="{{item.img}}" lazy-load></image></view>
</view> </view>
</scroll-view> </scroll-view>
</view> </view>

View File

@ -238,6 +238,56 @@
border: 4rpx dashed rgba(255, 255, 255, .4); border: 4rpx dashed rgba(255, 255, 255, .4);
box-shadow: 0rpx 0rpx 20rpx rgba(0, 0, 0, .8); box-shadow: 0rpx 0rpx 20rpx rgba(0, 0, 0, .8);
} }
.works-btn {
position: fixed;
right: 20rpx;
top: 20rpx;
z-index: 10000;
background-color: rgba(0,0,0,.3);
color: #fff;
font-size: 28rpx;
border-radius: 10rpx;
padding: 16rpx 20rpx;
}
.content-box {
position: fixed;
left: 0;
top: 0;
bottom: 0;
right: 0;
z-index: 100001;
display: flex;
justify-content: center;
align-items: center;
}
.input-box {
display: flex;
flex-direction: column;
background-color: rgba(255,255,255,.6);
border-radius: 6rpx;
padding: 20rpx;
color: #000;
font-size: 26rpx;
text-align: center;
}
.input-box text {
font-weight: bold;
}
.input-box input {
background-color: #fff;
margin-top: 20rpx;
text-align: left;
padding: 10rpx 20rpx;
height: auto;
}
.input-box view {
width: 100%;
margin-top: 20rpx;
padding: 20rpx;
color: #fff;
background-color: rgba(0,0,0,.2);
}
.auth-box {position: fixed;top: 0;right: 0;left: 0;bottom: 0;display: flex;justify-content: center;align-items: center;z-index: 1000;} .auth-box {position: fixed;top: 0;right: 0;left: 0;bottom: 0;display: flex;justify-content: center;align-items: center;z-index: 1000;}
.auth-box > view {background-color: #FFFFFF;border-radius: 10rpx;padding: 30rpx;box-shadow: 0rpx 0rpx 20rpx rgba(0,0,0,.5);margin: 0 100rpx;} .auth-box > view {background-color: #FFFFFF;border-radius: 10rpx;padding: 30rpx;box-shadow: 0rpx 0rpx 20rpx rgba(0,0,0,.5);margin: 0 100rpx;}
.auth-top {display: flex;} .auth-top {display: flex;}

171
pages/works/works.js Normal file
View File

@ -0,0 +1,171 @@
// pages/works/works.js
var urlPath = require('../../config.js');
Page({
/**
* 页面的初始数据
*/
data: {
workTitleArr: ['保存的作品', '分享的作品'],
workIndex: 0,
imgArr: [{
imgSrc: '../../img/background/1.png',
workName: '饺子吃肉肉饺子吃肉肉饺子吃肉肉饺子吃'
},
{
imgSrc: '../../img/background/1.png',
workName: '饺子吃肉肉'
},
{
imgSrc: '../../img/background/1.png',
workName: '饺子吃肉肉'
},
{
imgSrc: '../../img/background/1.png',
workName: '饺子吃肉肉'
},
{
imgSrc: '../../img/background/1.png',
workName: '饺子吃肉肉'
},
],
page: 1,
size: 200
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.checkImg();
},
// chooseTitle(e){
// let newIndex = e.currentTarget.dataset.index;
// this.setData({
// workIndex:newIndex
// })
// console.log(this.data.workIndex);
// },
checkImg() {
wx.request({
url: urlPath.myBottleReleaseList,
data: {
page: this.data.page,
size: this.data.size
},
header: {
'token': wx.getStorageSync('token')
},
method: 'post',
success: (res) => {
if (res.data.code == 0) {
let newArr = [];
if (res.data.data.list.length) {
res.data.data.list.forEach(item => {
let obj = {
name: item.name,
id: item.id,
imgSrc: 'https://fenggu.scdxtc.cn' + item.release_img,
userId: item.user_id,
time: item.create_time,
isShare: item.production_id //0未分享
}
newArr.push(obj);
})
}
this.setData({
imgArr: newArr
})
}
}
});
},
shareEv(e) {
wx.downloadFile({
url: this.data.imgArr[e.currentTarget.dataset.index].imgSrc,
success: (res) => {
wx.showShareImageMenu({
path: res.tempFilePath,
success:(res)=>{
this.shareImg(e.currentTarget.dataset.id,e.currentTarget.dataset.index);
},
fail:(err)=>{
console.log(err);
}
})
}
})
},
shareImg(id,index){
wx.request({
url: urlPath.publishMyBottle,
data: {
id: id
},
header: {
'token': wx.getStorageSync('token')
},
method: 'post',
success: (res) => {
if (res.data.code == 0) {
this.data.imgArr[index].isShare=1;
this.setData({
imgArr:this.data.imgArr
})
wx.showToast({
title: '分享作品成功'
})
}
}
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})

3
pages/works/works.json Normal file
View File

@ -0,0 +1,3 @@
{
"usingComponents": {}
}

16
pages/works/works.wxml Normal file
View File

@ -0,0 +1,16 @@
<!--pages/works/works.wxml-->
<!-- 标题 -->
<!-- <view class="title-box">
<view wx:for="{{workTitleArr}}" wx:key="index" bindtap="chooseTitle" data-index="{{index}}" class="title-btn {{workIndex==index?'workActive':''}}">{{item}}</view>
</view> -->
<!-- 列表 -->
<view class="img-list">
<view class="item-box" wx:for="{{imgArr}}" wx:key="index">
<image src="{{item.imgSrc}}" mode="widthFix" lazy-load></image>
<text class="clips2">{{item.name}}</text>
<view class="time">{{item.time}}</view>
<view wx:if="{{item.isShare==0}}" class="share-box" bindtap="shareEv" data-id="{{item.id}}" data-index="{{index}}">
<image src="../../img/share-icon.png"></image>
</view>
</view>
</view>

69
pages/works/works.wxss Normal file
View File

@ -0,0 +1,69 @@
/* pages/works/works.wxss */
page {
background-color: #F5f5f5;
}
.title-box {
display: flex;
justify-content: space-around;
margin-top: 20rpx;
}
.title-btn {
font-size: 28rpx;
color: #999;
}
.workActive {
color: #2a7be9!important;
text-shadow: 2rpx 2rpx 2rpx rgba(0,0,0,1);
}
.img-list {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
padding: 20rpx;
}
.img-list .item-box{
position: relative;
display: flex;
flex-direction: column;
align-items: center;
width: 48%;
background-color: #fff;
margin-bottom: 20rpx;
}
.share-box {
position: absolute;
top: 20rpx;
right: 20rpx;
display: flex;
justify-content: center;
align-items: center;
width: 60rpx;
height: 60rpx;
border-radius: 6rpx;
background-color: #fff;
box-shadow: 3rpx 3rpx ,10rpx rgba(0,0,0,.8);
}
.share-box image {
width: 40rpx!important;
height: 40rpx;
}
.img-list image {
width: 100%;
}
.img-list text {
width: 100%;
height: auto;
font-size: 26rpx;
color: #333;
padding: 10rpx 20rpx;
line-height: 40rpx;
}
.time {
width: 100%;
font-size: 24rpx;
color: #999;
text-align: left;
padding: 0 20rpx 10rpx 20rpx;
}
.clips2{display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;text-overflow: ellipsis;word-wrap: break-word;word-break:break-all;}