//index.js
const app = getApp()
const updateManager = wx.getUpdateManager()
var clipboardData = ""
var isusecliData = false
const db = wx.cloud.database()
Page({
data: {
avatarUrl: './user-unlogin.png',
userInfo: {},
logged: false,
takeSession: false,
requestResult: '',
imgTmp: [],
videoTmp: '',
inputTxt: '',
writePhotosAlbum: false,
postUrl: "",
sourceTempUrl: [],
fileIDs: [],
alreadyInDB: true,
dbids: [],
},
onLoad: function() {
wx.stopPullDownRefresh()
if (!wx.cloud) {
wx.redirectTo({
url: '../chooseLib/chooseLib',
})
return
}
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
console.log("检查更新:"+ res.hasUpdate)
if (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: 'UPDATE',
content: 'The new version is ready,do you want to installed?',
cancelText: 'NO',
confirmText: 'YES',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
updateManager.onUpdateFailed(function () {
// 新版本下载失败
wx.showModal({
title: 'UPDATE',
content: 'The new version download failed,please check the network and try again later!',
confirmText: 'YES',
showCancel: false,
success: function (res) {
}
})
})
})
}
})
wx.getSetting({
success: res => {
// 获取用户信息
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
// console.log("获取信息001")
wx.getUserInfo({
success: res => {
this.setData({
avatarUrl: res.userInfo.avatarUrl,
userInfo: res.userInfo,
logged: true
})
}
})
}else{
logged: false
}
//获取相册权限
this.setData({
writePhotosAlbum: res.authSetting['scope.writePhotosAlbum']
})
}
})
// 获取剪贴板内容
var that = this
wx.getClipboardData({
success(res) {
clipboardData = res.data
if (clipboardData != null && clipboardData != "" && clipboardData != undefined) {
var re = new RegExp("(https ?| ftp | file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]", 'g');
var redlurl = re.exec(clipboardData);
if(redlurl != null){
redlurl = redlurl[0]
var str = "oasis.weibo.cn"
if(redlurl.indexOf(str) != -1){
wx.showModal({
title: 'Tips',
content: 'Do you want to use the clipboard contents directly?\n' + clipboardData,
cancelText: 'NO',
confirmText: 'YES',
success(res) {
if (res.confirm) {
isusecliData = true
that.dlsubmit()
}
}
})
}
}
}
}
})
},
// 下拉刷新
onPullDownRefresh: function(){
this.setData({
imgTmp: [],
videoTmp: '',
inputTxt: ''
})
this.onLoad()
},
// 点击输入框时清除输入框
cleanInput: function(){
var that = this
that.setData({
inputTxt: ''
})
},
onGetUserInfo: function(e) {
// console.log("获取信息")
if (!this.data.logged && e.detail.userInfo) {
this.setData({
logged: true,
avatarUrl: e.detail.userInfo.avatarUrl,
userInfo: e.detail.userInfo
})
}
},
// 获取资源
dlsubmit: function(e){
var mythis=this;
mythis.setData({
imgTmp: [],
videoTmp: '',
})
var dlurl = "";
if(isusecliData){
dlurl = clipboardData
isusecliData = false
}else{
dlurl = e.detail.value.dlurl;
}
console.log("输入链接:" + dlurl);
var re = new RegExp("(https ?| ftp | file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]", 'g');
var redlurl = re.exec(dlurl);
console.log(redlurl);
if (redlurl != null){
redlurl = redlurl[0];
var str = "oasis.weibo.cn";
if(redlurl.indexOf(str) != -1){
console.log("获取链接:" + redlurl);
mythis.setData({
postUrl: redlurl
})
// mythis.getFromDB()
wx.showLoading({
title: 'downloading...',
})
setTimeout(function () {
wx.hideLoading()
}, 2000)
wx.request({
url: redlurl,
header: { 'content-type': 'application/x-www-form-urlencoded' },
success(res) {
console.log(res);
if (res.statusCode == 200) {
var data = res.data;
console.log(data);
wx.cloud.callFunction({
name: 'utils',
data: {
data: data,
action: 'parseHTML'
},
success: function (res) {
// 得到img/video地址
var sourceurl = res.result
console.log("云函数调用结果:" + sourceurl)
if (sourceurl.length === 1) {
if (sourceurl[0].indexOf("https://wx") === -1 && sourceurl[0].indexOf("https://lz.sinaimg.cn") === -1) {
// 视频
mythis.downloadAndSaveVideo(sourceurl[0])
} else {
// 下载并保存---图片
mythis.downloadAndSaveImg(sourceurl)
}
} else {
// 下载并保存---图片
mythis.downloadAndSaveImg(sourceurl)
}
},
fail: function (e) {
console.log("云函数调用错误:" + e)
wx.showModal({
title: 'Download Failed',
content: 'Please try again later~',
showCancel: false,
confirmText: 'YES',
success(res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
})
}
})
}
},
fail(e) {
wx.showModal({
title: 'Download Failed',
content: 'Please try again later~',
showCancel: false,
confirmText: 'YES',
success(res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
})
}
})
}else{
wx.showModal({
title: 'Tips',
content: 'Please enter the correct url!(only support oasis)',
showCancel: false,
confirmText: 'YES',
success(res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
})
}
}else{
wx.showModal({
title: 'Tips',
content: 'Please enter the correct url!(only support oasis)',
showCancel: false,
confirmText: 'YES',
success(res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
})
}
},
checkWriteAlbum: function(){
if (!this.data.writePhotosAlbum) {// 未授权相册
wx.authorize({
scope: 'scope.write
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
oasisimgdl-master.7z (27个子文件)
project.config.json 1KB
miniprogram
sitemap.json 77B
pages
index
index.wxml 2KB
user-unlogin.png 5KB
index.js 17KB
index.json 27B
index.wxss 3KB
jc
jc.wxml 810B
jc.json 27B
jc.js 2KB
jc.wxss 652B
app.json 818B
app.js 601B
app.wxss 2KB
images
android48.png 728B
jc.png 2KB
home.png 1KB
jc-d.png 2KB
home-d.png 1KB
iOS48.png 915B
cloudfunctions
utils
package.json 286B
package-lock.json 35KB
index.js 1009B
openapi
package.json 258B
config.json 313B
index.js 2KB
.gitignore 145B
共 27 条
- 1
资源评论
riiyn
- 粉丝: 4
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功