refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,108 @@
|
||||
<template>
|
||||
<view class="background">
|
||||
<view class="container">
|
||||
<view class="nav">
|
||||
<view class="left_content">
|
||||
<text class="left_icon" @click="onBack()">{{backIcon}}</text>
|
||||
</view>
|
||||
|
||||
<view class="title_content">
|
||||
<text class="title">{{title}}</text>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
<web-view class="web_container" :src="url"></web-view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
const instance = getCurrentInstance()!.proxy!
|
||||
|
||||
const url = ref('')
|
||||
const title = ref('')
|
||||
const animationType = ref('slide-out-bottom')
|
||||
const backIcon = ref('\ue601')
|
||||
|
||||
function onBack() {
|
||||
uni.closeDialogPage({
|
||||
dialogPage: instance.$page,
|
||||
animationType: animationType.value,
|
||||
success(res) {
|
||||
console.log('closeThisDialog success', res)
|
||||
},
|
||||
fail(err) {
|
||||
console.log('closeThisDialog fail', err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onLoad((options : OnLoadOptions) => {
|
||||
url.value = options["url"] as string;
|
||||
title.value = options["title"] as string;
|
||||
animationType.value = options["animationType"] as string;
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.background {
|
||||
background-color: #007aff;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.nav {
|
||||
height: 45px;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
height: 45px;
|
||||
}
|
||||
|
||||
.left_content {
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 40px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.left_icon {
|
||||
color: white;
|
||||
top: 5px;
|
||||
height: 100%;
|
||||
font-family: uni-icon;
|
||||
font-size: 26px;
|
||||
}
|
||||
|
||||
.title_content {
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 45px;
|
||||
right: 45px;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.title {
|
||||
color: white;
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
.container {
|
||||
padding-top: var(--status-bar-height);
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.web_container {
|
||||
background-color: #f1f1f1;
|
||||
padding-top: 10px;
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,163 @@
|
||||
<template>
|
||||
<view>
|
||||
<page-head :title="title"></page-head>
|
||||
<view class="uni-padding-wrap uni-common-mt">
|
||||
<view class="uni-btn-v uni-common-mt">
|
||||
<button type="default" @click="verify(false)">一键登录(半屏)</button>
|
||||
</view>
|
||||
<view class="uni-btn-v uni-common-mt">
|
||||
<button type="default" @click="verify(true)">一键登录(全屏)</button>
|
||||
</view>
|
||||
<view class="uni-btn-v uni-common-mt">
|
||||
<button type="default" @click="customLoginIn()">一键登录(自定义页面)</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
const title = ref('一键登录')
|
||||
const uniVerifyManager = ref(null as UniVerifyManager | null)
|
||||
const phone = ref('')
|
||||
const slogan = ref('')
|
||||
const privacyName = ref('')
|
||||
const privacyUrl = ref('')
|
||||
|
||||
const preLogin = (callback: (() => void)) => {
|
||||
uniVerifyManager.value?.preLogin({
|
||||
success: (res) => {
|
||||
phone.value = res.number;
|
||||
slogan.value = res.slogan;
|
||||
privacyName.value = res.privacyName;
|
||||
privacyUrl.value = res.privacyUrl;
|
||||
console.log("pre login success");
|
||||
callback();
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error("pre login fail => " + JSON.stringify(err));
|
||||
const hasCauseMessage = (err.cause?.cause?.message ?? '').length > 0
|
||||
uni.showModal({
|
||||
title: '预登录失败',
|
||||
content: hasCauseMessage ? JSON.parseObject(err.cause?.cause?.message ?? '')?.getString("errorDesc") : err.errMsg,
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const pushCustomPage = () => {
|
||||
const url = '/pages/API/get-uni-verify-manager/uni-verify-custom-page?phone=' + phone.value + '&slogan=' + slogan.value + '&name=' + privacyName.value + '&link=' + privacyUrl.value;
|
||||
uni.openDialogPage({
|
||||
url: url,
|
||||
animationType: 'slide-in-bottom',
|
||||
success(res) {
|
||||
console.log("成功打开自定义登录页面");
|
||||
},
|
||||
fail(err) {
|
||||
console.log(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const customLoginIn = () => {
|
||||
if('production' === process.env.NODE_ENV && '__UNI__HelloUniAppX'===uni.getAppBaseInfo().appId){
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '一键登录为收费功能,当前环境暂不支持。请在HBuilderX中新建Hello uni-app x项目真机运行体验!',
|
||||
showCancel: false
|
||||
})
|
||||
return
|
||||
}
|
||||
const isPreLoginValid = uniVerifyManager.value?.isPreLoginValid() ?? false;
|
||||
if (isPreLoginValid) {
|
||||
pushCustomPage();
|
||||
} else {
|
||||
preLogin(() => {
|
||||
pushCustomPage();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const takePhoneNumber = (accessToken: string, openId: string) => {
|
||||
// 云函数取号
|
||||
uniCloud.callFunction({
|
||||
name: 'univerify',
|
||||
data: {
|
||||
access_token: accessToken, // 客户端一键登录接口返回的access_token
|
||||
openid: openId // 客户端一键登录接口返回的openid
|
||||
}
|
||||
}).then(res => {
|
||||
// 关闭登录页
|
||||
uniVerifyManager.value?.close();
|
||||
setTimeout(() => {
|
||||
uni.showModal({
|
||||
title: '取号成功',
|
||||
content: res.result.getJSON("res")?.getString("phoneNumber"),
|
||||
showCancel: false
|
||||
});
|
||||
}, 100);
|
||||
}).catch(err => {
|
||||
console.error(JSON.stringify(err));
|
||||
// 关闭登录页
|
||||
uniVerifyManager.value?.close();
|
||||
setTimeout(() => {
|
||||
uni.showModal({
|
||||
title: '取号失败',
|
||||
content: (err as Error).message,
|
||||
showCancel: false
|
||||
});
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
const login = (fullScreen: boolean) => {
|
||||
uniVerifyManager.value?.login({
|
||||
uniVerifyStyle:{
|
||||
fullScreen: fullScreen,
|
||||
loginBtnText: "一键登录",
|
||||
logoPath: "/static/test-image/logo.png"
|
||||
},
|
||||
success: (res) => {
|
||||
console.log("login success => " + JSON.stringify(res));
|
||||
takePhoneNumber(res.accessToken,res.openId);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error("login fail => " + err);
|
||||
const hasCauseMessage = (err.cause?.cause?.message ?? '').length > 0
|
||||
uni.showModal({
|
||||
title: '登录失败',
|
||||
content: hasCauseMessage ? JSON.parseObject(err.cause?.cause?.message ?? "")?.getString("errorDesc") : err.errMsg,
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const verify = (fullScreen: boolean) => {
|
||||
if('production' === process.env.NODE_ENV && '__UNI__HelloUniAppX'===uni.getAppBaseInfo().appId){
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '一键登录为收费功能,当前环境暂不支持。请在HBuilderX中新建Hello uni-app x项目真机运行体验!',
|
||||
showCancel: false
|
||||
})
|
||||
return
|
||||
}
|
||||
// 校验预登录是否有效
|
||||
const isPreLoginValid = uniVerifyManager.value?.isPreLoginValid() ?? false;
|
||||
if (isPreLoginValid) {
|
||||
// 预登录有效,执行登录
|
||||
login(fullScreen);
|
||||
} else {
|
||||
// 预登录无效,执行预登录
|
||||
preLogin(() => {
|
||||
login(fullScreen);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
uniVerifyManager.value = uni.getUniVerifyManager();
|
||||
// 预登录
|
||||
preLogin(() => { });
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,269 @@
|
||||
<template>
|
||||
<view class="container" :class="state.isDarkMode ? 'theme-dark' : 'theme-light'">
|
||||
<view class="safe_content">
|
||||
<text class="close_icon" @click="closePage">{{closeIcon}}</text>
|
||||
<text class="title">这是一键登录自定义 uvue 页面</text>
|
||||
<view class="number">
|
||||
<text id="number-text" class="number-text" ref="number-text">{{phone}}</text>
|
||||
<text id="slogan-text" class="slogan-text">{{slogan}}</text>
|
||||
</view>
|
||||
<button id="login-button" class="login-button" @click="loginIn">本机号码一键登录</button>
|
||||
<view class="privacy">
|
||||
<checkbox id="privacy-checkbox" class="privacy-checkbox" ref="privacy-checkbox" :checked="false"></checkbox>
|
||||
<text class="privacy-normal-text">登录即同意</text>
|
||||
<text id="privacy-text" class="privacy-text" @click="openLink">{{privacyName}}</text>
|
||||
</view>
|
||||
<text class="other" @click="otherLogin">其他登录方式</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { state } from '@/store/index.uts'
|
||||
|
||||
const instance = getCurrentInstance()!.proxy!
|
||||
|
||||
const uniVerifyManager = ref(null as UniVerifyManager | null)
|
||||
const phone = ref('')
|
||||
const slogan = ref('')
|
||||
const privacyName = ref('')
|
||||
const privacyUrl = ref('')
|
||||
const closeIcon = ref('\uE650')
|
||||
const isLoading = ref(false)
|
||||
|
||||
function closePage() {
|
||||
uni.closeDialogPage({
|
||||
dialogPage: instance.$page,
|
||||
animationType: 'slide-out-bottom',
|
||||
success(res) {
|
||||
console.log('closeThisDialog success', res)
|
||||
},
|
||||
fail(err) {
|
||||
console.log('closeThisDialog fail', err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function openLink() {
|
||||
let url = '/pages/API/get-uni-verify-manager/full-webview-page?url=' + privacyUrl.value + '&title=' + privacyName.value + '&animationType=slide-out-bottom';
|
||||
uni.openDialogPage({
|
||||
url: url,
|
||||
animationType: 'slide-in-bottom',
|
||||
success(res) {
|
||||
console.log("打开隐私协议");
|
||||
},
|
||||
fail(err) {
|
||||
console.log(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function takePhoneNumber(token : string, openId : string) {
|
||||
uniCloud.callFunction({
|
||||
name: 'univerify',
|
||||
data: {
|
||||
access_token: token,
|
||||
openid: openId
|
||||
}
|
||||
}).then(res => {
|
||||
closePage();
|
||||
setTimeout(() => {
|
||||
uni.showModal({
|
||||
title: '取号成功',
|
||||
content: res.result.getJSON("res")?.getString("phoneNumber"),
|
||||
showCancel: false
|
||||
});
|
||||
}, 100);
|
||||
}).catch(err => {
|
||||
console.error(JSON.stringify(err));
|
||||
closePage();
|
||||
setTimeout(() => {
|
||||
uni.showModal({
|
||||
title: '取号失败',
|
||||
content: (err as Error).message,
|
||||
showCancel: false
|
||||
});
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
function loginIn() {
|
||||
if (isLoading.value) {
|
||||
uni.showToast({
|
||||
title: "正在登录中,请稍后",
|
||||
position: "bottom",
|
||||
duration: 2000
|
||||
})
|
||||
return;
|
||||
}else{
|
||||
isLoading.value = true;
|
||||
}
|
||||
const numberTextElement = instance.$page.getElementById('number-text');
|
||||
const sloganTextElement = instance.$page.getElementById('slogan-text');
|
||||
const loginButtonElement = instance.$page.getElementById('login-button');
|
||||
const privacyCheckBoxElement = instance.$page.getElementById('privacy-checkbox');
|
||||
const privacyTextElement = instance.$page.getElementById('privacy-text');
|
||||
if (numberTextElement != null && sloganTextElement != null && loginButtonElement != null && privacyCheckBoxElement != null && privacyTextElement != null) {
|
||||
uniVerifyManager.value?.customLogin({
|
||||
numberTextElement: numberTextElement,
|
||||
sloganTextElement: sloganTextElement,
|
||||
loginButtonElement: loginButtonElement,
|
||||
privacyCheckBoxElement: privacyCheckBoxElement,
|
||||
privacyTextElement: privacyTextElement,
|
||||
success: (res) => {
|
||||
console.log(res);
|
||||
takePhoneNumber(res.accessToken, res.openId);
|
||||
},
|
||||
fail: (error) => {
|
||||
if (error.errCode == 40001) {
|
||||
uni.showToast({
|
||||
title: "请同意服务条款",
|
||||
position: "bottom",
|
||||
duration: 2000
|
||||
})
|
||||
} else if (error.errCode == 40002) {
|
||||
uni.showToast({
|
||||
title: "授权页不符合规范",
|
||||
position: "bottom",
|
||||
duration: 2000
|
||||
})
|
||||
} else {
|
||||
const errorMsg = JSON.parseObject(error.cause?.cause?.message ?? "")?.getString("errorDesc") ?? error.errMsg;
|
||||
uni.showToast({
|
||||
title: errorMsg,
|
||||
position: "bottom",
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
},
|
||||
complete: () =>{
|
||||
isLoading.value = false;
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: "未获取到页面元素",
|
||||
position: "bottom",
|
||||
duration: 2000
|
||||
})
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function otherLogin() {
|
||||
uni.showToast({
|
||||
title: "使用其他方式登录",
|
||||
position: "bottom"
|
||||
})
|
||||
}
|
||||
|
||||
onLoad((options : OnLoadOptions) => {
|
||||
uniVerifyManager.value = uni.getUniVerifyManager();
|
||||
phone.value = options['phone'] as string;
|
||||
slogan.value = options['slogan'] as string;
|
||||
privacyName.value = options['name'] as string;
|
||||
privacyUrl.value = options['link'] as string;
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
background-color: var(--background-color);
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.safe_content {
|
||||
padding-top: var(--status-bar-height);
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.close_icon {
|
||||
left: 90%;
|
||||
top: 15px;
|
||||
font-family: uni-icon;
|
||||
font-size: 24px;
|
||||
/* font-weight: bold; */
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.title {
|
||||
align-self: center;
|
||||
top: 20px;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.number {
|
||||
width: 100%;
|
||||
top: 25%;
|
||||
position: absolute;
|
||||
height: 120px;
|
||||
}
|
||||
|
||||
.number-text {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
align-self: center;
|
||||
height: 30px;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.slogan-text {
|
||||
margin-top: 10px;
|
||||
width: 100%;
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
align-self: center;
|
||||
color: gray;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.login-button {
|
||||
width: 80%;
|
||||
top: 40%;
|
||||
position: absolute;
|
||||
align-self: center;
|
||||
background-color: orangered;
|
||||
font-size: 16px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.privacy {
|
||||
margin-top: 10px;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
top: 45%;
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
align-self: center;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.privacy-checkbox {
|
||||
transform: scale(0.65);
|
||||
}
|
||||
|
||||
.privacy-text {
|
||||
margin-top: 4px;
|
||||
color: #007aff;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.privacy-normal-text {
|
||||
margin-top: 4px;
|
||||
color: gray;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.other {
|
||||
bottom: 7%;
|
||||
transform: translateY(50%);
|
||||
position: absolute;
|
||||
align-self: center;
|
||||
font-size: 14px;
|
||||
color: var(--text-color);
|
||||
}
|
||||
</style>
|
||||
在新工单中引用
屏蔽一个用户