123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- // pages/share/share.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- codeImg: 'https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E4%BA%8C%E7%BB%B4%E7%A0%81&step_word=&hs=0&pn=0&spn=0&di=19620&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=undefined&cs=65199140%2C1406017826&os=695039919%2C3289081284&simid=0%2C0&adpicid=0&lpn=0&ln=1845&fr=&fmq=1607396518663_R&fm=&ic=undefined&s=undefined&hd=undefined&latest=undefined©right=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&ist=&jit=&cg=&bdtype=11&oriquery=&objurl=http%3A%2F%2Fremote.yunnan.cn%2Fqr%2Fphp%2Fqr.php%3Fd%3Dhttp%3A%2F%2Fnews.yunnan.cn%2Fsystem%2F2020%2F12%2F08%2F031165250.shtml&fromurl=ippr_z2C%24qAzdH3FAzdH3Fgjof_z%26e3By7ggwg_z%26e3BvgAzdH3Ffyfpj4AzdH3FdadaAzdH3F8dAzdH3FabAzdH3Fan88mcdca_z%26e3Bfip4s&gsm=1&rpstart=0&rpnum=0&islist=&querylist=&force=undefined'
- },
- save() {
- wx.getSetting({
- success: (res) => {
- console.log(res)
- if (!res.authSetting['scope.writePhotosAlbum']) {
- wx.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- console.log(res, "我点击同意啦")
- wx.showLoading({
- title: '保存中...'
- })
- let imgSrc = this.data.codeImg;
- wx.downloadFile({
- url: imgSrc,
- success: function (res) {
- console.log(res, '我下载完成啦');
- //图片保存到本地
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: function (data) {
- console.log(data, '我保存成功啦')
- wx.hideLoading();
- wx.showToast({
- title: '保存成功',
- icon: 'success',
- duration: 2000
- })
- },
- fail: function (err) {
- console.log(err, '我保存失败啦')
- wx.hideLoading();
- if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
- console.log("当初用户拒绝,再次发起授权")
- wx.openSetting({
- success(settingdata) {
- console.log(settingdata)
- if (settingdata.authSetting['scope.writePhotosAlbum']) {
- console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
- } else {
- console.log('获取权限失败,给出不给权限就无法正常使用的提示')
- }
- }
- })
- }
- },
- complete(res) {
- console.log(res);
- }
- })
- },
- complete(res) {
- wx.hideLoading()
- }
- })
- }
- })
- } else {
- wx.showLoading({
- title: '保存中...'
- })
- console.log(this.data.classInfo.codeImg)
- let imgSrc = this.data.classInfo.codeImg
- wx.downloadFile({
- url: imgSrc,
- success: function (res) {
- console.log(res, '我下载完成啦');
- wx.hideLoading();
- //图片保存到本地
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: function (data) {
- console.log(data, '我保存成功啦')
- wx.hideLoading();
- wx.showToast({
- title: '保存成功',
- icon: 'success',
- duration: 2000
- })
- },
- fail: function (err) {
- console.log(err, '我保存失败啦')
- wx.hideLoading();
- if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
- console.log("当初用户拒绝,再次发起授权")
- wx.openSetting({
- success(settingdata) {
- console.log(settingdata)
- if (settingdata.authSetting['scope.writePhotosAlbum']) {
- console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
- } else {
- console.log('获取权限失败,给出不给权限就无法正常使用的提示')
- }
- }
- })
- }
- },
- complete(res) {
- console.log(res);
- }
- })
- }
- })
- }
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|