|
@@ -1,5 +1,5 @@
|
|
|
import React from "react";
|
|
|
-import { View, Text, Image, Button } from "@tarojs/components";
|
|
|
+import { View, Text, Image, Button, Canvas } from "@tarojs/components";
|
|
|
import Taro from "@tarojs/taro";
|
|
|
|
|
|
import "./index.scss";
|
|
@@ -23,6 +23,8 @@ class Us extends React.Component<any, any> {
|
|
|
this.state = {
|
|
|
height: 0,
|
|
|
heightKf: 0,
|
|
|
+ Cwidth: 0,
|
|
|
+ Cheight: 0,
|
|
|
userUrl: Taro.getStorageSync("userUrl") || "",
|
|
|
userPhone: Taro.getStorageSync("userPhone") || "",
|
|
|
};
|
|
@@ -54,23 +56,74 @@ class Us extends React.Component<any, any> {
|
|
|
url: base.baseAPI + "/wx/getuserphonenumber?code=" + e.detail.code,
|
|
|
method: "GET",
|
|
|
}).then((res: any) => {
|
|
|
- const { data: { code, data: { phoneInfo } }, statusCode } = res;
|
|
|
- if (statusCode !== 200 || code !== 0) return Taro.showToast({
|
|
|
- title: "获取手机号失败",
|
|
|
- icon: "none",
|
|
|
- });
|
|
|
+ const {
|
|
|
+ data: {
|
|
|
+ code,
|
|
|
+ data: { phoneInfo },
|
|
|
+ },
|
|
|
+ statusCode,
|
|
|
+ } = res;
|
|
|
+ if (statusCode !== 200 || code !== 0)
|
|
|
+ return Taro.showToast({
|
|
|
+ title: "获取手机号失败",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
const { phoneNumber } = phoneInfo;
|
|
|
this.setState({
|
|
|
- userPhone: phoneNumber || ""
|
|
|
- })
|
|
|
+ userPhone: phoneNumber || "",
|
|
|
+ });
|
|
|
Taro.setStorageSync("userPhone", phoneNumber || "");
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ createImge = () => {
|
|
|
+ const ctx = Taro.createCanvasContext("myCanvas");
|
|
|
+
|
|
|
+ // 获取远程图片
|
|
|
+ Taro.getImageInfo({
|
|
|
+ src: "https://cxzx.smcic.net/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/6.jpg",
|
|
|
+ }).then((res: any) => {
|
|
|
+ const { width, height, path } = res;
|
|
|
+ this.setState({
|
|
|
+ Cwidth: width * this.#systemInfo.pixelRatio,
|
|
|
+ Cheight: height * this.#systemInfo.pixelRatio,
|
|
|
+ });
|
|
|
+ Taro.nextTick(() => {
|
|
|
+ ctx.drawImage(
|
|
|
+ path,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ width * this.#systemInfo.pixelRatio,
|
|
|
+ height * this.#systemInfo.pixelRatio
|
|
|
+ );
|
|
|
+ // ctx.setFillStyle("black");
|
|
|
+ // ctx.setFontSize(36);
|
|
|
+
|
|
|
+ // ctx.fillText("李勇利", 80, 80);
|
|
|
+ ctx.draw(false, () => {
|
|
|
+ Taro.canvasToTempFilePath({
|
|
|
+ canvasId: "myCanvas",
|
|
|
+ quality: 0.8,
|
|
|
+ success: (res: any) => {
|
|
|
+ Taro.previewImage({
|
|
|
+ urls: [res.tempFilePath],
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
render() {
|
|
|
// const { } = this.props;
|
|
|
return (
|
|
|
<View className="Us">
|
|
|
+ <Canvas
|
|
|
+ id="myCanvas"
|
|
|
+ canvas-id="myCanvas"
|
|
|
+ style={`width: ${this.state.Cwidth}px;height: ${this.state.Cheight}px;`}
|
|
|
+ ></Canvas>
|
|
|
<Button
|
|
|
className="user"
|
|
|
open-type="chooseAvatar"
|
|
@@ -80,8 +133,9 @@ class Us extends React.Component<any, any> {
|
|
|
</Button>
|
|
|
|
|
|
<Image
|
|
|
- style={`width: ${this.#systemInfo.screenWidth}px;height: ${this.state.height
|
|
|
- }px;`}
|
|
|
+ style={`width: ${this.#systemInfo.screenWidth}px;height: ${
|
|
|
+ this.state.height
|
|
|
+ }px;`}
|
|
|
src="https://cxzx.smcic.net/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/us-top.png"
|
|
|
onLoad={this.getImageSize}
|
|
|
/>
|
|
@@ -107,7 +161,7 @@ class Us extends React.Component<any, any> {
|
|
|
</View>
|
|
|
)}
|
|
|
{this.state.userPhone && (
|
|
|
- <View className="us_cell">
|
|
|
+ <View className="us_cell" onClick={this.createImge}>
|
|
|
<View className="left">
|
|
|
<Image src={certificate} className="img"></Image>
|
|
|
<Text className="text">证书下载</Text>
|
|
@@ -130,8 +184,9 @@ class Us extends React.Component<any, any> {
|
|
|
)}
|
|
|
</InputBox>
|
|
|
<Image
|
|
|
- style={`width: ${this.#systemInfo.screenWidth * 0.92}px;height: ${this.state.heightKf
|
|
|
- }px;display: block;margin: 0 auto`}
|
|
|
+ style={`width: ${this.#systemInfo.screenWidth * 0.92}px;height: ${
|
|
|
+ this.state.heightKf
|
|
|
+ }px;display: block;margin: 0 auto`}
|
|
|
showMenuByLongpress={true}
|
|
|
src="https://cxzx.smcic.net/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/us-kf.png"
|
|
|
onLoad={this.getImageKf}
|