feat: 未登录状态调整
This commit is contained in:
@@ -8,9 +8,9 @@
|
||||
>
|
||||
<button
|
||||
class="reset-btn more-tips-item-title"
|
||||
open-type="getPhoneNumber"
|
||||
@getphonenumber="onLogin"
|
||||
@click="sendReply(item)"
|
||||
:open-type="needAuth ? 'getPhoneNumber' : ''"
|
||||
@getphonenumber="handleGetPhoneNumber"
|
||||
@click="handleClick(item)"
|
||||
>
|
||||
{{ item }}
|
||||
</button>
|
||||
@@ -20,10 +20,12 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { defineProps } from "vue";
|
||||
import { defineProps, ref } from "vue";
|
||||
import { onLogin, checkToken } from "@/hooks/useGoLogin";
|
||||
|
||||
const emits = defineEmits(["replySent"]);
|
||||
const needAuth = ref(true);
|
||||
let pendingText = "";
|
||||
|
||||
defineProps({
|
||||
itemList: {
|
||||
@@ -45,42 +47,38 @@ const sendReply = (text) => {
|
||||
emits("replySent", text); // 向父组件传递数据
|
||||
});
|
||||
};
|
||||
|
||||
// 处理点击事件
|
||||
const handleClick = (text) => {
|
||||
// 检查本地token
|
||||
const token = uni.getStorageSync("token");
|
||||
|
||||
if (token) {
|
||||
// 情况2:token有值,直接发送回复,此时open-type为空字符串
|
||||
needAuth.value = false;
|
||||
sendReply(text);
|
||||
} else {
|
||||
// 情况1:token没有值,设置需要授权状态,触发微信授权
|
||||
needAuth.value = true;
|
||||
pendingText = text;
|
||||
// 由于open-type已经动态绑定为'getPhoneNumber',点击会自动触发授权
|
||||
}
|
||||
};
|
||||
|
||||
// 处理微信授权回调
|
||||
const handleGetPhoneNumber = async (e) => {
|
||||
await onLogin(e);
|
||||
|
||||
// 授权成功后发送之前存储的文本
|
||||
if (pendingText) {
|
||||
sendReply(pendingText);
|
||||
pendingText = "";
|
||||
}
|
||||
|
||||
needAuth.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.more-tips {
|
||||
width: 100%;
|
||||
|
||||
&-scroll {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
overflow-x: auto;
|
||||
white-space: nowrap;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
padding-bottom: 12px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.more-tips-item {
|
||||
border-radius: 8px;
|
||||
margin: 4px;
|
||||
box-shadow: 0 2px 5px 0px rgba(0, 0, 0, 0.1);
|
||||
background-color: #ffffff;
|
||||
padding: 2px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-shrink: 0;
|
||||
white-space: nowrap;
|
||||
|
||||
.more-tips-item-title {
|
||||
font-family: PingFang SC, PingFang SC;
|
||||
font-weight: 500;
|
||||
font-size: 12px;
|
||||
color: #00a6ff;
|
||||
line-height: 24px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
@import "./styles/ChatMoreTips.scss";
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user