登录、注册页样式修改
This commit is contained in:
@@ -60,14 +60,18 @@
|
||||
@input="(e: any) => account = e.detail.value"
|
||||
/>
|
||||
</view>
|
||||
<view class="field">
|
||||
<view class="field password-field">
|
||||
<input
|
||||
class="input"
|
||||
type="password"
|
||||
:type="isPasswordVisible ? 'text' : 'password'"
|
||||
placeholder="密码"
|
||||
:value="password"
|
||||
@input="(e: any) => password = e.detail.value"
|
||||
/>
|
||||
<view class="eye-btn" @click="isPasswordVisible = !isPasswordVisible">
|
||||
<!-- 睁眼表示可见(type='text'), 闭眼表示不可见(type='password') -->
|
||||
<text class="eye-icon">{{ isPasswordVisible ? '👁️' : '🙈' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -163,6 +167,7 @@ const loginType = ref<number>(0)
|
||||
const account = ref<string>('')
|
||||
const password = ref<string>('')
|
||||
const captcha = ref<string>('')
|
||||
const isPasswordVisible = ref<boolean>(false)
|
||||
|
||||
const isLoading = ref<boolean>(false)
|
||||
|
||||
@@ -170,32 +175,38 @@ const isLoading = ref<boolean>(false)
|
||||
* 【核心函数】:登录成功后,多条件校验是否为商家角色
|
||||
* 优先级: session_uid (auth_id) -> id -> normalized email
|
||||
*/
|
||||
const checkMerchantAccess = async (uid: string, rawEmail: string) : Promise<boolean> => {
|
||||
const checkMerchantAccess = async (uid: string, rawEmail: string) : Promise<string | null> => {
|
||||
const email = rawEmail.trim().toLowerCase()
|
||||
console.log(`🔍 开始校验商家端角色 -> UID: ${uid}, Email: ${email}`)
|
||||
|
||||
try {
|
||||
// 1. 尝试按 auth_id 查询
|
||||
let res = await supa.from('ak_users').select('role').eq('auth_id', uid).execute()
|
||||
let res = await supa.from('ak_users').select('id, role').eq('auth_id', uid).execute()
|
||||
let dataArray = res.data
|
||||
if (Array.isArray(dataArray) && dataArray.length > 0) {
|
||||
const role = (dataArray[0] as UTSJSONObject).getString('role')
|
||||
const obj = dataArray[0] as UTSJSONObject
|
||||
const role = obj.getString('role')
|
||||
const id = obj.getString('id')
|
||||
console.log('✅ 按 auth_id 匹配成功,role:', role)
|
||||
return role === 'merchant'
|
||||
if (role === 'merchant' && id != null) return id
|
||||
return null
|
||||
}
|
||||
|
||||
// 2. 尝试按 id 查询 (兼容老数据)
|
||||
res = await supa.from('ak_users').select('role').eq('id', uid).execute()
|
||||
res = await supa.from('ak_users').select('id, role').eq('id', uid).execute()
|
||||
dataArray = res.data
|
||||
if (Array.isArray(dataArray) && dataArray.length > 0) {
|
||||
const role = (dataArray[0] as UTSJSONObject).getString('role')
|
||||
const obj = dataArray[0] as UTSJSONObject
|
||||
const role = obj.getString('role')
|
||||
const id = obj.getString('id')
|
||||
console.log('✅ 按 id 匹配成功,role:', role)
|
||||
return role === 'merchant'
|
||||
if (role === 'merchant' && id != null) return id
|
||||
return null
|
||||
}
|
||||
|
||||
// 3. 尝试按 email 兜底查询
|
||||
if (email !== '') {
|
||||
res = await supa.from('ak_users').select('role').eq('email', email).execute()
|
||||
res = await supa.from('ak_users').select('id, role').eq('email', email).execute()
|
||||
dataArray = res.data
|
||||
|
||||
if (Array.isArray(dataArray) && dataArray.length > 0) {
|
||||
@@ -203,9 +214,12 @@ const checkMerchantAccess = async (uid: string, rawEmail: string) : Promise<bool
|
||||
if (dataArray.length > 1) {
|
||||
console.error('⚠️ 警告: 按 email 查到多条 ak_users 记录,取第一条校验。Email:', email)
|
||||
}
|
||||
const role = (dataArray[0] as UTSJSONObject).getString('role')
|
||||
const obj = dataArray[0] as UTSJSONObject
|
||||
const role = obj.getString('role')
|
||||
const id = obj.getString('id')
|
||||
console.log('✅ 按 email 匹配成功,role:', role)
|
||||
return role === 'merchant'
|
||||
if (role === 'merchant' && id != null) return id
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,6 +350,7 @@ const handleLogin = async () => {
|
||||
class_id: ''
|
||||
} as UserProfile
|
||||
setUserProfile(adminProfile)
|
||||
uni.setStorageSync('merchant_id', 'admin') // mock
|
||||
|
||||
uni.showToast({ title: '管理员登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
@@ -385,12 +400,15 @@ const handleLogin = async () => {
|
||||
const sessionUser = result.user
|
||||
let sessionUid = sessionUser?.getString('id') ?? ''
|
||||
|
||||
const isMerchant = await checkMerchantAccess(sessionUid, account.value)
|
||||
if (!isMerchant) {
|
||||
const merchantId = await checkMerchantAccess(sessionUid, account.value)
|
||||
if (merchantId == null) {
|
||||
await supa.signOut()
|
||||
logout()
|
||||
throw new Error('您还没有注册商家端账户,快去注册一个')
|
||||
}
|
||||
|
||||
// 存入商家ID
|
||||
uni.setStorageSync('merchant_id', merchantId)
|
||||
} else {
|
||||
uni.showToast({ title: '手机号密码登录功能开发中', icon: 'none' })
|
||||
return
|
||||
@@ -619,6 +637,24 @@ const handleQQLogin = () => uni.showToast({ title: 'QQ登录开发中', icon: 'n
|
||||
/* Form */
|
||||
.form{ margin-top: 10px; }
|
||||
.field{ margin-bottom: 14px; }
|
||||
.password-field {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
.eye-btn {
|
||||
position: absolute;
|
||||
right: 14px;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 4px;
|
||||
}
|
||||
.eye-icon {
|
||||
font-size: 18px;
|
||||
}
|
||||
.input{
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
|
||||
Reference in New Issue
Block a user