Commit 52207aa2 by wangyalan-git

添加

parent 162955ff
......@@ -18,28 +18,29 @@ App({
overShare: function () {
//监听路由切换
//间接实现全局设置分享内容
var that = this
wx.onAppRoute(function (res) {
//获取加载的页面
let pages = getCurrentPages(),
//获取当前页面的对象
view = pages[pages.length - 1],
data;
if (view) {
data = view.data;
console.log('是否重写分享方法', this.globalData.userInfo);
if (!data.isOverShare) {
data.isOverShare = true;
view.onShareAppMessage = function () {
//你的分享配置
return {
title: '中厦全供',
path: '/pages/index/index?shareCode='+ this.globalData.userInfo.shareCode
};
}
}
//获取加载的页面
let pages = getCurrentPages(),
//获取当前页面的对象
view = pages[pages.length - 1],
data;
if (view) {
data = view.data;
console.log('是否重写分享方法', that.globalData.userInfo);
if (!data.isOverShare) {
data.isOverShare = true;
view.onShareAppMessage = function () {
//你的分享配置
return {
title: '中厦全供',
path: '/pages/index/index?shareCode=' + that.globalData.userInfo.shareCode
};
}
}
}
})
},
},
globalData: {
userInfo: '',
// 定义全局请求队列
......
......@@ -80,12 +80,14 @@ Page({
},
onShow: function () {
console.log('页面参路径',this.options)
var that =this
wx.getSetting({
success(res) {
if (!res.authSetting['scope.userInfo']) {
if (this.options.shareCode) {
if (that.options.shareCode) {
wx.navigateTo({
url: '/pages/login/login?shareCode=' + this.options.shareCode,
url: '/pages/login/login?shareCode=' + that.options.shareCode,
})
} else {
wx.navigateTo({
......@@ -93,8 +95,8 @@ Page({
})
}
} else {
if (this.options.shareCode) {
this.boundParentByShareCode(options.shareCode); // 绑定内容获取
if (that.options.shareCode) {
that.boundParentByShareCode(options.shareCode); // 绑定内容获取
}
}
}
......
......@@ -13,216 +13,9 @@ Page({
smsCode: null,
avatar: null,
popBox: 0, // 弹窗启动
inviteTemplate: ''
},
onImgOK(e) {
this.imagePath = e.detail.path;
this.setData({
image: this.imagePath
})
if (this.isSave) {
this.saveImage(this.imagePath);
}
console.log('imageok', this.data.image)
},
template() {
return {
"width": "200px",
"height": "320px",
"background": "#f8f8f8",
"views": [
{
"type": "rect",
"css": {
"background": "#DF001B",
"width": "200px",
"height": "40px",
"top": "0px",
"left": "0px",
"rotate": "0",
"borderRadius": "",
"shadow": "",
"color": "#DF001B"
}
},
{
"type": "text",
"text": "车理狗",
"css": {
"color": "#fff",
"background": "",
"width": "200px",
"height": "22.88px",
"top": "4.999999999999998px",
"left": "0px",
"rotate": "0",
"borderRadius": "",
"borderWidth": "",
"borderColor": "#000000",
"shadow": "",
"padding": "0px",
"fontSize": "16px",
"fontWeight": "normal",
"maxLines": "2",
"lineHeight": "23.088000000000005px",
"textStyle": "fill",
"textDecoration": "none",
"fontFamily": "",
"textAlign": "center"
}
},
{
"type": "rect",
"css": {
"background": "#fff",
"width": "200px",
"height": "80px",
"top": "27px",
"left": "0px",
"rotate": "0",
"borderRadius": "10px",
"shadow": "",
"color": "#fff"
}
},
{
"type": "text",
"text": "稀世宅品 欧儿童房灯LED灯卧室灯房间灯具灯饰男孩女孩稀世宅 北欧儿童房灯LED灯卧室灯房间灯具灯饰男孩女孩",
"css": {
"color": "#333",
"background": "#fff",
"width": "180px",
"height": "34.788000000000004px",
"top": "36px",
"left": "10px",
"rotate": "0",
"borderRadius": "",
"borderWidth": "",
"borderColor": "#000000",
"shadow": "",
"padding": "0px",
"fontSize": "12px",
"fontWeight": "normal",
"maxLines": "2",
"lineHeight": "17.316000000000003px",
"textStyle": "fill",
"textDecoration": "none",
"fontFamily": "",
"textAlign": "left"
}
},
{
"type": "text",
"text": "¥259.00",
"css": {
"color": "#DF001B",
"background": "",
"width": "100px",
"height": "22.88px",
"top": "70px",
"left": "7px",
"rotate": "0",
"borderRadius": "",
"borderWidth": "",
"borderColor": "#000000",
"shadow": "",
"padding": "0px",
"fontSize": "16px",
"fontWeight": "normal",
"maxLines": "2",
"lineHeight": "23.088000000000005px",
"textStyle": "fill",
"textDecoration": "none",
"fontFamily": "",
"textAlign": "c"
}
},
{
"type": "image",
"url": "/images/banner@2x.png",
"css": {
"width": "200px",
"height": "150px",
"top": "93px",
"left": "0px",
"rotate": "0",
"borderRadius": "",
"borderWidth": "",
"borderColor": "#000000",
"shadow": "",
"mode": "aspectFill"
}
},
// {
// "type": "qrcode",
// "content": "哈哈哈",
// "css": {
// "color": "#000000",
// "background": "#ffffff",
// "width": "50px",
// "height": "50px",
// "top": "254px",
// "left": "33px",
// "rotate": "0",
// "borderRadius": ""
// }
// },
{
"type": "text",
"text": "卡车行小程序",
"css": {
"color": "#333",
"background": "",
"width": "100px",
"height": "17.16px",
"top": "262px",
"left": "89px",
"rotate": "0",
"borderRadius": "",
"borderWidth": "",
"borderColor": "#000000",
"shadow": "",
"padding": "0px",
"fontSize": "12px",
"fontWeight": "bold",
"maxLines": "2",
"lineHeight": "17.316000000000003px",
"textStyle": "fill",
"textDecoration": "none",
"fontFamily": "",
"textAlign": "c"
}
},
{
"type": "text",
"text": "长按识别 去逛逛",
"css": {
"color": "#999",
"background": "",
"width": "100px",
"height": "11.44px",
"top": "281.02px",
"left": "92px",
"rotate": "0",
"borderRadius": "",
"borderWidth": "",
"borderColor": "#000000",
"shadow": "",
"padding": "0px",
"fontSize": "8px",
"fontWeight": "bold",
"maxLines": "2",
"lineHeight": "11.544000000000002px",
"textStyle": "fill",
"textDecoration": "none",
"fontFamily": "",
"textAlign": ""
}
}
]
}
},
// 用户信息
getUserInfo() {
var params = {
......@@ -233,48 +26,83 @@ Page({
console.log('用户信息', res.result)
this.setData({
userInfo: res.result,
}, function () {
this.getMiniAppQrcode()
});
})
this.getMiniAppQrcode()
},
errCallBack: (err) => {
wx.showToast({
title: '用户信息获取失败',
})
}
};
http.request(params);
},
// 二维码
getMiniAppQrcode() {
var that = this
var params = {
url: "/wechatCommon/getMiniAppQrcode",
method: "GET",
data: {},
callBack: (res) => {
let img = 'data:image/png;base64,' + res.result
this.send_code(img)
// console.log('二维码', img)
that.send_code(img)
}
};
http.request(params);
},
//将base64图片转网络图片
send_code: function (base64data) {
const fsm = wx.getFileSystemManager();
const FILE_BASE_NAME = 'tmp_base64src';
const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || [];
if (!format) {
console.log(new Error('ERROR_BASE64SRC_PARSE'));
send_code(code) {
/*code是指图片base64格式数据*/
//声明文件系统
const fs = wx.getFileSystemManager();
//随机定义路径名称
var times = new Date().getTime();
var codeimg = wx.env.USER_DATA_PATH + '/' + times + '.png';
//将base64图片写入
fs.writeFile({
filePath: codeimg,
data: code.slice(22),
encoding: 'base64',
success: () => {
this.setData({
code: codeimg
})
//写入成功了的话,新的图片路径就能用了
this.drawImage()
}
const filePath = `${wx.env.USER_DATA_PATH}/${FILE_BASE_NAME}.${format}`;
const buffer = wx.base64ToArrayBuffer(bodyData);
fsm.writeFile({
filePath,
data: buffer,
encoding: 'binary',
success() {
console.log("path",filePath)
},
fail() {
reject(new Error('ERROR_BASE64SRC_WRITE'));
},
});
});
},
sendCode() {
const fsm = wx.getFileSystemManager();
const FILE_BASE_NAME = 'tmp_base64src';
const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(img) || [];
if (!format) {
reject(new Error('ERROR_BASE64SRC_PARSE'));
}
const filePath = `${wx.env.USER_DATA_PATH}/${FILE_BASE_NAME}.${format}`;
const buffer = wx.base64ToArrayBuffer(bodyData);
console.log('执行')
fsm.writeFile({
filePath,
data: buffer,
encoding: 'binary',
success() {
console.log('filePath', filePath)
that.setData({
code: filePath
})
that.drawImage()
},
fail() {
console.log('图片转换失败')
reject(new Error('ERROR_BASE64SRC_WRITE'));
},
complete() {
console.log('无论图片转换失败')
}
})
console.log('二维码', res)
},
// 保存图片
saveImage(imagePath = '') {
......@@ -306,21 +134,7 @@ Page({
});
}
},
// 获取小程序图片
getInvite: function () {
var that = this
return new Promise(resolve => {
api.getInvite({}, {
suc: function (res) {
console.log('小程序吗', res)
that.setData({
smsCode: res.data.data
})
return resolve();
}
})
});
},
// 保存图片
save: function () {
let that = this;
......@@ -389,6 +203,7 @@ Page({
},
// 绘制图片
drawImage: function () {
console.log("获取到的数据", this.data.code, this.data.userInfo)
// 绘制图片
var that = this
wx.showLoading({
......@@ -455,25 +270,25 @@ Page({
context.setFillStyle('#E5E5E5')
context.fillText("邀请您使用【中厦全供】", myCanvasWidth / 2, myCanvasHeight / 2.9);
console.log('二维码', that.data.code)
// wx.getImageInfo({
// src: that.data.code,
// success: function (res) {
// console.log('图片', res)
// var smsCode = res.path;
// context.save();
// context.beginPath();
// //先画个圆 前两个参数确定了圆心 (x,y) 坐标 第三个参数是圆的半径 四参数是绘图方向 默认是false,即顺时针
// context.arc(avatarur2_width / 2 + avatarur2_x, avatarur2_heigth / 2 + avatarur2_y, avatarur2_width / 2, 0, Math.PI * 2, false);
// context.clip();
// context.drawImage(smsCode, avatarur2_x, avatarur2_y, avatarur2_width, avatarur2_heigth);
// // 必须是https图片
// context.restore();
// context.draw(true);
// },
// fail: function (err) {
// console.log('失败', err)
// }
// })
wx.getImageInfo({
src: that.data.code,
success: function (res) {
console.log('图片', res)
var smsCode = res.path;
context.save();
context.beginPath();
//先画个圆 前两个参数确定了圆心 (x,y) 坐标 第三个参数是圆的半径 四参数是绘图方向 默认是false,即顺时针
context.arc(avatarur2_width / 2 + avatarur2_x, avatarur2_heigth / 2 + avatarur2_y, avatarur2_width / 2, 0, Math.PI * 2, false);
context.clip();
context.drawImage(smsCode, avatarur2_x, avatarur2_y, avatarur2_width, avatarur2_heigth);
// 必须是https图片
context.restore();
context.draw(true);
},
fail: function (err) {
console.log('失败', err)
}
})
//定时器作用同上
setTimeout(function () {
wx.hideLoading();
......@@ -488,10 +303,7 @@ Page({
*/
onLoad: function (options) {
this.getUserInfo()
this.setData({
inviteTemplate: this.template()
})
console.log('inviteTemplate', this.data.inviteTemplate)
},
/**
* 生命周期函数--监听页面初次渲染完成
......
{
"usingComponents": {
"painter": "/components/painter/painter"
},
"usingComponents": {},
"navigationBarTitleText": "邀请海报",
"navigationBarBackgroundColor": "#000000",
"navigationBarTextStyle": "white"
......
var domain = "http://192.168.31.110:8086/capi"; //统一接口域名,测试环境
var domain = "http://192.168.31.113:8086/capi"; //统一接口域名,测试环境
exports.domain = domain;
......@@ -91,7 +91,7 @@ var getToken = function () {
wx.setStorageSync('token', '');
} else {
wx.setStorageSync('token', 'bearer' + result.access_token); //把token存入缓存,请求接口数据时要用
this.getUserInfo()
getUserInfo()
}
var globalData = getApp().globalData;
globalData.isLanding = false;
......@@ -112,10 +112,11 @@ function getUserInfo() {
data: {},
callBack: (res) => {
console.log('用户信息', res.result)
var app = getApp();
app.globalData.userInfo = res.result
}
};
http.request(params);
request(params);
}
// 更新用户头像昵称
function updateUserInfo() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment