|
- const app = getApp()
- import request from '../../utils/request'
- import Dialog from '@vant/weapp/dialog/dialog';
- const { appId } = require("../../utils/request");
-
- // pages/checkImg/checkImg.ts
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- currentIndex: 0,
- id: "",
- swiperList: [],
- title: ""
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- console.log(options);
- this.setData({
- id: options.id
- })
- if (options.id == "example") {
- console.log(1);
- const arr = [
- { image: "https://formall.oss-accelerate.aliyuncs.com/smartcapi/2023-09-27/5263476f945343bbab20e007bfd32c4b.jpg?x-oss-process=image/resize,w_10000/quality,q_60" },
- { image: "https://formall.oss-accelerate.aliyuncs.com/smartcapi/2023-09-27/5263476f945343bbab20e007bfd32c4b.jpg?x-oss-process=image/resize,w_10000/quality,q_60" },
- { image: "https://formall.oss-accelerate.aliyuncs.com/smartcapi/2023-09-27/5263476f945343bbab20e007bfd32c4b.jpg?x-oss-process=image/resize,w_10000/quality,q_60" },
- { image: "https://formall.oss-accelerate.aliyuncs.com/smartcapi/2023-09-27/5263476f945343bbab20e007bfd32c4b.jpg?x-oss-process=image/resize,w_10000/quality,q_60" }
- ]
- this.setData({
- swiperList: arr,
- title: "示例"
- })
- return
- }
- app.tokenCallBack = token => {
- if (!token) {
- wx.redirectTo({
- url: '/pages/login/login',
- })
- } else {
- this.getImageDetail(options.id)
- }
- }
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- const isLogin = wx.getStorageSync('token')
- if (isLogin) {
- this.getImageDetail(this.data.id)
- }
- },
-
- getImageDetail(id) {
- const that = this
- console.log(id, 'id');
- request.get({
- url: `/api/digitalAvatarPhoto/findById?id=${id}`
- }).then(res => {
- console.log(res, 'getImageDetail');
- that.setData({
- swiperList: res.data.photoList,
- title: res.data.title,
- })
- }).catch(err => {
- console.log(err, 'err');
- })
-
- },
-
- switchImg(e) {
- const currentIndex = e.currentTarget.dataset.index
- this.setData({
- currentIndex
- })
- },
-
- previewImage() {
- const array = []
- this.data.swiperList.forEach(item => {
- array.push(item.image)
- })
- wx.previewImage({
- urls: array,
- showmenu: true,
-
- })
- },
-
- swiperChanged(e) {
- const currentIndex = e.detail.current
- this.setData({
- currentIndex
- })
- },
-
- downloadImage() {
- const isLogin = wx.getStorageSync('token')
- if (!isLogin) {
- wx.redirectTo({
- url: '/pages/login/login',
- })
- return
- }
-
- const index = this.data.currentIndex
- const list = this.data.swiperList
- const filePath = "zhixiangImg.png"
-
- const url = list[index].image
-
- wx.downloadFile({
- url,
- success: res => {
- console.log(res, 'res');
- if (res.statusCode === 200) {
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: () => {
- wx.showToast({
- title: '保存成功!',
- icon: "success"
- })
- }
- })
- }
-
- }
- })
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- }
- })
|