Commit 2f7067dd Harvey

代码优化

1 个父辈 c49c2ec4
//const baseUrl = 'https://app.ydniu.com/graphql' //const baseUrl = 'https://app.ydniu.com/graphql'
const baseUrl = '/test_graphql' //const baseUrl = '/test_graphql'
//const baseUrl = '/graphql' const baseUrl = '/graphql'
function request(options = {}) { function request(options = {}) {
...@@ -35,15 +35,13 @@ function post(options = {}) { ...@@ -35,15 +35,13 @@ function post(options = {}) {
} }
async function graphql(options = {}) { async function graphql(options = {}) {
let header = {} let header = {}
try {
if (Android) { //#ifdef H5
header["ydn-cookie"] = `connect.sid=${JSON.parse(Android.getSystemInfo())['Cookie']['connect.sid']}` if (window.Android) {
} header["ydn-cookie"] = `connect.sid=${JSON.parse(window.Android.getSystemInfo())['Cookie']['connect.sid']}`
} catch (e) {
console.log(e.message)
} }
//#endif
let opts = Object.assign({ let opts = Object.assign({
type: 'query' type: 'query'
...@@ -74,13 +72,18 @@ async function graphql(options = {}) { ...@@ -74,13 +72,18 @@ async function graphql(options = {}) {
res = res.data.data[opts.name] res = res.data.data[opts.name]
if (res.Error == '未登录') { if (res.Error == '未登录') {
try {
if (Android) window.location.href = 'ydncp://www.ydniu.com?type=7' //#ifdef H5
} catch (e) { if (window.Android) {
uni.redirectTo({ window.location.href = 'ydncp://www.ydniu.com?type=7'
url: `/login?from=${encodeURIComponent(getCurrentPages()[0].__page__.fullPath)}` return
})
} }
//#endif
uni.redirectTo({
url: `/login?from=${encodeURIComponent(getCurrentPages()[0].__page__.fullPath)}`
})
return return
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<image mode="widthFix" :src="src"></image> <image mode="widthFix" :src="src"></image>
</view> </view>
<view class="page-tabbar"> <view class="page-tabbar">
<view class="page-tabbar-tip red" @click="save">保存海报去分享</view> <view class="page-tabbar-tip" @click="save">保存海报去分享</view>
</view> </view>
</view> </view>
</template> </template>
...@@ -20,14 +20,7 @@ ...@@ -20,14 +20,7 @@
methods: { methods: {
save() { save() {
//#ifdef H5 //#ifdef H5
try { require('@/static/js/h5-utils.js').downloadIamge(this.src)
if (Android) {
Android.save2Album(this.src)
}
} catch (e) {
const $h5 = require('@/static/js/h5-utils.js')
$h5.downloadIamge(this.src)
}
//#endif //#endif
} }
} }
...@@ -35,16 +28,16 @@ ...@@ -35,16 +28,16 @@
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.page-content {} .page-content {}
.page-content image { .page-content image {
width: 90%; width: 90%;
margin: 10px 5%; margin: 10px 5%;
} }
.page-tabbar { .page-tabbar {
display: flex; display: flex;
position: fixed; position: fixed;
max-width: $sys-max-width; max-width: $sys-max-width;
bottom: 0; bottom: 0;
width: 100%; width: 100%;
......
...@@ -40,13 +40,9 @@ ...@@ -40,13 +40,9 @@
} }
//#ifdef H5 //#ifdef H5
try { if (window.Android) {
if (Android) { const $h5 = require('@/static/js/h5-utils.js')
const $h5 = require('@/static/js/h5-utils.js') $h5.head_tv(this.src)
$h5.head_tv(this.src)
}
} catch (e) {
} }
//#endif //#endif
}, },
...@@ -67,14 +63,7 @@ ...@@ -67,14 +63,7 @@
}, },
save() { save() {
//#ifdef H5 //#ifdef H5
try { require('@/static/js/h5-utils.js').downloadIamge(this.src)
if (Android) {
Android.save2Album(this.src)
}
} catch (e) {
const $h5 = require('@/static/js/h5-utils.js')
$h5.downloadIamge(this.src)
}
//#endif //#endif
} }
} }
...@@ -94,8 +83,8 @@ ...@@ -94,8 +83,8 @@
position: fixed; position: fixed;
bottom: 0; bottom: 0;
width: 100%; width: 100%;
max-width: $sys-max-width; max-width: $sys-max-width;
height: 44px; height: 44px;
background-color: #F8F8F8; background-color: #F8F8F8;
justify-content: space-around; justify-content: space-around;
...@@ -119,7 +108,7 @@ ...@@ -119,7 +108,7 @@
} }
.popup-content { .popup-content {
width: 80vw; width: 80vw;
max-width: 520px; max-width: 520px;
padding: 20px 20px 38px 20px; padding: 20px 20px 38px 20px;
background-color: #FFFFFF; background-color: #FFFFFF;
......
...@@ -60,12 +60,10 @@ ...@@ -60,12 +60,10 @@
}, },
async onLoad() { async onLoad() {
//#ifdef H5 //#ifdef H5
try { if (window.Android) {
if (Android) { const $h5 = require('@/static/js/h5-utils.js')
const $h5 = require('@/static/js/h5-utils.js') $h5.remove_uni_page_head()
$h5.remove_uni_page_head() }
}
} catch (e) {}
//#endif //#endif
this.bindData() this.bindData()
}, },
......
...@@ -24,26 +24,39 @@ export function head_tv(url) { ...@@ -24,26 +24,39 @@ export function head_tv(url) {
}); });
} }
export function downloadIamge(imgsrc){
const image = new Image()
// 允许资源跨域使用
image.setAttribute('crossOrigin', 'anonymous')
image.src = imgsrc
image.onload = () => {
// 利用canvas将图片转换为base64编码
const canvas = document.createElement('canvas')
canvas.width = image.width
canvas.height = image.height
const context = canvas.getContext('2d')
context?.drawImage(image, 0, 0, image.width, image.height)
// 将canvas对象转换为base64位编码
const url = canvas.toDataURL('image/png')
// 点击触发下载
const a = document.createElement('a')
const event = new MouseEvent('click')
a.download = imgsrc.replace(/(.*\/)*([^.]+.*)/ig, "$2").split("?")[0] || 'Certificate'
a.href = url
a.dispatchEvent(event)
}
}
\ No newline at end of file \ No newline at end of file
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')
image.src = imgsrc
image.onload = () => {
// 利用canvas将图片转换为base64编码
const canvas = document.createElement('canvas')
canvas.width = image.width
canvas.height = image.height
const context = canvas.getContext('2d')
context?.drawImage(image, 0, 0, image.width, image.height)
// 将canvas对象转换为base64位编码
const url = canvas.toDataURL('image/png')
// 点击触发下载
const a = document.createElement('a')
const event = new MouseEvent('click')
a.download = imgsrc.replace(/(.*\/)*([^.]+.*)/ig, "$2").split("?")[0] || 'Certificate'
a.href = url
a.dispatchEvent(event)
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!