123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924 |
- <!-- ---------------------------------------------------------------------
- --------------------------------------------------------------------- -->
- <template>
- <view class="uqrcode" :class="{ 'uqrcode-hide': hide }" :style="{ width: `${templateOptions.width}px`, height: `${templateOptions.height}px` }">
-
-
- <canvas
- class="uqrcode-canvas"
- :id="canvasId"
- :canvas-id="canvasId"
- :type="type"
- :style="{
- width: `${templateOptions.canvasWidth}px`,
- height: `${templateOptions.canvasHeight}px`,
- transform: templateOptions.canvasTransform
- }"
- @click="onClick"
- v-if="templateOptions.canvasDisplay"
- ></canvas>
-
-
-
- <gcanvas
- class="uqrcode-canvas"
- ref="gcanvas"
- :style="{
- width: `${templateOptions.canvasWidth}px`,
- height: `${templateOptions.canvasHeight}px`
- }"
- @click="onClick"
- v-if="templateOptions.canvasDisplay"
- ></gcanvas>
-
-
-
- <view class="uqrcode-h5-save" v-if="isH5Save">
- <image class="uqrcode-h5-save-image" :src="tempFilePath"></image>
- <text class="uqrcode-h5-save-text">若保存失败,请长按二维码进行保存</text>
- <view class="uqrcode-h5-save-close" @click="isH5Save = false">
- <view class="uqrcode-h5-save-close-before"></view>
- <view class="uqrcode-h5-save-close-after"></view>
- </view>
- </view>
-
-
- <view class="uqrcode-makeing" v-if="makeing">
- <image
- class="uqrcode-makeing-image"
- :style="{ width: `${templateOptions.size / 4}px`, height: `${templateOptions.size / 4}px` }"
- src="data:image/gif;base64,R0lGODlhAAEAAfIEAOHh4SSsWuDg4N3d3f///wAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/wtYTVAgRGF0YVhNUDw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDYuMC1jMDAyIDc5LjE2NDQ4OCwgMjAyMC8wNy8xMC0yMjowNjo1MyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYm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V0eACP6XBXaRRSjhhBRWaOGFGGao4YYcdujhhyCGKOKIJJZo4okopqjiimQB4OKLMMYo44w01mjjjTMSKMCOPPbo449ABinkkDgWaeSROOpI5JJMNonkk1BGqaSTVFYZ5ZVY3jillVx2meWXSG7p5Zhkgmmmi2KWqeaZbBqZ5ppwtilnjG/GaeecbNZ55554Yqknn4D2eeSfgRYqaI2EGqrooS8muiijkDr6KKSCSjoppXNaeimmeSq46aec2qgpqKH66SmpqJYKwKipqjroqa3yKVWSsP64oaknSVmrj7deOauWu/bYq665QgmhhrgCRexl/1UOayxFy+bGpbNP/ipqsDxSGya0zxropLavFlsttjuC6ya343rbpLlFWosouQKwS6u426rLpLzA0hsus1Tie62+59q7pL/vAtwuvATT6K7CCCPrK7r18vutw9Hm9LDARCacI8T7SmulxjIuvDHGQ4JMJ8cBS7wuxa6GjPK9LLcMo8i2xiwzmi8PbPPNNPO6s8w9C/tzy0FnO7SrRZd7tKpJx7t0qU2bzGjUT4fadKxYn2xw1lwfvHXXYDP8ddhkN5pz2WhfjTbQZ68dttpuM9123De7PDbddZvJatZUk4x3xbsk6/Hfa/atMuGCWww4f4gXPrfYhzferbKTDy554hmBXxz55R0rXvlgnGvO1OJphS665+luTncCADs="
- ></image>
- </view>
-
- <view class="uqrcode-error" v-if="inError"><text class="uqrcode-error-message">Error, see console.</text></view>
- </view>
- </template>
- <script>
- import { toRaw } from 'vue';
- import UQRCode from '../../js_sdk/uqrcode';
- import { enable, WeexBridge } from '../../js_sdk/gcanvas';
- const modal = weex.requireModule('modal');
- export default {
- name: 'uqrcode',
- props: {
-
- canvasId: {
- type: String,
- required: true
- },
-
- value: {
- type: [String, Number]
- },
-
- size: {
- type: [String, Number],
- default: 200
- },
-
- sizeUnit: {
- type: String,
- default: 'px'
- },
-
- options: {
- type: Object,
- default: () => {
- return {};
- }
- },
-
- fileType: {
- type: String,
- default: 'png'
- },
-
- start: {
- type: Boolean,
- default: true
- },
-
- auto: {
- type: Boolean,
- default: false
- },
-
- hide: {
- type: Boolean,
- default: false
- },
-
- type: {
- type: String,
- default: undefined
- },
-
- isQueueLoadImage: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- canvas: undefined,
- canvasContext: undefined,
- makeDelegate: undefined,
- drawDelegate: undefined,
- toTempFilePathDelegate: undefined,
- makeing: false,
- drawing: false,
- inError: false,
- isH5Save: false,
- tempFilePath: '',
- templateOptions: {
- size: 0,
- width: 0,
- height: 0,
- canvasWidth: 0,
- canvasHeight: 0,
- canvasTransform: '',
- canvasDisplay: false
- },
- uqrcodeOptions: {
- data: ''
- },
- makeingPattern: [
- [
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, true, true, true, true, true, true, true]
- ],
- [
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, false, false, false, false, false, false, false],
- [true, true, true, true, true, true, false, true, true, true],
- [true, true, true, true, true, true, false, true, true, true],
- [true, true, true, true, true, true, false, true, true, true]
- ],
- [
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, true, true, true, true, false, false, false],
- [true, true, true, true, true, true, true, false, false, false],
- [true, true, true, true, true, true, true, false, false, false],
- [true, true, true, false, false, false, false, true, true, true],
- [true, true, true, false, false, false, false, true, true, true]
- ],
- [
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, false, false, false, false, false, false, false],
- [true, true, true, false, false, false, false, false, false, false],
- [true, true, true, false, false, false, false, false, false, false],
- [true, true, true, false, false, false, false, false, false, false],
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, true, true, true, true, true, true, true],
- [true, true, true, true, true, true, true, true, true, true]
- ]
- ]
- };
- },
- watch: {
- value: {
- handler() {
- if (this.auto) {
- this.remake();
- }
- }
- },
- size: {
- handler() {
- if (this.auto) {
- this.remake();
- }
- }
- },
- options: {
- handler() {
- if (this.auto) {
- this.remake();
- }
- },
- deep: true
- },
- makeing: {
- handler(val) {
- if (!val) {
- if (typeof this.toTempFilePathDelegate === 'function') {
- this.toTempFilePathDelegate();
- }
- }
- }
- },
- isQueueLoadImage: {
- handler(val) {
- UQRCode.isQueueLoadImage = val;
- },
- immediate: true
- }
- },
- mounted() {
- this.templateOptions.size = this.sizeUnit == 'rpx' ? uni.upx2px(this.size) : this.size;
- this.templateOptions.canvasWidth = this.templateOptions.size;
- this.templateOptions.canvasHeight = this.templateOptions.size;
- if (this.type == '2d') {
-
- this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size /
- this.templateOptions.canvasHeight})`;
-
- } else {
- this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size /
- this.templateOptions.canvasHeight})`;
- }
- if (this.start) {
- this.make();
- }
- },
- methods: {
-
- getTemplateOptions() {
- var size = this.sizeUnit == 'rpx' ? uni.upx2px(this.size) : this.size;
- return UQRCode.deepReplace(this.templateOptions, {
- size,
- width: size,
- height: size
- });
- },
-
- getUqrcodeOptions() {
- return UQRCode.deepReplace(this.options, {
- data: String(this.value),
- size: Number(this.templateOptions.size)
- });
- },
-
- resetCanvas(callback) {
- this.templateOptions.canvasDisplay = false;
- this.$nextTick(() => {
- this.templateOptions.canvasDisplay = true;
- this.$nextTick(() => {
- callback && callback();
- });
- });
- },
-
- async draw(callback = {}, isDrawDelegate = false) {
- if (typeof callback.success != 'function') {
- callback.success = () => {};
- }
- if (typeof callback.fail != 'function') {
- callback.fail = () => {};
- }
- if (typeof callback.complete != 'function') {
- callback.complete = () => {};
- }
- if (this.drawing) {
- if (!isDrawDelegate) {
- this.drawDelegate = () => {
- this.draw(callback, true);
- };
- return;
- }
- } else {
- this.drawing = true;
- }
- this.inError = false;
- if (!this.canvasId) {
- console.error('[uQRCode]: canvasId must be set!');
- this.inError = true;
- callback.fail({
- errMsg: '[uQRCode]: canvasId must be set!'
- });
- return;
- }
- if (!this.value) {
- console.error('[uQRCode]: value must be set!');
- this.inError = true;
- callback.fail({
- errMsg: '[uQRCode]: value must be set!'
- });
- return;
- }
-
- this.templateOptions = this.getTemplateOptions();
-
- this.uqrcodeOptions = this.getUqrcodeOptions();
-
- if (typeof this.uqrcodeOptions.errorCorrectLevel === 'string') {
- this.uqrcodeOptions.errorCorrectLevel = UQRCode.errorCorrectLevel[this.uqrcodeOptions.errorCorrectLevel];
- }
-
-
- if (typeof this.options.useDynamicSize === 'undefined') {
- this.uqrcodeOptions.useDynamicSize = true;
- }
-
-
- this.uqrcodeOptions.useDynamicSize = false;
-
-
- const qr = new UQRCode();
-
- qr.setOptions(this.uqrcodeOptions);
-
- qr.make();
-
- let canvasContext = null;
-
- if (this.type === '2d') {
-
-
- const canvas = (this.canvas = await new Promise(resolve => {
- uni
- .createSelectorQuery()
- .in(this)
- .select(`#${this.canvasId}`)
- .fields({
- node: true,
- size: true
- })
- .exec(res => {
- resolve(res[0].node);
- });
- }));
- canvasContext = this.canvasContext = canvas.getContext('2d');
-
- this.templateOptions.canvasWidth = qr.size;
- this.templateOptions.canvasHeight = qr.size;
- this.templateOptions.canvasTransform = '';
-
- const dpr = uni.getSystemInfoSync().pixelRatio;
- canvas.width = qr.dynamicSize * dpr;
- canvas.height = qr.dynamicSize * dpr;
- canvasContext.scale(dpr, dpr);
-
- UQRCode.loadImage = function(src) {
-
- return new Promise((resolve, reject) => {
- const img = canvas.createImage();
- img.src = src;
- img.onload = () => {
- resolve(img);
- };
- img.onerror = err => {
- reject(err);
- };
- });
- };
-
-
-
- canvasContext = this.canvasContext = uni.createCanvasContext(this.canvasId, this);
-
- this.templateOptions.canvasWidth = qr.dynamicSize;
- this.templateOptions.canvasHeight = qr.dynamicSize;
- this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size /
- this.templateOptions.canvasHeight})`;
-
- UQRCode.loadImage = function(src) {
- return new Promise((resolve, reject) => {
- if (src.startsWith('http')) {
- uni.getImageInfo({
- src,
- success: res => {
- resolve(res.path);
- },
- fail: err => {
- reject(err);
- }
- });
- } else {
- if (src.startsWith('.')) {
- console.error('[uQRCode]: 本地图片路径仅支持绝对路径!');
- throw new Error('[uQRCode]: local image path only supports absolute path!');
- } else {
- resolve(src);
- }
- }
- });
- };
-
- } else {
-
- canvasContext = this.canvasContext = uni.createCanvasContext(this.canvasId, this);
-
- this.templateOptions.canvasWidth = qr.dynamicSize;
- this.templateOptions.canvasHeight = qr.dynamicSize;
- this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size /
- this.templateOptions.canvasHeight})`;
-
- UQRCode.loadImage = function(src) {
- return new Promise((resolve, reject) => {
-
- if (src.startsWith('http')) {
- uni.getImageInfo({
- src,
- success: res => {
- resolve(res.path);
- },
- fail: err => {
- reject(err);
- }
- });
- } else {
- if (src.startsWith('.')) {
- console.error('[uQRCode]: 本地图片路径仅支持绝对路径!');
- throw new Error('[uQRCode]: local image path only supports absolute path!');
- } else {
- resolve(src);
- }
- }
- });
- };
- }
-
-
-
- const gcanvas = this.$refs['gcanvas'];
- const canvas = enable(gcanvas, {
- bridge: WeexBridge
- });
- canvasContext = this.canvasContext = canvas.getContext('2d');
-
- UQRCode.loadImage = function(src) {
- return new Promise((resolve, reject) => {
-
- if (src.startsWith('http')) {
- uni.getImageInfo({
- src,
- success: res => {
- resolve(res.path);
- },
- fail: err => {
- reject(err);
- }
- });
- } else {
- if (src.startsWith('.')) {
- console.error('[uQRCode]: 本地图片路径仅支持绝对路径!');
- throw new Error('[uQRCode]: local image path only supports absolute path!');
- } else {
- resolve(src);
- }
- }
- });
- };
-
-
- qr.canvasContext = canvasContext;
-
- setTimeout(() => {
-
- qr.drawCanvas()
- .then(() => {
- if (this.drawDelegate) {
-
- let delegate = this.drawDelegate;
- this.drawDelegate = undefined;
- delegate();
- } else {
- this.drawing = false;
- callback.success();
- }
- })
- .catch(err => {
- if (this.drawDelegate) {
-
- let delegate = this.drawDelegate;
- this.drawDelegate = undefined;
- delegate();
- } else {
- this.drawing = false;
- this.inError = true;
- callback.fail(err);
- }
- })
- .finally(() => {
- callback.complete();
- });
- }, 300);
- },
-
- make(callback = {}) {
- this.makeing = true;
- if (typeof callback.success != 'function') {
- callback.success = () => {};
- }
- if (typeof callback.fail != 'function') {
- callback.fail = () => {};
- }
- if (typeof callback.complete != 'function') {
- callback.complete = () => {};
- }
- this.resetCanvas(() => {
- clearTimeout(this.makeDelegate);
- this.makeDelegate = setTimeout(() => {
- this.draw({
- success: () => {
- setTimeout(() => {
- callback.success();
- this.complete(true);
- }, 300);
- },
- fail: err => {
- callback.fail(err);
- this.complete(false, err.errMsg);
- },
- complete: () => {
- callback.complete();
- this.makeing = false;
- }
- });
- }, 300);
- });
- },
-
- remake(callback) {
- this.$emit('change');
- this.make(callback);
- },
-
- complete(success = true, errMsg = '') {
- if (success) {
- this.$emit('complete', {
- success
- });
- } else {
- this.$emit('complete', {
- success,
- errMsg
- });
- }
- },
-
- toTempFilePath(callback = {}) {
- if (typeof callback.success != 'function') {
- callback.success = () => {};
- }
- if (typeof callback.fail != 'function') {
- callback.fail = () => {};
- }
- if (typeof callback.complete != 'function') {
- callback.complete = () => {};
- }
- if (this.makeing) {
-
- this.toTempFilePathDelegate = () => {
- this.toTempFilePath(callback);
- };
- return;
- } else {
- this.toTempFilePathDelegate = null;
- }
-
- if (this.type === '2d') {
-
-
- const reg = new RegExp('^data:image/png;base64,', 'g');
-
- const dataURL = toRaw(this.canvas)
- .toDataURL()
- .replace(reg, '');
-
-
- const dataURL = this.canvas.toDataURL().replace(reg, '');
-
- const fs = wx.getFileSystemManager();
- const tempFilePath = `${wx.env.USER_DATA_PATH}/${new Date().getTime()}${
- Math.random()
- .toString()
- .split('.')[1]
- }.png`;
- fs.writeFile({
- filePath: tempFilePath,
- data: dataURL,
- encoding: 'base64',
- success: res => {
- callback.success({
- tempFilePath
- });
- },
- fail: err => {
- callback.fail(err);
- },
- complete: () => {
- callback.complete();
- }
- });
-
- } else {
- uni.canvasToTempFilePath(
- {
- canvasId: this.canvasId,
- fileType: this.fileType,
- width: Number(this.templateOptions.canvasWidth),
- height: Number(this.templateOptions.canvasHeight),
- destWidth: Number(this.templateOptions.size),
- destHeight: Number(this.templateOptions.size),
- success: res => {
- callback.success(res);
- },
- fail: err => {
- callback.fail(err);
- },
- complete: () => {
- callback.complete();
- }
- },
- this
- );
- }
-
-
-
- const dpr = uni.getSystemInfoSync().pixelRatio;
- this.canvasContext.toTempFilePath(
- 0,
- 0,
- this.templateOptions.canvasWidth * dpr,
- this.templateOptions.canvasHeight * dpr,
- this.templateOptions.size * dpr,
- this.templateOptions.size * dpr,
- '',
- 1,
- res => {
- callback.success(res);
- callback.complete(res);
- }
- );
-
- },
-
- save(callback = {}) {
- if (typeof callback.success != 'function') {
- callback.success = () => {};
- }
- if (typeof callback.fail != 'function') {
- callback.fail = () => {};
- }
- if (typeof callback.complete != 'function') {
- callback.complete = () => {};
- }
- this.toTempFilePath({
- success: res => {
-
- uni.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: res1 => {
- callback.success(res1);
- },
- fail: err1 => {
- callback.fail(err1);
- },
- complete: () => {
- callback.complete();
- }
- });
-
-
-
- this.isH5Save = true;
- this.tempFilePath = res.tempFilePath;
- const aEle = document.createElement('a');
- aEle.download = 'uQRCode';
- aEle.href = res.tempFilePath;
- document.body.appendChild(aEle);
- aEle.click();
- aEle.remove();
- callback.success({
- errMsg: 'ok'
- });
- callback.complete();
-
- },
- fail: err => {
- callback.fail(err);
- callback.complete();
- }
- });
- },
-
- onClick(e) {
- this.$emit('click', e);
- }
- }
- };
- </script>
- <style scoped>
- .uqrcode {
- position: relative;
- }
- .uqrcode-hide {
- position: fixed;
- left: 7500rpx;
- }
- .uqrcode-canvas {
- transform-origin: top left;
- }
- .uqrcode-makeing {
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- z-index: 10;
-
- display: flex;
-
- justify-content: center;
- align-items: center;
- }
- .uqrcode-makeing-image {
-
- display: block;
- max-width: 120px;
- max-height: 120px;
-
- }
- .uqrcode-error {
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
-
- display: flex;
-
- justify-content: center;
- align-items: center;
- }
- .uqrcode-error-message {
- font-size: 12px;
- color: #939291;
- }
- .uqrcode-h5-save {
- position: fixed;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- z-index: 100;
- background-color: rgba(0, 0, 0, 0.68);
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- }
- .uqrcode-h5-save-image {
- width: 512rpx;
- height: 512rpx;
- padding: 32rpx;
- }
- .uqrcode-h5-save-text {
- margin-top: 20rpx;
- font-size: 32rpx;
- font-weight: 700;
- color: #ffffff;
- }
- .uqrcode-h5-save-close {
- position: relative;
- margin-top: 72rpx;
- width: 40rpx;
- height: 40rpx;
- border: 2rpx solid #ffffff;
- border-radius: 40rpx;
- padding: 10rpx;
- }
- .uqrcode-h5-save-close-before {
- position: absolute;
- top: 50%;
- transform: translateY(-50%) rotate(45deg);
- width: 40rpx;
- height: 4rpx;
- background: #ffffff;
- }
- .uqrcode-h5-save-close-after {
- position: absolute;
- top: 50%;
- transform: translateY(-50%) rotate(-45deg);
- width: 40rpx;
- height: 4rpx;
- background: #ffffff;
- }
- </style>
|