uni-app 开发 App 、 H5 横屏签名(基于lime-signature)

news/2025/2/26 6:12:09

所用插件:lime-signature

在这里插入图片描述

使用到 CSS 特性

  1. 绝对定位
  2. transform 旋转
  3. transform-origin transform 原点

复习一下定位元素(相对定位、绝对定位、粘性定位)

在这里插入图片描述

代码#

<template>
  <view class="signature-page">
    <view class="operate-box">
      <button @click="handleSignatureClick('back')">
        {{ $t("common.back") }}
      </button>
      <button @click="handleSignatureClick('clear')">
        {{ $t("maintenance.signatureBtns[0]") }}
      </button>
      <button @click="handleSignatureClick('undo')">
        {{ $t("maintenance.signatureBtns[1]") }}
      </button>
      <button @click="handleSignatureClick('save')">
        {{ $t("maintenance.signatureBtns[2]") }}
      </button>
    </view>
    <view class="canvas-box">
      <l-signature
        disableScroll
        backgroundColor="#fff"
        ref="signatureRef"
        :penColor="penColor"
        :penSize="penSize"
        :openSmooth="openSmooth"
        :landscape="IsLandscape"
      ></l-signature>
    </view>
  </view>
</template>

<script>
/**
 * 签名-横屏
 * @author demon3443002624@outlook.com
 * @version 1.0.0
 */
import { dataURLtoFile, changeUrl } from "@/common/utils.js";
const UPLOAD_FILE_URL_MAINTENANCE5 =
  changeUrl("/Lease/UploadLeaseMaintenanceNewV2File") + "?type=5";
export default {
  data() {
    return {
      type: null,
      penColor: "#000",
      penSize: 5,
      openSmooth: true,
      IsLandscape: false,
    };
  },
  onLoad(params) {
    const _this = this;
    const eventChannel = this.getOpenerEventChannel();
    // 监听acceptData事件,获取上一页通过eventChannel传送到当前页面的数据
    eventChannel.on("acceptData", function (data) {
      _this.type = data.type;
    });
    // 横屏签名
    this.IsLandscape = true;

    // #ifdef APP-PLUS
    // this.IsLandscape = true
    // plus.screen.lockOrientation('landscape-primary') // App 屏幕旋转
    // #endif
  },
  onUnload() {
    // #ifdef APP-PLUS
    // plus.screen.lockOrientation('portrait-primary') // App 屏幕旋转
    // #endif
  },
  methods: {
    handleSignatureClick(type) {
      if (type == "back") {
        uni.navigateBack();
        return;
      }
      if (type == "openSmooth") {
        this.openSmooth = !this.openSmooth;
        return;
      }
      const signatureRefStr = "signatureRef";
      if (type == "save") {
        this.$refs[signatureRefStr].canvasToTempFilePath({
          success: (res) => {
            // App 生成的图片路径, H5 生成的base64 处理方式不同
            const commonHandler = (resultInner) => {
              if (resultInner.statusCode === 200) {
                const responseDataJson = resultInner.data;
                if (responseDataJson) {
                  const responseData = JSON.parse(responseDataJson);
                  const eventChannel = this.getOpenerEventChannel();
                  // 向上一页通过事件传递数据
                  eventChannel.emit("editData", {
                    type: this.type,
                    url: responseData.Data,
                  });
                  uni.navigateBack();
                }
              }
            };

            // #ifdef H5
            uni.uploadFile({
              url: UPLOAD_FILE_URL_MAINTENANCE5,
              file: dataURLtoFile(res.tempFilePath, "file.png"), // ** 没有文件名,后台出错
              name: "file",
              success: (result) => {
                commonHandler(result);
              },
              fail: (err) => {},
            });
            // #endif
            // #ifdef APP
            uni.uploadFile({
              url: UPLOAD_FILE_URL_MAINTENANCE5,
              filePath: res.tempFilePath,
              name: "file",
              success: (result) => {
                commonHandler(result);
              },
              fail: (err) => {},
            });
            // #endif
          },
        });
        return;
      }
      if (this.$refs[signatureRefStr]) this.$refs[signatureRefStr][type]();
    },
  },
};
</script>

<style lang="scss">
$operate-btn-width: 100rpx;
.signature-page {
  margin-top: var(--status-bar-height);
  height: calc(
    100vh - var(--window-top) - var(--status-bar-height) - var(--window-bottom)
  );
  width: 100%;
  position: relative;
  .canvas-box {
    height: 100%;
    margin-left: $operate-btn-width;
  }

  .operate-box {
    position: absolute;
    display: flex;
    transform: rotate(90deg);
    transform-origin: top left;
    height: $operate-btn-width;
    width: calc(
      100vh - var(--window-top) - var(--status-bar-height) -
        var(--window-bottom)
    );
    top: 0;
    left: $operate-btn-width;
    z-index: 1;
    uni-button {
      flex: 1;
      margin: 5rpx 10rpx;
    }
  }
}
</style>

结果

在这里插入图片描述
在这里插入图片描述


http://www.niftyadmin.cn/n/5868156.html

相关文章

Java多线程中的死锁问题

1.什么是死锁 线程在获取资源的时候&#xff0c;由于获取不到&#xff0c;导致线程卡死&#xff08;阻塞&#xff09;&#xff0c;程序就不执行了。 2.发生死锁的情况 1.一个线程获取一把锁 一个线程如果同时获取一把锁两次&#xff0c;如果是可重入锁&#xff0c;就没有问…

Maven 从下载到实战,xml帮助文档

一、Maven 免费下载 1. 官方下载地址 官网推荐&#xff1a;访问 Maven 官网&#xff0c;选择最新稳定版本&#xff08;如 3.8.1 或 3.6.3&#xff09;的 bin.zip 文件179。 国内镜像&#xff1a;若官网下载缓慢&#xff0c;可使用以下网盘资源&#xff08;注意版权风险&#…

Mac 上安装多版本的 JDK 且实现 自由切换

1.可以通过查看以下目录中的内容&#xff0c;确认当前已经安装的 jdk 版本。 cd /Library/Java/JavaVirtualMachines2.命令行查看 jdk 的安装路径 /usr/libexec/java_home -V3.下载要安装的jdk版本&#xff0c;修改环境变量( cat ~/.bash_profile) # 定义JDK 8和JDK 17的安装路…

Ajax数据采集与分析详解

文章目录 1. 什么是 Ajax&#xff1f;2. Ajax 的工作原理3. Ajax 在网页中的应用场景4. 爬取 Ajax 数据的方法4.1 分析网络请求4.2 模拟 Ajax 请求4.3 使用 Selenium 模拟浏览器4.4 使用 Headless 浏览器 5. 处理动态参数6. 处理分页和滚动加载7. 处理反爬虫机制8. 数据存储9. …

IPTools for .NET:快速查询全球IP信息

IPTools for .NET&#xff1a;快速查询全球IP信息 IPTools 是一个用于快速查询全球 IP 地址信息的库&#xff0c;支持国内和国际 IP 查询&#xff0c;提供详细的地理位置信息&#xff08;如国家、省份、城市&#xff09;以及经纬度等数据。 1. IPTools.China IPTools.China …

Vue 中动态实现进度条

在 Vue 中动态实现进度条&#xff0c;基本上有两种常见的方法&#xff1a;直接通过 Vue 数据绑定控制样式&#xff0c;或者利用外部库来实现更复杂的功能。我们会深入探讨这两种方式&#xff0c;并且详细说明每种方法的实现步骤、优缺点以及使用场景。 1. 使用 Vue 数据绑定来…

SQL*PLUS命令

SQL*Plus概述 SQL*Plus工具是随Oracle 数据库服务器或客户端的安装而自动进行安装的管理与开发工具&#xff0c;Oracle数据库中所有的管理操作都可以通过SQL*Plus工具完成&#xff0c;同时开发人员利用SQL*Plus可以测试、运行SQL语句和PL/SQL程序。 运行方式&#xff1a; 命令…

国科大——数据挖掘(0812课程)——课后作业

前沿&#xff1a; 此文章记录了2024年度秋季学期数据挖掘课程的三次课后作业&#xff0c;答案仅供参考。 第一次作业 1 假定数据仓库中包含4个维&#xff1a;date, product, vendor, location&#xff1b;和两个度量&#xff1a;sales_volume和sales_cost。 1&#xff09;画…