Commit 2f7067dd Harvey

代码优化

1 个父辈 c49c2ec4
//const baseUrl = 'https://app.ydniu.com/graphql'
const baseUrl = '/test_graphql'
//const baseUrl = '/graphql'
//const baseUrl = '/test_graphql'
const baseUrl = '/graphql'
function request(options = {}) {
......@@ -35,15 +35,13 @@ function post(options = {}) {
}
async function graphql(options = {}) {
let header = {}
try {
if (Android) {
header["ydn-cookie"] = `connect.sid=${JSON.parse(Android.getSystemInfo())['Cookie']['connect.sid']}`
}
} catch (e) {
console.log(e.message)
//#ifdef H5
if (window.Android) {
header["ydn-cookie"] = `connect.sid=${JSON.parse(window.Android.getSystemInfo())['Cookie']['connect.sid']}`
}
//#endif
let opts = Object.assign({
type: 'query'
......@@ -74,13 +72,18 @@ async function graphql(options = {}) {
res = res.data.data[opts.name]
if (res.Error == '未登录') {
try {
if (Android) window.location.href = 'ydncp://www.ydniu.com?type=7'
} catch (e) {
//#ifdef H5
if (window.Android) {
window.location.href = 'ydncp://www.ydniu.com?type=7'
return
}
//#endif
uni.redirectTo({
url: `/login?from=${encodeURIComponent(getCurrentPages()[0].__page__.fullPath)}`
})
}
return
}
......
......@@ -4,7 +4,7 @@
<image mode="widthFix" :src="src"></image>
</view>
<view class="page-tabbar">
<view class="page-tabbar-tip red" @click="save">保存海报去分享</view>
<view class="page-tabbar-tip" @click="save">保存海报去分享</view>
</view>
</view>
</template>
......@@ -20,14 +20,7 @@
methods: {
save() {
//#ifdef H5
try {
if (Android) {
Android.save2Album(this.src)
}
} catch (e) {
const $h5 = require('@/static/js/h5-utils.js')
$h5.downloadIamge(this.src)
}
require('@/static/js/h5-utils.js').downloadIamge(this.src)
//#endif
}
}
......
......@@ -40,14 +40,10 @@
}
//#ifdef H5
try {
if (Android) {
if (window.Android) {
const $h5 = require('@/static/js/h5-utils.js')
$h5.head_tv(this.src)
}
} catch (e) {
}
//#endif
},
methods: {
......@@ -67,14 +63,7 @@
},
save() {
//#ifdef H5
try {
if (Android) {
Android.save2Album(this.src)
}
} catch (e) {
const $h5 = require('@/static/js/h5-utils.js')
$h5.downloadIamge(this.src)
}
require('@/static/js/h5-utils.js').downloadIamge(this.src)
//#endif
}
}
......
......@@ -60,12 +60,10 @@
},
async onLoad() {
//#ifdef H5
try {
if (Android) {
if (window.Android) {
const $h5 = require('@/static/js/h5-utils.js')
$h5.remove_uni_page_head()
}
} catch (e) {}
//#endif
this.bindData()
},
......
......@@ -24,7 +24,20 @@ export function head_tv(url) {
});
}
export function downloadIamge(imgsrc){
export function downloadIamge(imgsrc) {
if (window.Android) {
window.Android.save2Album(imgsrc)
return
}
if (window.WeixinJSBridge) {
uni.showToast({
title: '长按图片保存'
})
return
}
const image = new Image()
// 允许资源跨域使用
image.setAttribute('crossOrigin', 'anonymous')
......@@ -46,4 +59,4 @@ export function downloadIamge(imgsrc){
a.href = url
a.dispatchEvent(event)
}
}
\ No newline at end of file
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!