feat: 注册页面添加扫描邀请码
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
# 版本号
|
# 版本号
|
||||||
SHOPRO_VERSION=v2.4.1
|
SHOPRO_VERSION=v2.4.1
|
||||||
# 后端接口 - 正式环境(通过 process.env.NODE_ENV 非 development)
|
# 后端接口 - 正式环境(通过 process.env.NODE_ENV 非 development)
|
||||||
#SHOPRO_BASE_URL=http://8.136.55.200:48090
|
SHOPRO_BASE_URL=http://www.qflyqzy.net:48090
|
||||||
|
# SHOPRO_BASE_URL=https://yougoutest.api.riananyoumu.com
|
||||||
|
|
||||||
# 后端接口 - 测试环境(通过 process.env.NODE_ENV = development)
|
# 后端接口 - 测试环境(通过 process.env.NODE_ENV = development)
|
||||||
|
|
||||||
@@ -55,4 +56,3 @@ SHOPRO_MPLIVE_ON=0
|
|||||||
|
|
||||||
# 租户ID 默认 1
|
# 租户ID 默认 1
|
||||||
SHOPRO_TENANT_ID=1
|
SHOPRO_TENANT_ID=1
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
"name" : "优购商城",
|
"name" : "优购商城",
|
||||||
"appid" : "__UNI__8B19741",
|
"appid" : "__UNI__8B19741",
|
||||||
"description" : "",
|
"description" : "",
|
||||||
"versionName" : "1.5.5",
|
"versionName" : "1.5.8",
|
||||||
"versionCode" : 155,
|
"versionCode" : 158,
|
||||||
"transformPx" : false,
|
"transformPx" : false,
|
||||||
"app-plus" : {
|
"app-plus" : {
|
||||||
"privacy" : {
|
"privacy" : {
|
||||||
|
|||||||
+36
-5
@@ -17,7 +17,7 @@
|
|||||||
<uni-forms ref="form" label-position="top">
|
<uni-forms ref="form" label-position="top">
|
||||||
<view v-for="(v, i) in dataObj.con[type].arr" :key="i">
|
<view v-for="(v, i) in dataObj.con[type].arr" :key="i">
|
||||||
<uni-forms-item
|
<uni-forms-item
|
||||||
:required="false"
|
:required="dataObj.formArr[v].required !== false"
|
||||||
:label="dataObj.formArr[v].title"
|
:label="dataObj.formArr[v].title"
|
||||||
:name="dataObj.formArr[v].value"
|
:name="dataObj.formArr[v].value"
|
||||||
>
|
>
|
||||||
@@ -29,12 +29,14 @@
|
|||||||
:type="dataObj.formArr[v].type"
|
:type="dataObj.formArr[v].type"
|
||||||
:inputBorder="false"
|
:inputBorder="false"
|
||||||
:maxlength="dataObj.formArr[v].max"
|
:maxlength="dataObj.formArr[v].max"
|
||||||
|
:disabled="dataObj.formArr[v].value === 'inviteCode'"
|
||||||
@focus="() => onInputFocus(dataObj.formArr[v].value)"
|
@focus="() => onInputFocus(dataObj.formArr[v].value)"
|
||||||
@input="() => onInputInput(dataObj.formArr[v].value)"
|
@input="() => onInputInput(dataObj.formArr[v].value)"
|
||||||
/>
|
/>
|
||||||
<view v-if="v == 2" class="c_code size28" @click="getCode">{{
|
<view v-if="v == 2" class="c_code size28" @click="getCode">{{
|
||||||
num > 0 && num < 60 ? num + 's后重新获取' : '获取验证码'
|
num > 0 && num < 60 ? num + 's后重新获取' : '获取验证码'
|
||||||
}}</view>
|
}}</view>
|
||||||
|
<view v-if="v == 6" class="invite-scan-icon _icon-scan" @tap.stop="onInviteScan"></view>
|
||||||
<view
|
<view
|
||||||
v-if="shouldShowDropdownIcon(dataObj.formArr[v].value)"
|
v-if="shouldShowDropdownIcon(dataObj.formArr[v].value)"
|
||||||
class="login-suggest-icon"
|
class="login-suggest-icon"
|
||||||
@@ -117,12 +119,14 @@
|
|||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import { onLoad } from '@dcloudio/uni-app';
|
import { onLoad } from '@dcloudio/uni-app';
|
||||||
import AuthUtil from '@/sheep/api/member/auth';
|
import AuthUtil from '@/sheep/api/member/auth';
|
||||||
|
import { scanInviteCode } from '@/utils/qrScanner';
|
||||||
let type = ref(2);
|
let type = ref(2);
|
||||||
let formData = reactive({
|
let formData = reactive({
|
||||||
mobile: '',
|
mobile: '',
|
||||||
code: '',
|
code: '',
|
||||||
password: '',
|
password: '',
|
||||||
confirmPassword: '',
|
confirmPassword: '',
|
||||||
|
inviteCode: '',
|
||||||
});
|
});
|
||||||
let num = ref(0);
|
let num = ref(0);
|
||||||
const inputIconMap = {
|
const inputIconMap = {
|
||||||
@@ -131,6 +135,7 @@
|
|||||||
3: '/static/icon/icon3.png',
|
3: '/static/icon/icon3.png',
|
||||||
4: '/static/icon/icon3.png',
|
4: '/static/icon/icon3.png',
|
||||||
5: '/static/icon/icon4.png',
|
5: '/static/icon/icon4.png',
|
||||||
|
6: '/static/icon/icon5.png',
|
||||||
};
|
};
|
||||||
let dataObj = reactive({
|
let dataObj = reactive({
|
||||||
con: {
|
con: {
|
||||||
@@ -154,7 +159,7 @@
|
|||||||
},
|
},
|
||||||
3: {
|
3: {
|
||||||
title: '用户注册',
|
title: '用户注册',
|
||||||
arr: [1, 2, 4, 5],
|
arr: [1, 2, 4, 5, 6],
|
||||||
text: '已有账号,',
|
text: '已有账号,',
|
||||||
btn1: 4,
|
btn1: 4,
|
||||||
btn2: 3,
|
btn2: 3,
|
||||||
@@ -204,6 +209,13 @@
|
|||||||
value: 'confirmPassword',
|
value: 'confirmPassword',
|
||||||
placeholder: '请再次输入您的密码',
|
placeholder: '请再次输入您的密码',
|
||||||
},
|
},
|
||||||
|
6: {
|
||||||
|
title: '邀请码',
|
||||||
|
type: 'text',
|
||||||
|
value: 'inviteCode',
|
||||||
|
max: 32,
|
||||||
|
placeholder: '请扫码获取邀请码',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
btns: {
|
btns: {
|
||||||
1: {
|
1: {
|
||||||
@@ -401,14 +413,18 @@
|
|||||||
let arr = dataObj.con[type.value].arr;
|
let arr = dataObj.con[type.value].arr;
|
||||||
let obj = {};
|
let obj = {};
|
||||||
for (let i = 0; i < arr.length; i++) {
|
for (let i = 0; i < arr.length; i++) {
|
||||||
if (!formData[dataObj.formArr[arr[i]].value]) {
|
const formItem = dataObj.formArr[arr[i]];
|
||||||
|
const valueKey = formItem?.value;
|
||||||
|
const required = formItem?.required !== false;
|
||||||
|
const value = formData[valueKey];
|
||||||
|
if (required && !value) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: dataObj.formArr[arr[i]].placeholder,
|
title: formItem?.placeholder,
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
obj[dataObj.formArr[arr[i]].value] = formData[dataObj.formArr[arr[i]].value];
|
if (value || required) obj[valueKey] = value;
|
||||||
}
|
}
|
||||||
let url = '';
|
let url = '';
|
||||||
switch (type.value) {
|
switch (type.value) {
|
||||||
@@ -519,6 +535,12 @@
|
|||||||
const go = (type) => {
|
const go = (type) => {
|
||||||
uni.navigateTo({ url: '/pages/home/agreement?type=' + type });
|
uni.navigateTo({ url: '/pages/home/agreement?type=' + type });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onInviteScan = async () => {
|
||||||
|
const code = await scanInviteCode({ toastOnError: true, allowCamera: false });
|
||||||
|
if (!code) return;
|
||||||
|
formData.inviteCode = code;
|
||||||
|
};
|
||||||
onLoad(async () => {
|
onLoad(async () => {
|
||||||
loadLoginHistory();
|
loadLoginHistory();
|
||||||
});
|
});
|
||||||
@@ -640,6 +662,15 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
.invite-scan-icon {
|
||||||
|
margin-left: auto;
|
||||||
|
padding-left: 12rpx;
|
||||||
|
padding-right: 6rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 36rpx;
|
||||||
|
color: #c6c6c6;
|
||||||
|
}
|
||||||
.login-suggest {
|
.login-suggest {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
@@ -0,0 +1,153 @@
|
|||||||
|
function isH5Runtime() {
|
||||||
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
||||||
|
}
|
||||||
|
|
||||||
|
function toast(text) {
|
||||||
|
uni.showToast({ title: text, icon: 'none' });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extractInviteCode(text) {
|
||||||
|
const raw = String(text || '').trim();
|
||||||
|
if (!raw) return '';
|
||||||
|
try {
|
||||||
|
const url = new URL(raw);
|
||||||
|
const params = url.searchParams;
|
||||||
|
return (
|
||||||
|
params.get('inviteCode') ||
|
||||||
|
params.get('code') ||
|
||||||
|
params.get('invite') ||
|
||||||
|
params.get('shareId') ||
|
||||||
|
params.get('bindUserId') ||
|
||||||
|
''
|
||||||
|
);
|
||||||
|
} catch (e) {}
|
||||||
|
const m = raw.match(/[?&](inviteCode|code|invite|shareId|bindUserId)=([^&#]+)/i);
|
||||||
|
if (m?.[2]) {
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(m[2]);
|
||||||
|
} catch (e) {
|
||||||
|
return m[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
function scanFromCamera({ scanType = ['qrCode'] } = {}) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
uni.scanCode({
|
||||||
|
onlyFromCamera: false,
|
||||||
|
scanType,
|
||||||
|
success: (res) => resolve(String(res?.result || '')),
|
||||||
|
fail: (err) => resolve(err?.errMsg === 'scanCode:fail cancel' ? '' : ''),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickSingleImageFileH5() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (!isH5Runtime()) {
|
||||||
|
resolve(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.type = 'file';
|
||||||
|
input.accept = 'image/*';
|
||||||
|
input.onchange = () => resolve((input.files && input.files[0]) || null);
|
||||||
|
input.click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function barcodeDetectQrFromFileH5(file) {
|
||||||
|
if (!file) return '';
|
||||||
|
if (!isH5Runtime()) return '';
|
||||||
|
const Detector = window.BarcodeDetector;
|
||||||
|
if (!Detector) return '';
|
||||||
|
try {
|
||||||
|
const detector = new Detector({ formats: ['qr_code'] });
|
||||||
|
if (window.createImageBitmap) {
|
||||||
|
const bitmap = await window.createImageBitmap(file);
|
||||||
|
const codes = await detector.detect(bitmap);
|
||||||
|
return String(codes?.[0]?.rawValue || '');
|
||||||
|
}
|
||||||
|
const img = new Image();
|
||||||
|
const url = URL.createObjectURL(file);
|
||||||
|
const text = await new Promise((resolve) => {
|
||||||
|
img.onload = async () => {
|
||||||
|
try {
|
||||||
|
const codes = await detector.detect(img);
|
||||||
|
resolve(String(codes?.[0]?.rawValue || ''));
|
||||||
|
} catch (e) {
|
||||||
|
resolve('');
|
||||||
|
} finally {
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
img.onerror = () => {
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
resolve('');
|
||||||
|
};
|
||||||
|
img.src = url;
|
||||||
|
});
|
||||||
|
return text;
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function scanQrCode({
|
||||||
|
scanType = ['qrCode'],
|
||||||
|
allowCamera = true,
|
||||||
|
allowAlbum = true,
|
||||||
|
toastOnError = true,
|
||||||
|
} = {}) {
|
||||||
|
if (!isH5Runtime()) {
|
||||||
|
const raw = await scanFromCamera({ scanType });
|
||||||
|
if (!raw && toastOnError) toast('扫码失败');
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allowAlbum && !allowCamera) {
|
||||||
|
const file = await pickSingleImageFileH5();
|
||||||
|
if (!file) return '';
|
||||||
|
const raw = await barcodeDetectQrFromFileH5(file);
|
||||||
|
if (!raw && toastOnError) toast('当前浏览器不支持图片识别');
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allowAlbum && allowCamera) {
|
||||||
|
const raw = await scanFromCamera({ scanType });
|
||||||
|
if (!raw && toastOnError) toast('扫码失败');
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
const action = await new Promise((resolve) => {
|
||||||
|
uni.showActionSheet({
|
||||||
|
itemList: ['相机扫码', '相册识别'],
|
||||||
|
success: (res) => resolve(res?.tapIndex),
|
||||||
|
fail: () => resolve(-1),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (action === 0) {
|
||||||
|
const raw = await scanFromCamera({ scanType });
|
||||||
|
if (!raw && toastOnError) toast('扫码失败');
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action === 1) {
|
||||||
|
const file = await pickSingleImageFileH5();
|
||||||
|
if (!file) return '';
|
||||||
|
const raw = await barcodeDetectQrFromFileH5(file);
|
||||||
|
if (!raw && toastOnError) toast('当前浏览器不支持图片识别,请用相机扫码');
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function scanInviteCode({ toastOnError = true, allowCamera = true, allowAlbum = true } = {}) {
|
||||||
|
const raw = await scanQrCode({ toastOnError, allowCamera, allowAlbum });
|
||||||
|
const code = extractInviteCode(raw);
|
||||||
|
if (!code && toastOnError) toast('未识别到邀请码');
|
||||||
|
return code;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user