| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <template>
- <view>
- <web-view :webview-styles="webviewStyles" :src="url" v-if="iOS"></web-view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- url: "",
- webviewStyles: {
- progress: {
- color: '#F07423'
- }
- },
- type: "",
- iOS: true
- };
- },
- onLoad(param) {
- this.type = param.type;
- let title = ""
- if (this.type == 1) {
- title = "用户使用协议"
- } else if (this.type == 2) {
- title = "隐私协议"
- } else if (this.type == 3) {
- title = "入驻协议"
- }
- uni.setNavigationBarTitle({
- title: title
- })
- this.webviewStyles.progress.color = getApp().globalData.color1;
- this.queryProtocolConfigView();
- },
- methods: {
- async queryProtocolConfigView() {
- let res = await this.$myRequest({
- url: "/project/queryProtocolConfigView",
- data: {},
- })
- if (res.data.success) {
- if (this.type = '1') { //使用协议
- this.url = res.data.single.userUseProtocol;
- } else if (this.type = '2') { //隐私协议
- this.url = res.data.single.userPrivacyProtocol;
- } else if (this.type = '3') { //业主注册协议
- this.url = res.data.single.ownerRegistProtocol;
- }
- let index = this.url.lastIndexOf('.');
- let ah = this.url.substring(index+1);
- if(ah.indexOf('pdf')>-1){ //是pdf
- this.loadpdf();
- }
-
- }
- },
- loadpdf() {
- uni.getSystemInfo({
- success: (res) => {
- console.log(res)
- if (res.system.includes('iOS')) {
- this.iOS = true;
- } else {
- this.iOS = false;
- // Android 需要下载后再打开
- uni.downloadFile({
- url: this.url,
- success: (res) => {
- const path = res.tempFilePath;
- uni.openDocument({
- filePath: path,
- fileType: 'pdf',
- success: (res) => {
- uni.navigateBack({
- delta: 1
- });
- },
- fail: (err) => {
- uni.showToast({
- title: '打开文件失败',
- icon: 'none',
- duration: 2000
- });
- }
- });
- },
- fail: (err) => {
- console.log(err);
- uni.showToast({
- title: '下载文件失败',
- icon: 'none',
- duration: 2000
- });
- }
- });
- }
- }
- });
- }
- }
- }
- </script>
- <style lang="scss">
- </style>
|