3 Commits

7 changed files with 90 additions and 71 deletions
Unified View
  1. +10
    -0
      App.vue
  2. +39
    -0
      index.html
  3. +3
    -2
      manifest.json
  4. +1
    -1
      pages.json
  5. +35
    -68
      pages/index/index.vue
  6. +1
    -0
      static/js/uni.webview.1.5.6.js
  7. +1
    -0
      uni.webview.1.5.6.js

+ 10
- 0
App.vue View File

@ -1,6 +1,16 @@
<script> <script>
export default { export default {
onLaunch: function() { onLaunch: function() {
document.addEventListener('UniAppJSBridgeReady', function() {
uni.webView.getEnv(function(res) {
console.log('当前环境:' + JSON.stringify(res));
});
});
/* 动态引入script */
const script = document.createElement('script')
script.src = '/static/js/uni.webview.1.5.6.js'
document.body.appendChild(script)
}, },
onShow: function() { onShow: function() {
this.$store.commit('initConfig') this.$store.commit('initConfig')


+ 39
- 0
index.html View File

@ -16,5 +16,44 @@
<body> <body>
<div id="app"><!--app-html--></div> <div id="app"><!--app-html--></div>
<script type="module" src="/main.js"></script> <script type="module" src="/main.js"></script>
<script type="text/javascript">
var userAgent = navigator.userAgent;
if (userAgent.indexOf('AlipayClient') > -1) {
// 支付宝小程序的 JS-SDK 防止 404 需要动态加载,如果不需要兼容支付宝小程序,则无需引用此 JS 文件。
document.writeln('<script src="https://appx/web-view.min.js"' + '>' + '<' + '/' + 'script>');
} else if (/QQ/i.test(userAgent) && /miniProgram/i.test(userAgent)) {
// QQ 小程序
document.write(
'<script type="text/javascript" src="https://qqq.gtimg.cn/miniprogram/webview_jssdk/qqjssdk-1.0.0.js"><\/script>'
);
} else if (/miniProgram/i.test(userAgent) && /micromessenger/i.test(userAgent)) {
// 微信小程序 JS-SDK 如果不需要兼容微信小程序,则无需引用此 JS 文件。
document.write('<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"><\/script>');
} else if (/toutiaomicroapp/i.test(userAgent)) {
// 头条小程序 JS-SDK 如果不需要兼容头条小程序,则无需引用此 JS 文件。
document.write(
'<script type="text/javascript" src="https://lf1-cdn-tos.bytegoofy.com/goofy/developer/jssdk/jssdk-1.2.0.js"><\/script>');
} else if (/swan/i.test(userAgent)) {
// 百度小程序 JS-SDK 如果不需要兼容百度小程序,则无需引用此 JS 文件。
document.write(
'<script type="text/javascript" src="https://b.bdstatic.com/searchbox/icms/searchbox/js/swan-2.0.18.js"><\/script>'
);
} else if (/quickapp/i.test(userAgent)) {
// quickapp
document.write('<script type="text/javascript" src="https://quickapp/jssdk.webview.min.js"><\/script>');
}
</script>
<!-- uni 的 SDK -->
<!-- 需要把 uni.webview.1.5.6.js 下载到自己的服务器 -->
<!-- <script src="https://gitcode.net/dcloud/uni-app/-/raw/dev/dist/uni.webview.1.5.6.js"></script> -->
<script src="./uni.webview.1.5.6.js"></script>
<script>
document.addEventListener('UniAppJSBridgeReady', function() {
uni.webView.getEnv(function(res) {
console.log('当前环境:' + JSON.stringify(res));
});
// uni.webView.navigateTo(...)
});
</script>
</body> </body>
</html> </html>

+ 3
- 2
manifest.json View File

@ -89,7 +89,7 @@
} }
}, },
"devServer" : { "devServer" : {
"https" : false,
"https" : true,
"proxy" : { "proxy" : {
"/ws/geocoder/v1/" : { "/ws/geocoder/v1/" : {
"target" : "https://apis.map.qq.com", "target" : "https://apis.map.qq.com",
@ -100,6 +100,7 @@
"changeOrigin" : true "changeOrigin" : true
} }
} }
}
},
"title" : "行后报告"
} }
} }

+ 1
- 1
pages.json View File

@ -11,7 +11,7 @@
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",
"navigationBarTitleText": "行后报告", "navigationBarTitleText": "行后报告",
"navigationBarBackgroundColor": "#F8F8F8",
"navigationBarBackgroundColor": "#DAF3FF",
"backgroundColor": "#F8F8F8", "backgroundColor": "#F8F8F8",
"navigationStyle": "custom" "navigationStyle": "custom"
}, },


+ 35
- 68
pages/index/index.vue View File

@ -146,9 +146,7 @@
<img v-if="current < 15" class="img turn right" src="@/static/image/icon-right.png" @click="next" /> <img v-if="current < 15" class="img turn right" src="@/static/image/icon-right.png" @click="next" />
<div class="flex bottom"> <div class="flex bottom">
<div class="flex btns">
<button class="btn" @click="createPdf">生成pdf</button>
</div>
<button class="btn" @click="createPdf">生成pdf</button>
</div> </div>
</div> </div>
@ -197,8 +195,16 @@
next() { next() {
this.current += 1 this.current += 1
}, },
createPdf() {
async upload(pdfBlob) {
const pdfUrl = URL.createObjectURL(pdfBlob);
const url = await this.$Oss.ossUpload(pdfUrl)
console.log('ossUpload', url)
return url
},
createPdf() {
uni.showLoading({ uni.showLoading({
title: '生成中...' title: '生成中...'
}) })
@ -239,57 +245,19 @@
fillPage() fillPage()
} }
const canvas = item.value const canvas = item.value
const contentWidth = canvas.width
const contentHeight = canvas.height
// let imgHeight = (WIDTH / contentWidth) * contentHeight // a4
let pageData = canvas.toDataURL('image/jpeg', 1.0) let pageData = canvas.toDataURL('image/jpeg', 1.0)
PDF.addImage(pageData, 'JPEG', 0, 0, WIDTH, HEIGHT) PDF.addImage(pageData, 'JPEG', 0, 0, WIDTH, HEIGHT)
return
//
let leftHeight = imgHeight
//
let position = 0
// a4
if (imgHeight > HEIGHT) {
while (leftHeight > 0) {
// xy
PDF.addImage(pageData, 'JPEG', 0, position, WIDTH, imgHeight)
leftHeight = leftHeight - HEIGHT
position -= HEIGHT
if (leftHeight > 0) {
PDF.addPage()
fillPage()
}
}
} else {
PDF.addImage(pageData, 'JPEG', 0, 0, WIDTH, imgHeight)
// const marginY = (HEIGHT - imgHeight) / 2 //
// // xy
// PDF.addImage(pageData, 'JPEG', 0, marginY > 0 ? marginY : 0, a4Width, imgHeight)
}
}) })
// #ifdef H5
PDF.save('测试生成pdf' + '.pdf'); //h5pdf
// #endif
return
uni.postMessage({
data: {
imageData: PDF.output("datauristring"),
}
// PDF Blob
const pdfBlob = PDF.output('blob');
return this.upload(pdfBlob)
}).then(url => {
this.$jWeixin.miniProgram.postMessage({
data: url
}); });
// uni.navigateBack()
uni.redirectTo({
url: `/pages_order/thesis/createPdf?id=${this.id}`
})
this.$jWeixin.miniProgram.navigateBack()
}).catch(err => { }).catch(err => {
console.log('err', err) console.log('err', err)
}).finally(() => { }).finally(() => {
@ -400,29 +368,28 @@
} }
.bottom { .bottom {
position: fixed;
left: 0;
bottom: 0;
width: 100vw;
height: 55px;
padding: 0 25px;
position: fixed;
left: 0;
bottom: 0;
width: 100vw;
background: #FFFFFF;
box-sizing: border-box;
padding: 32rpx 40rpx;
padding-bottom: calc(env(safe-area-inset-bottom) + 32rpx);
box-sizing: border-box; box-sizing: border-box;
background: #FFFFFF;
box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
.btns {
width: 100%;
// justify-content: space-between;
}
.btn { .btn {
padding: 10px 45px;
font-size: 14px;
width: 100%;
padding: 14rpx 0;
font-family: PingFang SC;
font-weight: 500;
font-size: 36rpx;
line-height: 1.4;
color: #FFFFFF; color: #FFFFFF;
background: #4883F9;
border-radius: 21px;
border: none;
background: linear-gradient(to right, #21FEEC, #019AF9);
border: 2rpx solid #00A9FF;
border-radius: 41rpx;
} }
}
}
</style> </style>

+ 1
- 0
static/js/uni.webview.1.5.6.js
File diff suppressed because it is too large
View File


+ 1
- 0
uni.webview.1.5.6.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save