uniapp 开发微信小程序记录

推荐文章

1.pdf路径 判断文件是否存在

    //判断 是否本地有
    handlePdfHas(path) {
      const fs = wx.getFileSystemManager();
      const filePath = path; //文件路径
      try {
        const data = fs.readFileSync(filePath, "binary");
        // 文件存在,可以处理数据
        return true;
      } catch (e) {
        return false;
        // 文件不存在或读取失败
      }
    },

2.预览pfd文档,链接是正常urlPdf: https:// ***.pdf

//微信小程序预览文档,可预览.doc,.docx,.xls,.xlsx,.pdf等文件
			preview(urlPdf) {
				uni.showLoading({
					title: '正在加载中..'
				})
				uni.downloadFile({
					url: urlPdf,
					success: function(res) {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
								uni.hideLoading()
							},
						});
					},
					complete: function(r) {
						uni.hideLoading()
					}
				});
			},

 3.pdf是文档流的时候,先本地存储一个临时链接,然后openDocument 打开。

			getPDF(url) {
				const result = weekApi({
					journal_url: url
				}).then(res => {
					const arrayBuffer = res; // 接收到的PDF文档流(ArrayBuffer)  
					const filePath = wx.env.USER_DATA_PATH  +`/${new Date().getTime()}.pdf`; // 指定保存路径和文件名  

					// 获取文件系统管理器  
					const fs = wx.getFileSystemManager();

					// 使用writeFile方法将Buffer对象写入文件  
					fs.writeFile({
						filePath: filePath, // 文件的路径  
						data: arrayBuffer, // 要写入文件的数据  
						
						encoding: 'binary', // 文件的编码方式,这里使用二进制编码  
						success: function(result) {
							console.log('文件保存成功', result);
							// 文件保存成功后,可以进行后续操作,如打开文件等  

							wx.openDocument({
								filePath: filePath,
								fileType: 'pdf',
								success: function(res) {
							 	console.log('打开文档成功');
								}
							});
						},
						fail: function(error) {
							console.error('文件保存失败', error);
						}
					});
				});
			}

4.webview 打开连接,需要在小程序设置>开发管理配置

5.触底,下拉,置顶 

下拉需要在pages.json 配置;

  //触底函数
  onReachBottom() {
    console.log("触底");
  },
  //下拉函数
  onPullDownRefresh() {
    // 来停止下拉刷新的动画效果
    uni.stopPullDownRefresh();
  },

  //置顶方法
  uni.pageScrollTo({
      scrollTop: 0,
      duration: 300,
      animation: true, // 是否使用动画过渡
  });

6.跳转tabbar 

      uni.switchTab({
        url: "/pages/*",
      });

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值