Add new components for login and comment functionality
This commit is contained in:
92
components/comment-section/index.vue
Normal file
92
components/comment-section/index.vue
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mt-30px">
|
||||||
|
<div class="h-48px w-938px rounded-1px bg-[#F8F8F8] pl-10px text-16px text-[#333333] font-normal line-height-50px"> 共有{{ result.total || 0 }}条评论 </div>
|
||||||
|
<div v-for="item in result.list" :key="item.id" class="mt-20px border-b-1px border-b-[#eee] border-b-solid pb-14px">
|
||||||
|
<div class="flex items-start">
|
||||||
|
<el-avatar :src="item.creatorInfo.avatar" alt="" srcset="" class="h-50px w-49px rounded-full" />
|
||||||
|
<div class="flex-1 pl-8px">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<div class="relative top-4px text-14px!">{{ item.creatorInfo.nickName }}</div>
|
||||||
|
<div class="text-12px text-[#999999] font-normal">发表时间:{{ dayjs(item.creatorInfo.createTime).format('YYYY-MM-DD HH:mm:ss') }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-10px box-border rd-4px bg-[#f8f8f8] px-18px py-10px text-14px text-[#999999] font-normal">{{ item.content }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- 添加element-plus分页 -->
|
||||||
|
<el-pagination
|
||||||
|
v-model:current-page="query.pageNo"
|
||||||
|
:page-size="query.pageSize"
|
||||||
|
layout="prev, pager, next"
|
||||||
|
:total="result.total"
|
||||||
|
class="mt-10px"
|
||||||
|
@current-change="handleCurrentChange"
|
||||||
|
/>
|
||||||
|
<el-input v-model="commentContent" type="textarea" :rows="6" placeholder="请输入内容" class="mt-20px w-100%"></el-input>
|
||||||
|
<div>
|
||||||
|
<el-button type="primary" class="mt-10px h-40px w-101px rounded-4px text-16px text-[#FFFFFF] font-bold" @click="handleCreateComment">
|
||||||
|
发表评论
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch } from 'vue'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
import { getCommentList, createComment } from '@/api/drawe-detail'
|
||||||
|
import type { PageResultProjectCommentResVO } from '@/api/drawe-detail/types'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
relationId: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
projectId: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const query = ref({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = ref<PageResultProjectCommentResVO>({
|
||||||
|
list: [],
|
||||||
|
total: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
const commentContent = ref('')
|
||||||
|
const handleCurrentChange = (pageNo: number) => {
|
||||||
|
query.value.pageNo = pageNo
|
||||||
|
handleGetCommentList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取评论列表
|
||||||
|
const handleGetCommentList = async () => {
|
||||||
|
const res = await getCommentList({ relationId: props.relationId, pageNum: query.value.pageNo, pageSize: query.value.pageSize })
|
||||||
|
if (res.code === 0) {
|
||||||
|
result.value.list = res.data.list
|
||||||
|
result.value.total = res.data.total
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发表评论
|
||||||
|
const handleCreateComment = async () => {
|
||||||
|
const res = await createComment({ relationId: props.relationId, content: commentContent.value, projectId: props.projectId })
|
||||||
|
if (res.code === 0) {
|
||||||
|
commentContent.value = ''
|
||||||
|
query.value.pageNo = 1
|
||||||
|
handleGetCommentList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.relationId,
|
||||||
|
() => {
|
||||||
|
handleGetCommentList()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
</script>
|
||||||
40
components/kl-card-detail/index.vue
Normal file
40
components/kl-card-detail/index.vue
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<template>
|
||||||
|
<div class="box-border w-100% flex cursor-pointer rounded-4px bg-[#F4F5F6] pa-15px">
|
||||||
|
<div>
|
||||||
|
<el-image :src="props.cardItemInfo.iconUrl" class="h-90px w-90px rounded-4px" fit="cover"></el-image>
|
||||||
|
</div>
|
||||||
|
<div class="ml-9px box-border">
|
||||||
|
<div class="mt-8px flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<div class="title text-16px text-[#333333] font-normal">{{ props.cardItemInfo.title }}</div>
|
||||||
|
<div class="description mt-14px text-14px text-[#999999] font-normal">{{ props.cardItemInfo.description }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { PropType } from 'vue'
|
||||||
|
import type { ProjectDrawPageRespVO } from '@/api/home/type'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
cardItemInfo: {
|
||||||
|
type: Object as PropType<ProjectDrawPageRespVO>,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
ellipsisNum: {
|
||||||
|
type: Number,
|
||||||
|
default: 1,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.title {
|
||||||
|
@include ellipsis(1);
|
||||||
|
}
|
||||||
|
.description {
|
||||||
|
@include ellipsis(v-bind(ellipsisNum));
|
||||||
|
}
|
||||||
|
</style>
|
||||||
61
components/kl-card-picture/index.vue
Normal file
61
components/kl-card-picture/index.vue
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mb-20px w-100% cursor-pointer overflow-hidden border border-[#EEEEEE] rounded-10px border-solid bg-[#FFFFFF]" @click="handleClick">
|
||||||
|
<div>
|
||||||
|
<el-image :src="props.itemInfo.iconUrl" class="h-216px w-100%" fit="cover"></el-image>
|
||||||
|
</div>
|
||||||
|
<div class="box-border p-16px">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<div class="title mr-38px text-16px text-[#333333] font-bold">{{ props.itemInfo.title }}</div>
|
||||||
|
<div class="mt-8px text-15px text-[#999999] font-normal">by {{ props.itemInfo?.ownedUserIdInfo?.nickName }}</div>
|
||||||
|
</div>
|
||||||
|
<div><img :src="props.itemInfo?.ownedUserIdInfo?.avatar" alt="" srcset="" class="h-40px w-40px rd-50%" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-24px flex items-center justify-between">
|
||||||
|
<div class="flex items-center justify-between text-14px text-[#666666] font-normal">
|
||||||
|
<div class="mr-9px flex items-center">
|
||||||
|
<img src="@/assets/images/look.png" alt="" srcset="" class="mr-2px h-17px" />
|
||||||
|
<span class="color-#666">{{ props.itemInfo.previewPoint }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="mr-9px flex items-center">
|
||||||
|
<img src="@/assets/images/add.png" alt="" srcset="" class="mr-2px h-22px" />
|
||||||
|
<span class="color-#666">{{ props.itemInfo.hotPoint }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center">
|
||||||
|
<img src="@/assets/images/chat.png" alt="" srcset="" class="mr-4px h-17px" />
|
||||||
|
<span class="color-#666">{{ props.itemInfo.commentsPoint }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="h-30px w-90px cursor-pointer border border-[#1A65FF] rounded-15px border-solid text-center line-height-30px"
|
||||||
|
><span class="text-14px text-[#1A65FF] font-normal">查看详情</span></div
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { PropType } from 'vue'
|
||||||
|
import type { pageRes } from '@/api/upnew/types'
|
||||||
|
const props = defineProps({
|
||||||
|
itemInfo: {
|
||||||
|
type: Object as PropType<pageRes['list'][0]>,
|
||||||
|
default: () => {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
console.log(props.itemInfo)
|
||||||
|
|
||||||
|
// 跳转到下载详情页 并且是单独开标签
|
||||||
|
window.open(`/down-drawe-detail?id=${props.itemInfo.id}`, '_blank') // 修改为在新窗口打开
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.title {
|
||||||
|
@include ellipsis(1);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
29
components/kl-email/index.ts
Normal file
29
components/kl-email/index.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { createApp, ref } from 'vue'
|
||||||
|
import GlobalPopup from './index.vue'
|
||||||
|
|
||||||
|
const popupInstance = ref()
|
||||||
|
|
||||||
|
const openLoginEmail = () => {
|
||||||
|
if (!popupInstance.value) {
|
||||||
|
const app = createApp(GlobalPopup, {
|
||||||
|
visible: true,
|
||||||
|
onClose: () => {
|
||||||
|
closeLoginEmail()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const container = document.createElement('div')
|
||||||
|
document.body.appendChild(container)
|
||||||
|
popupInstance.value = app.mount(container)
|
||||||
|
}
|
||||||
|
// popupInstance.value.$el.innerHTML = content
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeLoginEmail = () => {
|
||||||
|
if (popupInstance.value) {
|
||||||
|
popupInstance.value.$el.parentNode.removeChild(popupInstance.value.$el)
|
||||||
|
popupInstance.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { openLoginEmail, closeLoginEmail }
|
||||||
456
components/kl-email/index.vue
Normal file
456
components/kl-email/index.vue
Normal file
@ -0,0 +1,456 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div v-if="visible" class="popup-overlay">
|
||||||
|
<div class="popup-content">
|
||||||
|
<div class="login-container relative">
|
||||||
|
<el-icon class="absolute right-0 top-0 cursor-pointer" @click="onClose()"><Close /></el-icon>
|
||||||
|
<!-- 左侧插图 -->
|
||||||
|
<div class="login-left">
|
||||||
|
<img src="@/assets/images/login-illustration.png" alt="login" class="login-img" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 右侧登录表单 -->
|
||||||
|
<div class="login-right">
|
||||||
|
<h2 class="login-title">邮箱登录</h2>
|
||||||
|
|
||||||
|
<!-- 登录方式切换 -->
|
||||||
|
<div class="login-tabs">
|
||||||
|
<!-- <span :class="['tab-item', activeTab === 'account' ? 'active' : '']" @click="activeTab = 'account'"> 密码登录 </span> -->
|
||||||
|
<!-- <span :class="['tab-item', activeTab === 'verify' ? 'active' : '']" @click="activeTab = 'verify'"> 邮箱登录 </span> -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 登录表单 -->
|
||||||
|
<el-form ref="formRef" :model="loginForm" :rules="rules" class="login-form">
|
||||||
|
<template v-if="activeTab === 'account'">
|
||||||
|
<el-form-item prop="mobile">
|
||||||
|
<el-input v-model="loginForm.mobile" placeholder="请输入用户名" :prefix-icon="User" class="w-322px!" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item prop="password">
|
||||||
|
<el-input v-model="loginForm.password" placeholder="请输入密码" :prefix-icon="Lock" type="password" />
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- 验证码登录 -->
|
||||||
|
<template v-else>
|
||||||
|
<el-form-item prop="email">
|
||||||
|
<el-input v-model="loginForm.email" placeholder="请输入邮箱" class="w-322px!" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item prop="code">
|
||||||
|
<div class="verify-code-input">
|
||||||
|
<el-input v-model="loginForm.code" placeholder="请输入验证码" />
|
||||||
|
<el-button type="primary" class="verify-code-btn" :disabled="counting > 0" @click="handleSendCode">
|
||||||
|
{{ counting > 0 ? `${counting}s后重新获取` : '获取验证码' }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- 登录按钮 -->
|
||||||
|
<el-button type="primary" class="login-button" :loading="loading" @click="handleLogin"> 登录 </el-button>
|
||||||
|
|
||||||
|
<!-- 用户协议 -->
|
||||||
|
<div class="agreement">
|
||||||
|
<el-checkbox v-model="loginForm.agreement"> 我已阅读并同意<span class="link">《多多用户协议》</span> </el-checkbox>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 第三方登录 -->
|
||||||
|
<div class="third-party-login">
|
||||||
|
<div class="login-icons" @click="handleLoginQQ">
|
||||||
|
<img src="@/assets/images/qq-v2.png" alt="QQ登录" class="login-icon" />
|
||||||
|
<div class="icon-text">QQ登录</div>
|
||||||
|
</div>
|
||||||
|
<div class="login-icons" @click="handleLoginWechat">
|
||||||
|
<img src="@/assets/images/weixin-v2.png" alt="微信登录" class="login-icon" />
|
||||||
|
<div class="icon-text">微信登录</div>
|
||||||
|
</div>
|
||||||
|
<div class="login-icons" @click="goToLogin">
|
||||||
|
<img src="@/assets/images/email-v2.png" alt="邮箱登录" class="login-icon" />
|
||||||
|
<div class="icon-text">账号登录</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 注册入口 -->
|
||||||
|
<div class="register-link"> 没有账号?<span class="link" @click="handleRegister">点击注册</span> </div>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, reactive, nextTick } from 'vue'
|
||||||
|
import { User, Lock, Close } from '@element-plus/icons-vue'
|
||||||
|
import type { FormInstance } from 'element-plus'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { login, sendEmailCode, loginByEmail } from '@/api/login/index'
|
||||||
|
import refreshToken from '@/utils/RefreshToken'
|
||||||
|
import { handleLoginQQ, handleLoginWechat, generateRandomString } from '@/utils/login'
|
||||||
|
import useUserStore from '@/store/user'
|
||||||
|
const userStore = useUserStore()
|
||||||
|
const { $openRegister, $openLogin } = useNuxtApp()
|
||||||
|
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
onClose: {
|
||||||
|
type: Function,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
|
active: {
|
||||||
|
type: String,
|
||||||
|
default: 'verify',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const activeTab = ref(props.active)
|
||||||
|
const counting = ref(0)
|
||||||
|
const formRef = ref<FormInstance>()
|
||||||
|
|
||||||
|
const loginForm = reactive({
|
||||||
|
mobile: '',
|
||||||
|
password: '',
|
||||||
|
email: '',
|
||||||
|
code: '',
|
||||||
|
agreement: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
const rules = {
|
||||||
|
mobile: {
|
||||||
|
required: true,
|
||||||
|
message: '请输入用户名',
|
||||||
|
trigger: 'blur',
|
||||||
|
},
|
||||||
|
password: {
|
||||||
|
required: true,
|
||||||
|
message: '请输入密码',
|
||||||
|
trigger: 'blur',
|
||||||
|
},
|
||||||
|
email: [
|
||||||
|
{ required: true, message: '请输入邮箱', trigger: 'blur' },
|
||||||
|
// { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' },
|
||||||
|
],
|
||||||
|
code: [
|
||||||
|
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||||
|
{ len: 6, message: '验证码长度应为6位', trigger: 'blur' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRegister = () => {
|
||||||
|
props.onClose()
|
||||||
|
nextTick(() => {
|
||||||
|
$openRegister()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 发送验证码
|
||||||
|
const handleSendCode = async () => {
|
||||||
|
if (counting.value > 0) return
|
||||||
|
if (!loginForm.email) {
|
||||||
|
ElMessage.warning('请输入邮箱')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 这里添加发送验证码的接口调用
|
||||||
|
// TODO: 调用发送验证码接口
|
||||||
|
const res = await sendEmailCode({
|
||||||
|
email: loginForm.email,
|
||||||
|
})
|
||||||
|
if (res.code !== 0) return
|
||||||
|
if (res.code === 0) {
|
||||||
|
ElMessage.success('验证码发送成功')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始倒计时
|
||||||
|
counting.value = 60
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
counting.value--
|
||||||
|
if (counting.value <= 0) {
|
||||||
|
clearInterval(timer)
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const loading = ref(false)
|
||||||
|
const handleLogin = async () => {
|
||||||
|
if (!loginForm.agreement) {
|
||||||
|
ElMessage.warning('请先同意用户协议')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 处理登录逻辑
|
||||||
|
// 根据不同登录方式处理登录逻辑
|
||||||
|
if (activeTab.value === 'account') {
|
||||||
|
await formRef.value?.validate()
|
||||||
|
// 账号密码登录逻辑
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const res = await login(loginForm)
|
||||||
|
const { code, data, msg } = res
|
||||||
|
if (code !== 0) return ElMessage.error(msg)
|
||||||
|
refreshToken.setToken(data.accessToken, data.refreshToken)
|
||||||
|
refreshToken.setUserId(data.userId.toString())
|
||||||
|
refreshToken.setUserName(loginForm.mobile)
|
||||||
|
userStore.setToken(data.accessToken)
|
||||||
|
userStore.setUserId(data.userId.toString())
|
||||||
|
userStore.setUserName(loginForm.mobile)
|
||||||
|
userStore.setRefreshToken(data.refreshToken)
|
||||||
|
ElMessage.success('登录成功')
|
||||||
|
props.onClose()
|
||||||
|
// 获取用户信息
|
||||||
|
userStore.getUserInfo()
|
||||||
|
// 登录成功
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 验证码登录逻辑
|
||||||
|
try {
|
||||||
|
await formRef.value?.validate()
|
||||||
|
// TODO: 调用注册接口
|
||||||
|
loading.value = true
|
||||||
|
const res = await loginByEmail({
|
||||||
|
email: loginForm.email,
|
||||||
|
code: loginForm.code,
|
||||||
|
})
|
||||||
|
if (res.code === 0) {
|
||||||
|
if (!res.data?.accessToken) {
|
||||||
|
// 没绑定手机 弹出手机登录界面
|
||||||
|
ElMessage.error('因你未绑定手机号,请先绑定手机号')
|
||||||
|
props.onClose()
|
||||||
|
setTimeout(() => {
|
||||||
|
$openLogin('verify', loginForm.email, 36, generateRandomString(16))
|
||||||
|
}, 1200)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const data = res.data
|
||||||
|
refreshToken.setToken(data.accessToken, data.refreshToken)
|
||||||
|
refreshToken.setUserId(data.userId.toString())
|
||||||
|
refreshToken.setUserName(loginForm.email)
|
||||||
|
userStore.setToken(data.accessToken)
|
||||||
|
userStore.setUserId(data.userId.toString())
|
||||||
|
userStore.setUserName(loginForm.email)
|
||||||
|
userStore.setRefreshToken(data.refreshToken)
|
||||||
|
ElMessage.success('登录成功')
|
||||||
|
props.onClose()
|
||||||
|
// 获取用户信息
|
||||||
|
userStore.getUserInfo()
|
||||||
|
// 登录成功
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 跳转到登录
|
||||||
|
const goToLogin = () => {
|
||||||
|
props.onClose()
|
||||||
|
// TODO: 触发切换到登录页面的事件
|
||||||
|
// emit('switch-to-login')
|
||||||
|
$openLogin()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.login-dialog {
|
||||||
|
.el-dialog {
|
||||||
|
border-radius: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-dialog__header {
|
||||||
|
// margin: 0;
|
||||||
|
// padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-dialog__body {
|
||||||
|
padding: 0px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.popup-overlay {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 10;
|
||||||
|
.popup-content {
|
||||||
|
background-color: white;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.login-container {
|
||||||
|
display: flex;
|
||||||
|
height: 508px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: #f9faff;
|
||||||
|
width: 480px;
|
||||||
|
|
||||||
|
.login-img {
|
||||||
|
width: 438px;
|
||||||
|
height: 258px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-right {
|
||||||
|
padding: 22px 25px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-title {
|
||||||
|
font-size: 20px;
|
||||||
|
color: #333;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-tabs {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
|
||||||
|
.tab-item {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
padding: 0 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
color: #1677ff;
|
||||||
|
font-weight: 500;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
bottom: -4px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
width: 20px;
|
||||||
|
height: 2px;
|
||||||
|
background: #1677ff;
|
||||||
|
border-radius: 1px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// &:first-child::after {
|
||||||
|
// content: '';
|
||||||
|
// position: absolute;
|
||||||
|
// right: 0;
|
||||||
|
// top: 50%;
|
||||||
|
// transform: translateY(-50%);
|
||||||
|
// width: 1px;
|
||||||
|
// height: 14px;
|
||||||
|
// background: #ddd;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form {
|
||||||
|
.el-input {
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-input__wrapper) {
|
||||||
|
background: #f5f5f5;
|
||||||
|
border: none;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-button {
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
margin-top: 24px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agreement {
|
||||||
|
margin: 16px 0;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
|
||||||
|
.link {
|
||||||
|
color: #1677ff;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.third-party-login {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 40px;
|
||||||
|
margin-top: 30px;
|
||||||
|
|
||||||
|
.login-icons {
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
.login-icon {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-text {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-link {
|
||||||
|
text-align: right;
|
||||||
|
margin-top: 20px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
|
||||||
|
.link {
|
||||||
|
color: #1677ff;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.verify-code-input {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
|
||||||
|
.el-input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.verify-code-btn {
|
||||||
|
width: 120px;
|
||||||
|
height: 40px;
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
color: #999;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
border-color: #dcdfe6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保验证码按钮文字不换行
|
||||||
|
:deep(.verify-code-btn) {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
36
components/kl-form-title/index.vue
Normal file
36
components/kl-form-title/index.vue
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<template>
|
||||||
|
<div class="form-title" :style="{ background: bgColor }">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
defineProps({
|
||||||
|
/** 背景色 */
|
||||||
|
bgColor: {
|
||||||
|
type: String,
|
||||||
|
default: '#f7f9fc',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.form-title {
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 14px;
|
||||||
|
padding: 8px 0;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
color: #23272e;
|
||||||
|
font-weight: 500;
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
background-color: #1e6ffa;
|
||||||
|
width: 3px;
|
||||||
|
height: 13px;
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 8px;
|
||||||
|
position: relative;
|
||||||
|
top: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
33
components/kl-login/index.ts
Normal file
33
components/kl-login/index.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { createApp, ref } from 'vue'
|
||||||
|
import GlobalPopup from './index.vue'
|
||||||
|
|
||||||
|
const popupInstance = ref()
|
||||||
|
|
||||||
|
const openLogin = (active = 'account', code = '', type = '', state = '') => {
|
||||||
|
if (!popupInstance.value) {
|
||||||
|
const app = createApp(GlobalPopup, {
|
||||||
|
visible: true,
|
||||||
|
active: active,
|
||||||
|
code: code,
|
||||||
|
type: type,
|
||||||
|
state: state,
|
||||||
|
onClose: () => {
|
||||||
|
closeLogin()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const container = document.createElement('div')
|
||||||
|
document.body.appendChild(container)
|
||||||
|
popupInstance.value = app.mount(container)
|
||||||
|
}
|
||||||
|
// popupInstance.value.$el.innerHTML = content
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeLogin = () => {
|
||||||
|
if (popupInstance.value) {
|
||||||
|
popupInstance.value.$el.parentNode.removeChild(popupInstance.value.$el)
|
||||||
|
popupInstance.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { openLogin, closeLogin }
|
||||||
471
components/kl-login/index.vue
Normal file
471
components/kl-login/index.vue
Normal file
@ -0,0 +1,471 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div v-if="visible" class="popup-overlay">
|
||||||
|
<div class="popup-content">
|
||||||
|
<div class="login-container relative">
|
||||||
|
<el-icon class="absolute right-0 top-0 cursor-pointer" @click="onClose()"><Close /></el-icon>
|
||||||
|
<!-- 左侧插图 -->
|
||||||
|
<div class="login-left">
|
||||||
|
<img src="@/assets/images/login-illustration.png" alt="login" class="login-img" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 右侧登录表单 -->
|
||||||
|
<div class="login-right">
|
||||||
|
<h2 class="login-title">登录</h2>
|
||||||
|
|
||||||
|
<!-- 登录方式切换 -->
|
||||||
|
<div class="login-tabs">
|
||||||
|
<span :class="['tab-item', activeTab === 'account' ? 'active' : '']" @click="activeTab = 'account'"> 密码登录 </span>
|
||||||
|
<span :class="['tab-item', activeTab === 'verify' ? 'active' : '']" @click="activeTab = 'verify'"> 验证码登录 </span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 登录表单 -->
|
||||||
|
<el-form ref="formRef" :model="loginForm" :rules="rules" class="login-form">
|
||||||
|
<template v-if="activeTab === 'account'">
|
||||||
|
<el-form-item prop="mobile">
|
||||||
|
<el-input v-model="loginForm.mobile" placeholder="请输入用户名" :prefix-icon="User" class="w-322px!" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item prop="password">
|
||||||
|
<el-input v-model="loginForm.password" placeholder="请输入密码" :prefix-icon="Lock" type="password" />
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- 验证码登录 -->
|
||||||
|
<template v-else>
|
||||||
|
<el-form-item prop="phone">
|
||||||
|
<el-input v-model="loginForm.phone" placeholder="请输入手机号" class="w-322px!" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item prop="code">
|
||||||
|
<div class="verify-code-input">
|
||||||
|
<el-input v-model="loginForm.code" placeholder="请输入验证码" />
|
||||||
|
<el-button type="primary" class="verify-code-btn" :disabled="counting > 0" @click="handleSendCode">
|
||||||
|
{{ counting > 0 ? `${counting}s后重新获取` : '获取验证码' }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- 登录按钮 -->
|
||||||
|
<el-button type="primary" class="login-button" :loading="loading" @click="handleLogin"> 登录 </el-button>
|
||||||
|
|
||||||
|
<!-- 用户协议 -->
|
||||||
|
<div class="agreement">
|
||||||
|
<el-checkbox v-model="loginForm.agreement"> 我已阅读并同意<span class="link">《多多用户协议》</span> </el-checkbox>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 第三方登录 -->
|
||||||
|
<div class="third-party-login">
|
||||||
|
<div class="login-icons" @click="handleLoginQQ">
|
||||||
|
<img src="@/assets/images/qq-v2.png" alt="QQ登录" class="login-icon" />
|
||||||
|
<div class="icon-text">QQ登录</div>
|
||||||
|
</div>
|
||||||
|
<div class="login-icons" @click="handleLoginWechat">
|
||||||
|
<img src="@/assets/images/weixin-v2.png" alt="微信登录" class="login-icon" />
|
||||||
|
<div class="icon-text">微信登录</div>
|
||||||
|
</div>
|
||||||
|
<div class="login-icons" @click="handleLoginEmail">
|
||||||
|
<img src="@/assets/images/email-v2.png" alt="邮箱登录" class="login-icon" />
|
||||||
|
<div class="icon-text">邮箱登录</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 注册入口 -->
|
||||||
|
<div class="register-link"> 没有账号?<span class="link" @click="handleRegister">点击注册</span> </div>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, reactive, nextTick } from 'vue'
|
||||||
|
import { User, Lock, Close } from '@element-plus/icons-vue'
|
||||||
|
import type { FormInstance } from 'element-plus'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { login, loginByMobile } from '@/api/login/index'
|
||||||
|
import { sendSms } from '@/api/common/index'
|
||||||
|
import { refreshToken as REFRESHTOKEN } from '@/utils/axios'
|
||||||
|
import { handleLoginQQ, handleLoginWechat } from '@/utils/login'
|
||||||
|
import useUserStore from '@/store/user'
|
||||||
|
const { $openRegister, $openLogin, $openLoginEmail } = useNuxtApp()
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
onClose: {
|
||||||
|
type: Function,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
|
active: {
|
||||||
|
type: String,
|
||||||
|
default: 'account',
|
||||||
|
},
|
||||||
|
/** code */
|
||||||
|
code: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
/** 区分 */
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
state: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const activeTab = ref(props.active)
|
||||||
|
const counting = ref(0)
|
||||||
|
const formRef = ref<FormInstance>()
|
||||||
|
|
||||||
|
const loginForm = reactive({
|
||||||
|
mobile: '',
|
||||||
|
password: '',
|
||||||
|
phone: '',
|
||||||
|
code: '',
|
||||||
|
agreement: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
const rules = {
|
||||||
|
mobile: {
|
||||||
|
required: true,
|
||||||
|
message: '请输入用户名',
|
||||||
|
trigger: 'blur',
|
||||||
|
},
|
||||||
|
password: {
|
||||||
|
required: true,
|
||||||
|
message: '请输入密码',
|
||||||
|
trigger: 'blur',
|
||||||
|
},
|
||||||
|
phone: [
|
||||||
|
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||||
|
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' },
|
||||||
|
],
|
||||||
|
code: [
|
||||||
|
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||||
|
{ len: 6, message: '验证码长度应为6位', trigger: 'blur' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRegister = () => {
|
||||||
|
props.onClose()
|
||||||
|
nextTick(() => {
|
||||||
|
$openRegister()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 发送验证码
|
||||||
|
const handleSendCode = async () => {
|
||||||
|
if (counting.value > 0) return
|
||||||
|
if (!loginForm.phone) {
|
||||||
|
ElMessage.warning('请输入手机号')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 这里添加手机号验证逻辑
|
||||||
|
const phoneReg = /^1[3-9]\d{9}$/
|
||||||
|
if (!phoneReg.test(loginForm.phone)) {
|
||||||
|
ElMessage.warning('请输入正确的手机号')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 这里添加发送验证码的接口调用
|
||||||
|
// TODO: 调用发送验证码接口
|
||||||
|
const res = await sendSms({
|
||||||
|
mobile: loginForm.phone,
|
||||||
|
scene: 1, // 场景值,根据实际情况设置
|
||||||
|
})
|
||||||
|
if (res.code !== 0) return
|
||||||
|
if (res.code === 0) {
|
||||||
|
ElMessage.success('验证码发送成功')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始倒计时
|
||||||
|
counting.value = 60
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
counting.value--
|
||||||
|
if (counting.value <= 0) {
|
||||||
|
clearInterval(timer)
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const loading = ref(false)
|
||||||
|
const handleLogin = async () => {
|
||||||
|
if (!loginForm.agreement) {
|
||||||
|
ElMessage.warning('请先同意用户协议')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 处理登录逻辑
|
||||||
|
// 根据不同登录方式处理登录逻辑
|
||||||
|
if (activeTab.value === 'account') {
|
||||||
|
await formRef.value?.validate()
|
||||||
|
// 账号密码登录逻辑
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const res = await login(loginForm)
|
||||||
|
const { code, data, msg } = res
|
||||||
|
if (code !== 0) return ElMessage.error(msg)
|
||||||
|
REFRESHTOKEN.setToken(data.accessToken, data.refreshToken)
|
||||||
|
REFRESHTOKEN.setUserId(data.userId.toString())
|
||||||
|
REFRESHTOKEN.setUserName(loginForm.mobile)
|
||||||
|
userStore.setToken(data.accessToken)
|
||||||
|
userStore.setUserId(data.userId.toString())
|
||||||
|
userStore.setUserName(loginForm.mobile)
|
||||||
|
userStore.setRefreshToken(data.refreshToken)
|
||||||
|
ElMessage.success('登录成功')
|
||||||
|
props.onClose()
|
||||||
|
// 获取用户信息
|
||||||
|
userStore.getUserInfo()
|
||||||
|
// 登录成功
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 验证码登录逻辑
|
||||||
|
try {
|
||||||
|
await formRef.value?.validate()
|
||||||
|
// TODO: 调用注册接口
|
||||||
|
loading.value = true
|
||||||
|
const res = await loginByMobile({
|
||||||
|
mobile: loginForm.phone,
|
||||||
|
code: loginForm.code,
|
||||||
|
socialType: props.type,
|
||||||
|
socialCode: props.code,
|
||||||
|
socialState: props.state,
|
||||||
|
})
|
||||||
|
if (res.code === 0) {
|
||||||
|
const data = res.data
|
||||||
|
REFRESHTOKEN.setToken(data.accessToken, data.refreshToken)
|
||||||
|
REFRESHTOKEN.setUserId(data.userId.toString())
|
||||||
|
REFRESHTOKEN.setUserName(loginForm.phone)
|
||||||
|
userStore.setToken(data.accessToken)
|
||||||
|
userStore.setUserId(data.userId.toString())
|
||||||
|
userStore.setUserName(loginForm.phone)
|
||||||
|
userStore.setRefreshToken(data.refreshToken)
|
||||||
|
ElMessage.success('登录成功')
|
||||||
|
props.onClose()
|
||||||
|
// 获取用户信息
|
||||||
|
userStore.getUserInfo()
|
||||||
|
// 登录成功
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleLoginEmail = () => {
|
||||||
|
props.onClose()
|
||||||
|
nextTick(() => {
|
||||||
|
$openLoginEmail()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.login-dialog {
|
||||||
|
.el-dialog {
|
||||||
|
border-radius: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-dialog__header {
|
||||||
|
// margin: 0;
|
||||||
|
// padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-dialog__body {
|
||||||
|
padding: 0px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.popup-overlay {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 10;
|
||||||
|
.popup-content {
|
||||||
|
background-color: white;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.login-container {
|
||||||
|
display: flex;
|
||||||
|
height: 508px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: #f9faff;
|
||||||
|
width: 480px;
|
||||||
|
|
||||||
|
.login-img {
|
||||||
|
width: 438px;
|
||||||
|
height: 258px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-right {
|
||||||
|
padding: 22px 25px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-title {
|
||||||
|
font-size: 20px;
|
||||||
|
color: #333;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-tabs {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
|
||||||
|
.tab-item {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
padding: 0 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
color: #1677ff;
|
||||||
|
font-weight: 500;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
bottom: -4px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
width: 20px;
|
||||||
|
height: 2px;
|
||||||
|
background: #1677ff;
|
||||||
|
border-radius: 1px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// &:first-child::after {
|
||||||
|
// content: '';
|
||||||
|
// position: absolute;
|
||||||
|
// right: 0;
|
||||||
|
// top: 50%;
|
||||||
|
// transform: translateY(-50%);
|
||||||
|
// width: 1px;
|
||||||
|
// height: 14px;
|
||||||
|
// background: #ddd;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form {
|
||||||
|
.el-input {
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-input__wrapper) {
|
||||||
|
background: #f5f5f5;
|
||||||
|
border: none;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-button {
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
margin-top: 24px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agreement {
|
||||||
|
margin: 16px 0;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
|
||||||
|
.link {
|
||||||
|
color: #1677ff;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.third-party-login {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 40px;
|
||||||
|
margin-top: 30px;
|
||||||
|
|
||||||
|
.login-icons {
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
.login-icon {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-text {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-link {
|
||||||
|
text-align: right;
|
||||||
|
margin-top: 20px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
|
||||||
|
.link {
|
||||||
|
color: #1677ff;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.verify-code-input {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
|
||||||
|
.el-input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.verify-code-btn {
|
||||||
|
width: 120px;
|
||||||
|
height: 40px;
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
color: #999;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
border-color: #dcdfe6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保验证码按钮文字不换行
|
||||||
|
:deep(.verify-code-btn) {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
264
components/kl-nav-tab/index.vue
Normal file
264
components/kl-nav-tab/index.vue
Normal file
@ -0,0 +1,264 @@
|
|||||||
|
<template>
|
||||||
|
<div class="w-100% border-b-1px border-b-[#eee] border-b-solid">
|
||||||
|
<div class="relative ma-auto flex items-center py-20px w-1500px!">
|
||||||
|
<img src="@/assets/images/logo5.png" alt="图夕夕" srcset="" class="h-51px w-182px cursor-pointer" @click="router.push('/index')" />
|
||||||
|
<div class="ml-60px flex items-center">
|
||||||
|
<span v-for="item in navList" :key="item" class="nav" :class="props.active === item ? 'active' : ''" @click="handleClick(item)">{{ item }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="relative ml-30px">
|
||||||
|
<el-input
|
||||||
|
v-model="searchQuery"
|
||||||
|
placeholder="电子产品"
|
||||||
|
:prefix-icon="Search"
|
||||||
|
class="search-input h-40px w-328px"
|
||||||
|
@focus="handleHot(), (showHotList = true)"
|
||||||
|
@input="handleInput"
|
||||||
|
></el-input>
|
||||||
|
<!-- 搜索框 获取到焦点 显示热门列表 -->
|
||||||
|
<div
|
||||||
|
v-if="showHotList"
|
||||||
|
v-loading="loading"
|
||||||
|
class="absolute left-16px top-42px z-100 w-276px border-width-1px border-color-#1A65FF rounded-bl-4px rounded-br-4px rounded-tl-0px rounded-tr-0px border-solid bg-[#fff] pa-10px"
|
||||||
|
>
|
||||||
|
<!-- 这里放置热门列表的内容 -->
|
||||||
|
<ul class="flex flex-col gap-6px">
|
||||||
|
<li
|
||||||
|
v-for="(item, index) in hotItems"
|
||||||
|
:key="index"
|
||||||
|
class="flex flex-row cursor-pointer items-center justify-between text-13px"
|
||||||
|
@click="handleHotItem(item)"
|
||||||
|
>
|
||||||
|
<span class="color-#333333">{{ item.projectTypeName }}</span>
|
||||||
|
<span v-if="item.count" class="color-#999999">{{ item.count }}份图纸</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div v-if="!hotItems.length" class="text-12px color-#999">无数据</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="absolute right-10px flex items-center">
|
||||||
|
<div class="h-36px w-36px border-rd-[50%] bg-[#F5F5F5] text-center line-height-44px">
|
||||||
|
<img v-if="!isLogin" src="@/assets/images/user.png" alt="" srcset="" class="h-19px w-17px" />
|
||||||
|
<img v-else :src="userStore.userInfoRes.avatar" alt="" srcset="" class="h-19px w-17px rd-50%" />
|
||||||
|
</div>
|
||||||
|
<span v-if="!isLogin" class="ml-14px cursor-pointer text-14px text-[#1A65FF] font-normal" @click="handleLogin">立即登录</span>
|
||||||
|
<el-dropdown v-else placement="top-start" @command="handleCommand">
|
||||||
|
<span class="ml-14px cursor-pointer text-14px text-[#1A65FF] font-normal">{{ userStore.userInfoRes.nickname || '立即登录' }}</span>
|
||||||
|
<template #dropdown>
|
||||||
|
<el-dropdown-menu>
|
||||||
|
<el-dropdown-item command="个人中心"
|
||||||
|
><el-icon><Setting /></el-icon>个人中心</el-dropdown-item
|
||||||
|
>
|
||||||
|
<el-dropdown-item command="退出"
|
||||||
|
><el-icon><SwitchButton /></el-icon>退出</el-dropdown-item
|
||||||
|
>
|
||||||
|
<!-- <el-dropdown-item>The Action 3st</el-dropdown-item> -->
|
||||||
|
</el-dropdown-menu>
|
||||||
|
</template>
|
||||||
|
</el-dropdown>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, getCurrentInstance, computed, onMounted } from 'vue'
|
||||||
|
import { Setting, SwitchButton } from '@element-plus/icons-vue'
|
||||||
|
import { page } from '@/api/upnew/index'
|
||||||
|
import { top } from '@/api/home/index'
|
||||||
|
import type { ProjectDrawStatisticAppRespVO } from '@/api/home/type'
|
||||||
|
import { Search } from '@element-plus/icons-vue'
|
||||||
|
import useUserStore from '@/store/user'
|
||||||
|
const userStore = useUserStore()
|
||||||
|
const { $openLogin } = useNuxtApp()
|
||||||
|
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
active: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: Number, // 1 图纸 2 模型 3 文本
|
||||||
|
default: 1,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const searchQuery = ref('')
|
||||||
|
const showHotList = ref(false)
|
||||||
|
const hotItems = ref<ProjectDrawStatisticAppRespVO[]>([])
|
||||||
|
|
||||||
|
// 是否登录
|
||||||
|
const isLogin = computed(() => {
|
||||||
|
return !!userStore.token
|
||||||
|
})
|
||||||
|
|
||||||
|
const navList = ref(['首页', '图纸', '文本', '模型', '国外专区', '工具箱', '交流频道'])
|
||||||
|
|
||||||
|
const loading = ref(false)
|
||||||
|
const handleHot = async () => {
|
||||||
|
loading.value = true
|
||||||
|
const res = await top({
|
||||||
|
limit: 10,
|
||||||
|
type: props.type, // 1 图纸 2 模型 3 文本
|
||||||
|
})
|
||||||
|
hotItems.value = res.data
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
handleHot()
|
||||||
|
|
||||||
|
const timer = ref(0)
|
||||||
|
const handleInput = (val: string) => {
|
||||||
|
searchQuery.value = val
|
||||||
|
loading.value = true
|
||||||
|
if (timer.value) {
|
||||||
|
window.clearTimeout(timer.value)
|
||||||
|
}
|
||||||
|
timer.value = window.setTimeout(async () => {
|
||||||
|
console.log('searchQuery', searchQuery.value)
|
||||||
|
const res = await page({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
type: props.type, // 1 图纸 2 模型 3 文本
|
||||||
|
title: searchQuery.value, // 1 图纸 2 模型 3 文本
|
||||||
|
})
|
||||||
|
if (res.code === 0) {
|
||||||
|
hotItems.value = res.data.list.map((c) => {
|
||||||
|
return { ...c, projectTypeName: c.title }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
loading.value = false
|
||||||
|
}, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleHotItem = (item: ProjectDrawStatisticAppRespVO) => {
|
||||||
|
const normal = { id: '0', name: '图纸库', isChildren: false }
|
||||||
|
const level = item.pairs?.filter(Boolean).map((item) => ({ id: item?.id, name: item?.name, isChildren: false })) || []
|
||||||
|
level.unshift(normal)
|
||||||
|
if (item.type === 1) {
|
||||||
|
navigateTo(`/drawe?level=${JSON.stringify(level)}&keywords=${item.title || ''}`, '_blank')
|
||||||
|
} else if (item.type === 2) {
|
||||||
|
navigateTo(`/text?level=${JSON.stringify(level)}&keywords=${item.title || ''}`, '_blank')
|
||||||
|
} else if (item.type === 3) {
|
||||||
|
navigateTo(`/model?level=${JSON.stringify(level)}&keywords=${item.title || ''}`, '_blank')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClick = (item: string) => {
|
||||||
|
switch (item) {
|
||||||
|
case '首页':
|
||||||
|
navigateTo('/index') // 修改为在新窗口打开
|
||||||
|
break
|
||||||
|
case '图纸':
|
||||||
|
navigateTo('/drawe') // 修改为在新窗口打开
|
||||||
|
break
|
||||||
|
case '文本':
|
||||||
|
navigateTo('/text') // 修改为在新窗口打开
|
||||||
|
break
|
||||||
|
case '模型':
|
||||||
|
navigateTo('/model') // 修改为在新窗口打开
|
||||||
|
break
|
||||||
|
case '国外专区':
|
||||||
|
navigateTo('/foreign') // 修改为在新窗口打开
|
||||||
|
break
|
||||||
|
case '牛人社区':
|
||||||
|
navigateTo('/community') // 修改为在新窗口打开
|
||||||
|
break
|
||||||
|
case '交流频道':
|
||||||
|
navigateTo('/communication/channel') // 修改为在新窗口打开
|
||||||
|
break
|
||||||
|
case '工具箱':
|
||||||
|
navigateTo('/toolbox') // 修改为在新窗口打开
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const handleLogin = () => {
|
||||||
|
$openLogin()
|
||||||
|
}
|
||||||
|
const handleCommand = (command: string) => {
|
||||||
|
if (command === '退出') {
|
||||||
|
userStore.logout()
|
||||||
|
userStore.$reset()
|
||||||
|
} else if (command === '个人中心') {
|
||||||
|
navigateTo('/personal/center/info')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
// 监听点击事件
|
||||||
|
document.addEventListener('click', (event) => {
|
||||||
|
const target = event.target as HTMLElement
|
||||||
|
if (!target.closest('.search-input')) {
|
||||||
|
showHotList.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.active {
|
||||||
|
color: #1a65ff !important;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 3px;
|
||||||
|
border-radius: 3px;
|
||||||
|
left: 0px;
|
||||||
|
bottom: -8px;
|
||||||
|
background-color: #1a65ff !important;
|
||||||
|
content: '';
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
::v-deep(.el-input__wrapper) {
|
||||||
|
border-radius: 23px !important;
|
||||||
|
width: 328px;
|
||||||
|
height: 40px;
|
||||||
|
// border: 1px solid #d7d7d7;
|
||||||
|
}
|
||||||
|
.nav {
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 16px;
|
||||||
|
color: #333333;
|
||||||
|
margin-right: 40px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 添加自定义样式来调整图标大小 */
|
||||||
|
::v-deep(.el-input__prefix .el-icon) {
|
||||||
|
font-size: 16px; /* 调整图标大小 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 修改 placeholder 的字体大小 */
|
||||||
|
::v-deep(.el-input__inner::placeholder) {
|
||||||
|
font-size: 14px; // 调整为你想要的字体大小
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 添加下拉菜单样式修正 */
|
||||||
|
::v-deep(.el-dropdown__popper) {
|
||||||
|
border: none !important;
|
||||||
|
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1) !important;
|
||||||
|
|
||||||
|
.el-dropdown-menu__item {
|
||||||
|
padding: 8px 20px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: #f5f7fa;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 移除聚焦时的蓝色边框 */
|
||||||
|
.el-dropdown-menu {
|
||||||
|
border: 1px solid #ebeef5 !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 移除触发按钮的轮廓线 */
|
||||||
|
.el-dropdown span {
|
||||||
|
&:focus {
|
||||||
|
outline: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
115
components/kl-query-filter/index.vue
Normal file
115
components/kl-query-filter/index.vue
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
<template>
|
||||||
|
<div class="filter-wrap">
|
||||||
|
<div v-if="slots.operate" class="operate-wrap m-b-8px p-b-8px">
|
||||||
|
<slot name="operate"></slot>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-between">
|
||||||
|
<div class="flex flex-wrap gap-8px">
|
||||||
|
<slot />
|
||||||
|
<template v-if="btn">
|
||||||
|
<div class="kl-filter-btns">
|
||||||
|
<el-button :loading="loading" :icon="Search" :class="[{ 'm-l-20px': props.searchBtnMarginLeft }]" type="primary" @click="handleSearch"
|
||||||
|
>搜索</el-button
|
||||||
|
>
|
||||||
|
<el-button v-if="isShowReset" :icon="Refresh" @click="handleReset">重置</el-button>
|
||||||
|
<slot name="followBtn"></slot>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-popover v-if="slots.ext" ref="popoverRef" placement="bottom-end" :width="popoverWidth" trigger="click">
|
||||||
|
<template #reference>
|
||||||
|
<slot name="more-btn">
|
||||||
|
<el-button type="primary" link
|
||||||
|
>更多筛选<el-icon><ArrowDown /></el-icon
|
||||||
|
></el-button>
|
||||||
|
</slot>
|
||||||
|
</template>
|
||||||
|
<slot name="ext" />
|
||||||
|
<el-divider />
|
||||||
|
<div class="flex flex-justify-end">
|
||||||
|
<el-button v-if="isShowReset" @click="handleReset">重置</el-button>
|
||||||
|
<el-button type="primary" @click="handleSearch">搜索</el-button>
|
||||||
|
</div>
|
||||||
|
</el-popover>
|
||||||
|
</div>
|
||||||
|
<slot name="btn"></slot>
|
||||||
|
</div>
|
||||||
|
<div v-if="slots.footer" class="filter-footer mt-14px">
|
||||||
|
<slot name="footer"></slot>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
// 注意 在使用 el-select 或 el-date-picker 等组件时,需要在组件上添加 :teleported="false" 属性,
|
||||||
|
// 否则会出现弹窗失去焦点关闭的情况
|
||||||
|
import { useSlots, ref, getCurrentInstance } from 'vue'
|
||||||
|
import { Search, ArrowDown, Refresh } from '@element-plus/icons-vue'
|
||||||
|
const slots = useSlots()
|
||||||
|
const { proxy } = getCurrentInstance() as any
|
||||||
|
const popoverRef = ref()
|
||||||
|
const props = defineProps({
|
||||||
|
loading: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
btn: {
|
||||||
|
//是否显示按钮
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
isShowReset: {
|
||||||
|
//是否显示重置按钮
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
popoverWidth: {
|
||||||
|
type: Number,
|
||||||
|
default: 350,
|
||||||
|
},
|
||||||
|
searchBtnMarginLeft: {
|
||||||
|
//搜索按钮是否有做边距
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const emits = defineEmits<{
|
||||||
|
(event: 'search'): void
|
||||||
|
(event: 'reset'): void
|
||||||
|
}>()
|
||||||
|
if (!proxy.$parent?.resetFields) {
|
||||||
|
console.error('QueryFilters必须嵌套在 ElForm 中才能正常使用')
|
||||||
|
}
|
||||||
|
const handleReset = () => {
|
||||||
|
if (props.loading) return
|
||||||
|
proxy.$parent?.resetFields()
|
||||||
|
emits('reset')
|
||||||
|
popoverRef.value?.hide()
|
||||||
|
}
|
||||||
|
const handleSearch = () => {
|
||||||
|
if (props.loading) return
|
||||||
|
emits('search')
|
||||||
|
popoverRef.value?.hide()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.filter-wrap {
|
||||||
|
background-color: #ffffff;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
padding: 12px;
|
||||||
|
.operate-wrap {
|
||||||
|
border-bottom: 1px solid #e6e8ed;
|
||||||
|
}
|
||||||
|
:deep(.el-form-item) {
|
||||||
|
margin-bottom: 0 !important;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
.kl-filter-btns {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
:deep(.el-divider--horizontal) {
|
||||||
|
margin: 12px 0 !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
731
components/kl-quick-menu/components/kl-service.vue
Normal file
731
components/kl-quick-menu/components/kl-service.vue
Normal file
@ -0,0 +1,731 @@
|
|||||||
|
<!-- 弄成一个聊天弹窗 仿照微信聊天弹窗 -->
|
||||||
|
<template>
|
||||||
|
<div class="chat-dialog">
|
||||||
|
<el-dialog v-model="dialogVisible" lock-scroll draggable :show-close="true" :close-on-click-modal="false" :close-on-press-escape="false" width="800px">
|
||||||
|
<template #header>
|
||||||
|
<div class="dialog-header">
|
||||||
|
<div class="title">在线客服</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="chat-layout">
|
||||||
|
<!-- 右侧聊天区域 -->
|
||||||
|
<div class="chat-container">
|
||||||
|
<!-- 消息列表区域 -->
|
||||||
|
<div ref="messageList" class="message-list" @scroll="handleScroll">
|
||||||
|
<!-- 加载更多提示 -->
|
||||||
|
<div v-if="chatMessageQuery.hasMore" class="load-more">
|
||||||
|
<el-icon v-if="chatMessageQuery.loading"><Loading /></el-icon>
|
||||||
|
<span v-else>上拉加载更多</span>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-for="(msg, index) in chatMessages"
|
||||||
|
:key="index"
|
||||||
|
:class="['message-item', msg.fromId === userStore.userInfoRes.id ? 'message-sent' : 'message-received']"
|
||||||
|
>
|
||||||
|
<div class="avatar">
|
||||||
|
<el-avatar :size="40" :src="msg.fromId === userStore.userInfoRes.id ? userStore.userInfoRes.avatar : userAvatar" />
|
||||||
|
</div>
|
||||||
|
<div class="message-content">
|
||||||
|
<div v-if="msg.msgType === 0" class="message-bubble whitespace-pre-wrap">{{ msg.content }}</div>
|
||||||
|
<div v-else-if="msg.msgType === 1" class="message-bubble max-w-50%">
|
||||||
|
<img :src="msg.content" alt="图片" class="w-100%" />
|
||||||
|
</div>
|
||||||
|
<div v-else class="message-bubble max-w-50%">
|
||||||
|
{{ msg.content.split('/').pop() }}
|
||||||
|
</div>
|
||||||
|
<div class="message-time">{{ dayjs(msg.createTime).format('YYYY-MM-DD HH:mm:ss') }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 输入区域 -->
|
||||||
|
<div class="input-area">
|
||||||
|
<div class="toolbar">
|
||||||
|
<div class="tool-left">
|
||||||
|
<el-tooltip content="发送图片" placement="top">
|
||||||
|
<el-icon class="tool-icon" @click="triggerImageUpload"><Picture /></el-icon>
|
||||||
|
</el-tooltip>
|
||||||
|
<input ref="imageInputRef" type="file" style="display: none" @change="handleImageUpload" />
|
||||||
|
<el-popover :visible="showEmoji" placement="top" :width="450" trigger="click">
|
||||||
|
<template #reference>
|
||||||
|
<el-icon class="tool-icon emoji-trigger" @click="showEmoji = !showEmoji"><Sunrise /></el-icon>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="emoji-list">
|
||||||
|
<span v-for="emoji in emojiList" :key="emoji" class="emoji-item" @click="insertEmoji(emoji)">
|
||||||
|
{{ emoji }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</el-popover>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="input-box">
|
||||||
|
<el-input
|
||||||
|
v-model="inputMessage"
|
||||||
|
type="textarea"
|
||||||
|
:rows="3"
|
||||||
|
placeholder="请输入消息,Enter 发送"
|
||||||
|
resize="none"
|
||||||
|
maxlength="255"
|
||||||
|
@keydown.enter.prevent="(e: any) => (e.shiftKey ? (inputMessage += '\n') : handleSend(0))"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="send-btn">
|
||||||
|
<el-button type="primary" :disabled="!inputMessage.trim()" @click="handleSend(0)">
|
||||||
|
<el-icon class="send-icon"><Position /></el-icon>
|
||||||
|
发送
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { throttle } from 'lodash'
|
||||||
|
import { ref, onMounted, nextTick } from 'vue'
|
||||||
|
import { Picture, Position, Sunrise, Loading } from '@element-plus/icons-vue'
|
||||||
|
import { upload } from '@/api/common'
|
||||||
|
import { sendKefuMessage, getMessagePage } from '@/api/channel/index'
|
||||||
|
import type { msgType, PageResultMessageRespVO } from '@/api/channel/types'
|
||||||
|
import useUserStore from '@/store/user'
|
||||||
|
const userStore = useUserStore()
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
|
const inputMessage = ref('')
|
||||||
|
const messageList = ref()
|
||||||
|
// const searchText = ref('')
|
||||||
|
const currentUserId = ref()
|
||||||
|
|
||||||
|
const dialogVisible = defineModel<boolean>('dialogVisible', { required: true })
|
||||||
|
// 获取传过来的数据
|
||||||
|
const props = defineProps({
|
||||||
|
sessionType: {
|
||||||
|
// 会话类型0:单聊 1:群聊,示例值(2)
|
||||||
|
type: String,
|
||||||
|
default: '1',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
console.log('会话类型', props.sessionType)
|
||||||
|
|
||||||
|
// 模拟数据
|
||||||
|
const userAvatar = 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'
|
||||||
|
|
||||||
|
// const userList = ref<PageResultSessionRespVO[]>([])
|
||||||
|
|
||||||
|
// 聊天记录
|
||||||
|
const chatMessages = ref<PageResultMessageRespVO['list']>([])
|
||||||
|
|
||||||
|
// 聊天消息查询
|
||||||
|
const chatMessageQuery = ref({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
hasMore: true,
|
||||||
|
loading: false,
|
||||||
|
sessionId: 0,
|
||||||
|
toId: 0,
|
||||||
|
isPending: false,
|
||||||
|
})
|
||||||
|
const switchUser = async () => {
|
||||||
|
// 切换用户
|
||||||
|
// chatMessageQuery.value.toId = user.fromId === userStore.userInfoRes.id ? user.toId : user.fromId
|
||||||
|
// chatMessageQuery.value.sessionId = currentUserId.value = user.sessionId
|
||||||
|
// user.unreadCount = 0 // 清除未读消息
|
||||||
|
// 切换用户时,清空聊天记录
|
||||||
|
chatMessageQuery.value.loading = true
|
||||||
|
chatMessageQuery.value.pageNo = 1
|
||||||
|
chatMessageQuery.value.hasMore = true
|
||||||
|
chatMessages.value = []
|
||||||
|
await getChatDetailList()
|
||||||
|
nextTick(() => {
|
||||||
|
scrollToBottom()
|
||||||
|
})
|
||||||
|
// 清空未读消息
|
||||||
|
// clearUnreadMessage({ id: user.sessionId })
|
||||||
|
}
|
||||||
|
|
||||||
|
const getChatDetailList = async () => {
|
||||||
|
const res = await getMessagePage({
|
||||||
|
pageNo: chatMessageQuery.value.pageNo,
|
||||||
|
pageSize: chatMessageQuery.value.pageSize,
|
||||||
|
// fromId: userStore.userInfoRes.id, // 当前用户id
|
||||||
|
// msgType: 2,
|
||||||
|
topic: `zbjk_message_kefu/${userStore.userInfoRes.id}`,
|
||||||
|
})
|
||||||
|
if (res.code === 0) {
|
||||||
|
chatMessageQuery.value.isPending = false
|
||||||
|
// 数据反过来
|
||||||
|
if (res.data.list.length > 0) {
|
||||||
|
// 保存当前滚动位置和内容高度
|
||||||
|
const scrollElement = messageList.value
|
||||||
|
const oldScrollHeight = scrollElement.scrollHeight
|
||||||
|
const oldScrollTop = scrollElement.scrollTop
|
||||||
|
chatMessages.value = [...res.data.list.reverse(), ...chatMessages.value]
|
||||||
|
// 在下一个 tick 后调整滚动位置
|
||||||
|
nextTick(() => {
|
||||||
|
const newScrollHeight = scrollElement.scrollHeight
|
||||||
|
const heightDiff = newScrollHeight - oldScrollHeight
|
||||||
|
scrollElement.scrollTop = oldScrollTop + heightDiff
|
||||||
|
})
|
||||||
|
}
|
||||||
|
chatMessageQuery.value.loading = false
|
||||||
|
chatMessageQuery.value.pageNo++
|
||||||
|
// 判断是否还有更多数据
|
||||||
|
if (res.data.list.length < chatMessageQuery.value.pageSize) {
|
||||||
|
chatMessageQuery.value.hasMore = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 滚动处理函数
|
||||||
|
const handleScroll = async (e: Event) => {
|
||||||
|
const target = e.target as HTMLElement
|
||||||
|
// 当滚动到顶部附近时触发加载更多
|
||||||
|
if (target.scrollTop < 50 && !chatMessageQuery.value.loading && chatMessageQuery.value.hasMore && !chatMessageQuery.value.isPending) {
|
||||||
|
// await loadMoreMessages()
|
||||||
|
chatMessageQuery.value.isPending = true
|
||||||
|
await throttledGetChatList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建节流函数,设置 500ms 的间隔
|
||||||
|
const throttledGetChatList = throttle(async () => {
|
||||||
|
await getChatDetailList()
|
||||||
|
}, 1500)
|
||||||
|
|
||||||
|
const handleSend = (msgType: msgType = 0) => {
|
||||||
|
if (!inputMessage.value.trim()) return
|
||||||
|
|
||||||
|
const newMessage = {
|
||||||
|
msgType: msgType,
|
||||||
|
content: inputMessage.value,
|
||||||
|
toId: 0, // 对方userId
|
||||||
|
userId: userStore.userInfoRes.id, // 当前用户id
|
||||||
|
fromId: userStore.userInfoRes.id, // 当前用户id
|
||||||
|
createTime: dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss'), // 当前时间戳
|
||||||
|
}
|
||||||
|
|
||||||
|
chatMessages.value.push(newMessage)
|
||||||
|
userStore.mqttClient?.publish(`zbjk_message_kefu/`, JSON.stringify(newMessage))
|
||||||
|
|
||||||
|
// 更新用户列表中的最后一条消息
|
||||||
|
// userLastMessage(newMessage)
|
||||||
|
// 清空输入框
|
||||||
|
inputMessage.value = ''
|
||||||
|
// 滚动到底部
|
||||||
|
scrollToBottom()
|
||||||
|
// 发送单聊信息存储到服务器
|
||||||
|
sendKefuMessage(newMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
const scrollToBottom = () => {
|
||||||
|
if (messageList.value) {
|
||||||
|
nextTick(() => {
|
||||||
|
messageList.value.scrollTop = messageList.value.scrollHeight
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switchUser()
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
userStore.mqttClient?.onMessage((topic: string, message: any) => {
|
||||||
|
if (topic.indexOf(`zbjk_message_kefu`) === -1) return
|
||||||
|
console.log('接收消息---------', topic, message)
|
||||||
|
console.log('当前用户id', userStore.userInfoRes.id)
|
||||||
|
console.log('当前聊天用户id', currentUserId.value)
|
||||||
|
// 将消息添加到聊天记录中
|
||||||
|
const msg = JSON.parse(message)
|
||||||
|
if (msg.userId === userStore.userInfoRes.id) return
|
||||||
|
msg.msgType = Number(msg.msgType)
|
||||||
|
// 当前用户发送的消息
|
||||||
|
chatMessages.value.push(msg)
|
||||||
|
// 更新当前用户列表中的最后一条消息
|
||||||
|
// userLastMessage(msg)
|
||||||
|
// 清空未读消息
|
||||||
|
// clearUnreadMessage({ id: msg.sessionId })
|
||||||
|
if (msg.msgType === 1) {
|
||||||
|
const img = new Image()
|
||||||
|
img.src = msg.content
|
||||||
|
img.onload = () => {
|
||||||
|
// 滚动到底部
|
||||||
|
scrollToBottom()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 滚动到底部
|
||||||
|
scrollToBottom()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
document.addEventListener('click', (event) => {
|
||||||
|
const target = event.target as HTMLElement
|
||||||
|
if (!target.closest('.emoji-popover') && !target.closest('.emoji-trigger')) {
|
||||||
|
showEmoji.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
// 触发图片上传
|
||||||
|
const imageInputRef = ref()
|
||||||
|
const triggerImageUpload = (): void => {
|
||||||
|
if (imageInputRef.value) {
|
||||||
|
imageInputRef.value.click()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理图片上传
|
||||||
|
const handleImageUpload = async (event: Event) => {
|
||||||
|
const target = event.target as HTMLInputElement
|
||||||
|
const files = target.files
|
||||||
|
|
||||||
|
if (files && files.length > 0) {
|
||||||
|
const file = files[0]
|
||||||
|
|
||||||
|
// 检查文件类型 0:文本 1:图片 2:视频 3:文件
|
||||||
|
const msgType = file.type.startsWith('image/') ? 1 : file.type.startsWith('video/') ? 2 : 3
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('fieldName', file?.name)
|
||||||
|
formData.append('file', file as Blob)
|
||||||
|
const res = await upload('/prod-api/app-api/infra/file/upload', formData)
|
||||||
|
if (res.code === 0) {
|
||||||
|
const imageUrl = res.data
|
||||||
|
if (msgType === 1) {
|
||||||
|
// 预加载图片
|
||||||
|
const img = new Image()
|
||||||
|
img.src = imageUrl
|
||||||
|
img.onload = () => {
|
||||||
|
inputMessage.value = imageUrl
|
||||||
|
handleSend(msgType)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputMessage.value = imageUrl
|
||||||
|
handleSend(msgType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置文件输入以允许重复选择同一文件
|
||||||
|
if (imageInputRef.value) {
|
||||||
|
imageInputRef.value.value = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const showEmoji = ref(false)
|
||||||
|
const emojiList = [
|
||||||
|
'😀',
|
||||||
|
'😃',
|
||||||
|
'😄',
|
||||||
|
'😁',
|
||||||
|
'😆',
|
||||||
|
'😅',
|
||||||
|
'😂',
|
||||||
|
'🤣',
|
||||||
|
'😊',
|
||||||
|
'😇',
|
||||||
|
'🙂',
|
||||||
|
'🙃',
|
||||||
|
'😉',
|
||||||
|
'😌',
|
||||||
|
'😍',
|
||||||
|
'🥰',
|
||||||
|
'😘',
|
||||||
|
'😗',
|
||||||
|
'😙',
|
||||||
|
'😚',
|
||||||
|
'😋',
|
||||||
|
'😛',
|
||||||
|
'😝',
|
||||||
|
'😜',
|
||||||
|
'🤪',
|
||||||
|
'🤨',
|
||||||
|
'🧐',
|
||||||
|
'🤓',
|
||||||
|
'😎',
|
||||||
|
'🤩',
|
||||||
|
'🥳',
|
||||||
|
'😏',
|
||||||
|
'😒',
|
||||||
|
'😞',
|
||||||
|
'😔',
|
||||||
|
'😟',
|
||||||
|
'😕',
|
||||||
|
'🙁',
|
||||||
|
'☹️',
|
||||||
|
'😣',
|
||||||
|
]
|
||||||
|
|
||||||
|
const insertEmoji = (emoji: string) => {
|
||||||
|
inputMessage.value += emoji
|
||||||
|
showEmoji.value = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.emoji-list {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(10, 1fr);
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
|
.emoji-item {
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 20px;
|
||||||
|
padding: 4px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
transition: all 0.2s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: #f5f5f5;
|
||||||
|
border-radius: 4px;
|
||||||
|
transform: scale(1.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.chat-dialog {
|
||||||
|
:deep(.el-dialog__header) {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 8px 8px 0 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-dialog__body) {
|
||||||
|
padding: 0px !important;
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-dialog) {
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 12px 32px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-dialog__headerbtn) {
|
||||||
|
top: 24px;
|
||||||
|
right: 12px;
|
||||||
|
z-index: 10;
|
||||||
|
|
||||||
|
.el-dialog__close {
|
||||||
|
font-size: 16px;
|
||||||
|
transition: all 0.3s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 16px;
|
||||||
|
// height: 40px;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-layout {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-list {
|
||||||
|
width: 280px;
|
||||||
|
border-right: 1px solid #eee;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background-color: #34353a;
|
||||||
|
|
||||||
|
.search-box {
|
||||||
|
padding: 12px 12px 12px 12px;
|
||||||
|
:deep(.el-input__wrapper) {
|
||||||
|
background-color: #4f5054 !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
:deep(.el-input__inner) {
|
||||||
|
color: #fff;
|
||||||
|
border-radius: 16px;
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-items {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
|
||||||
|
.user-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
padding: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
// background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background-color: rgba(255, 255, 255, 0.12) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-info {
|
||||||
|
flex: 1;
|
||||||
|
margin: 0 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
.user-name {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.last-message {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #999;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-status {
|
||||||
|
text-align: right;
|
||||||
|
|
||||||
|
.time {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #999;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.unread-badge {
|
||||||
|
:deep(.el-badge__content) {
|
||||||
|
background-color: #c561f9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-container {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
.chat-header {
|
||||||
|
padding: 16px 20px;
|
||||||
|
background: #fff;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
|
||||||
|
.header-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
|
||||||
|
.title-info {
|
||||||
|
.title {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subtitle {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-list {
|
||||||
|
flex: 1;
|
||||||
|
padding: 24px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow-y: auto;
|
||||||
|
background-color: #f7f8fa;
|
||||||
|
min-height: 300px;
|
||||||
|
.load-more {
|
||||||
|
text-align: center;
|
||||||
|
padding: 10px 0;
|
||||||
|
color: #999;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-item {
|
||||||
|
display: flex;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
|
||||||
|
&.message-sent {
|
||||||
|
flex-direction: row-reverse;
|
||||||
|
|
||||||
|
.message-content {
|
||||||
|
margin-right: 12px;
|
||||||
|
margin-left: 80px;
|
||||||
|
align-items: flex-end;
|
||||||
|
|
||||||
|
.message-bubble {
|
||||||
|
background: #1a65ff;
|
||||||
|
color: #fff;
|
||||||
|
border-radius: 12px 2px 12px 12px;
|
||||||
|
box-shadow: 0 4px 12px rgba(197, 97, 249, 0.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.message-received {
|
||||||
|
.message-content {
|
||||||
|
margin-left: 12px;
|
||||||
|
margin-right: 80px;
|
||||||
|
|
||||||
|
.message-bubble {
|
||||||
|
background-color: #fff;
|
||||||
|
border-radius: 2px 12px 12px 12px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
.message-bubble {
|
||||||
|
padding: 12px 16px;
|
||||||
|
font-size: 14px;
|
||||||
|
max-width: 400px;
|
||||||
|
word-break: break-word;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-time {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #999;
|
||||||
|
margin-top: 6px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-area {
|
||||||
|
background-color: #fff;
|
||||||
|
border-top: 1px solid #eee;
|
||||||
|
padding: 16px 24px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
.toolbar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0 0 12px;
|
||||||
|
|
||||||
|
.tool-left {
|
||||||
|
display: flex;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tool-icon {
|
||||||
|
font-size: 20px;
|
||||||
|
color: #666;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #c561f9;
|
||||||
|
transform: scale(1.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-box {
|
||||||
|
margin-bottom: 12px;
|
||||||
|
|
||||||
|
:deep(.el-textarea__inner) {
|
||||||
|
border: 1px solid #fff !important;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 12px;
|
||||||
|
font-size: 14px;
|
||||||
|
transition: all 0.3s;
|
||||||
|
outline: none !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
border-color: #c561f9;
|
||||||
|
box-shadow: none !important;
|
||||||
|
// box-shadow: 0 0 0 2px rgba(197, 97, 249, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.send-btn {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
|
||||||
|
.el-button {
|
||||||
|
background: #1a65ff;
|
||||||
|
border: none;
|
||||||
|
padding: 10px 24px;
|
||||||
|
font-size: 14px;
|
||||||
|
border-radius: 8px;
|
||||||
|
transition: all 0.3s;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
|
||||||
|
.send-icon {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
transform: translateY(-1px);
|
||||||
|
// box-shadow: 0 4px 12px rgba(197, 97, 249, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-disabled {
|
||||||
|
background: #e0e0e0;
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自定义滚动条样式
|
||||||
|
.message-list {
|
||||||
|
&::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background-color: rgba(0, 0, 0, 0.1);
|
||||||
|
border-radius: 3px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&::-webkit-scrollbar-track {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
235
components/kl-quick-menu/components/kl-vip.vue
Normal file
235
components/kl-quick-menu/components/kl-vip.vue
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog v-model="visible" width="800px" class="vip-dialog" align-center>
|
||||||
|
<template #header>
|
||||||
|
<div class="vip-modal-title">VIP套餐</div>
|
||||||
|
</template>
|
||||||
|
<div v-loading="loading" class="vip-cards">
|
||||||
|
<div v-for="item in viplist" :key="item.id" class="vip-card">
|
||||||
|
<div class="relative w-100% flex flex-col items-center">
|
||||||
|
<div class="vip-card-header basic">
|
||||||
|
<div class="vip-card-title">{{ item.name }}</div>
|
||||||
|
<!-- <div class="vip-card-subtitle">中小微企业</div> -->
|
||||||
|
</div>
|
||||||
|
<div class="vip-card-price">
|
||||||
|
<span class="price">¥{{ accDiv(item.payPrice || 0, 100) }}</span>
|
||||||
|
<span class="per">/1年</span>
|
||||||
|
</div>
|
||||||
|
<ul class="vip-card-features">
|
||||||
|
<li>1. {{ item.profile }}</li>
|
||||||
|
<li
|
||||||
|
>2. 佣金比例<span class="color-red">{{ item.brokerageRate }}</span
|
||||||
|
>%</li
|
||||||
|
>
|
||||||
|
</ul>
|
||||||
|
<div v-if="item.qrCodeUrl" class="vip-card-qrcode">
|
||||||
|
<el-icon class="absolute right-0px top-0px cursor-pointer" @click="item.qrCodeUrl = ''"><Close /></el-icon>
|
||||||
|
<qrcode-vue :value="item.qrCodeUrl" :size="150" level="H" />
|
||||||
|
<div>请使用微信扫二维码</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<el-button class="vip-card-btn" :loading="item.btnloading" @click="pay(item)">立即开通</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch, onMounted } from 'vue'
|
||||||
|
import { listVip, submitPayOrder, getPayStatus } from '@/api/pay/index'
|
||||||
|
import { accDiv } from '@/utils/utils'
|
||||||
|
import { Close } from '@element-plus/icons-vue'
|
||||||
|
import type { AppPayWalletPackageRespVO } from '@/api/pay/types'
|
||||||
|
// @ts-ignore
|
||||||
|
import QrcodeVue from 'qrcode.vue'
|
||||||
|
import useUserStore from '@/store/user'
|
||||||
|
const userStore = useUserStore()
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const emit = defineEmits(['update:modelValue'])
|
||||||
|
|
||||||
|
const visible = ref(props.modelValue)
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
(val) => (visible.value = val)
|
||||||
|
)
|
||||||
|
watch(visible, (val) => emit('update:modelValue', val))
|
||||||
|
|
||||||
|
const viplist = ref<AppPayWalletPackageRespVO[]>([])
|
||||||
|
const loading = ref(false)
|
||||||
|
const init = async () => {
|
||||||
|
try {
|
||||||
|
loading.value = true
|
||||||
|
const res = await listVip()
|
||||||
|
viplist.value = res.data
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
console.log(viplist.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
init()
|
||||||
|
})
|
||||||
|
|
||||||
|
const orderId = ref(0)
|
||||||
|
const pay = async (row: AppPayWalletPackageRespVO) => {
|
||||||
|
if (userStore.userInfoRes.vipLevel === 1 && row.level === 1) return ElMessage.error('您已经是VIP了,无需重复开通')
|
||||||
|
if (userStore.userInfoRes.vipLevel === 2 && row.level === 1) return ElMessage.error('您已经是SVIP了,过期之后再开通VIP')
|
||||||
|
if (userStore.userInfoRes.vipLevel === 2 && row.level === 2) return ElMessage.error('您已经是SVIP了,无需重复开通')
|
||||||
|
if (row.qrCodeUrl) return ElMessage.error('支付二维码已生成,请勿重复生成')
|
||||||
|
viplist.value.forEach((item) => {
|
||||||
|
if (item.id !== row.id) {
|
||||||
|
item.qrCodeUrl = ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
row.btnloading = true
|
||||||
|
const res = await submitPayOrder({
|
||||||
|
id: row.id,
|
||||||
|
memberId: userStore.userId, // 用户id
|
||||||
|
channelCode: 'wx_native',
|
||||||
|
})
|
||||||
|
if (res.code === 0) {
|
||||||
|
row.qrCodeUrl = res.data.displayContent
|
||||||
|
orderId.value = res.data.orderId
|
||||||
|
// 打开轮询任务
|
||||||
|
createQueryInterval(row)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
row.btnloading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 轮询查询任务 */
|
||||||
|
const interval = ref()
|
||||||
|
const createQueryInterval = (row: AppPayWalletPackageRespVO) => {
|
||||||
|
if (interval.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
interval.value = setInterval(async () => {
|
||||||
|
const data = await getPayStatus({ id: orderId.value })
|
||||||
|
// 已支付
|
||||||
|
if (data.data.status === 10) {
|
||||||
|
clearQueryInterval(row)
|
||||||
|
ElMessage.success('支付成功!')
|
||||||
|
}
|
||||||
|
// 已取消
|
||||||
|
if (data.data.status === 20) {
|
||||||
|
clearQueryInterval(row)
|
||||||
|
ElMessage.error('支付已关闭!')
|
||||||
|
}
|
||||||
|
}, 1000 * 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 清空查询任务 */
|
||||||
|
const clearQueryInterval = (row: AppPayWalletPackageRespVO) => {
|
||||||
|
// 清空各种弹窗
|
||||||
|
row.qrCodeUrl = ''
|
||||||
|
// 清空任务
|
||||||
|
clearInterval(interval.value)
|
||||||
|
interval.value = undefined
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.vip-modal-title {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
.vip-cards {
|
||||||
|
display: flex;
|
||||||
|
gap: 32px;
|
||||||
|
justify-content: center;
|
||||||
|
margin: 24px 0;
|
||||||
|
}
|
||||||
|
.vip-card {
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
|
||||||
|
padding: 24px 32px;
|
||||||
|
width: 260px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding-bottom: 70px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.vip-card-header {
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
padding-bottom: 12px;
|
||||||
|
border-radius: 8px 8px 0 0;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
padding: 10px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
.vip-card-header.basic {
|
||||||
|
background: linear-gradient(90deg, #f7b7a3, #e97c6a);
|
||||||
|
}
|
||||||
|
.vip-card-header.pro {
|
||||||
|
background: linear-gradient(90deg, #f7b7a3, #e97c6a);
|
||||||
|
}
|
||||||
|
.vip-card-title {
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.vip-card-subtitle {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.vip-card-price {
|
||||||
|
margin: 12px 0;
|
||||||
|
font-size: 28px;
|
||||||
|
color: #e74c3c;
|
||||||
|
font-weight: bold;
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.vip-card-price .origin {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #bbb;
|
||||||
|
text-decoration: line-through;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
.vip-card-price .per {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #888;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
.vip-card-features {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0 0 16px 0;
|
||||||
|
color: #444;
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
.vip-card-features li {
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
.vip-card-features .highlight {
|
||||||
|
color: #e74c3c;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.vip-card-btn {
|
||||||
|
width: 80%;
|
||||||
|
margin-top: 8px;
|
||||||
|
border-radius: 24px;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 20px;
|
||||||
|
}
|
||||||
|
:deep(.vip-card-qrcode) {
|
||||||
|
position: absolute !important;
|
||||||
|
inset: 0 !important;
|
||||||
|
z-index: 1;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
157
components/kl-quick-menu/index.vue
Normal file
157
components/kl-quick-menu/index.vue
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
<template>
|
||||||
|
<div class="fixed-button-group">
|
||||||
|
<div class="button-item" @click="handleVip">
|
||||||
|
<el-badge :is-dot="readCount" class="item">
|
||||||
|
<el-icon class="icon-item color-#10c55b!"><Trophy /></el-icon>
|
||||||
|
</el-badge>
|
||||||
|
<span class="button-text">VIP</span>
|
||||||
|
</div>
|
||||||
|
<div class="button-item" @click="handleService">
|
||||||
|
<el-badge :is-dot="readCount" class="item">
|
||||||
|
<el-icon class="icon-item color-#10c55b!"><Service /></el-icon>
|
||||||
|
</el-badge>
|
||||||
|
<span class="button-text">客服</span>
|
||||||
|
</div>
|
||||||
|
<div class="button-item" @click="handleSign">
|
||||||
|
<el-icon class="icon-item color-#10c55b!"><Checked /></el-icon>
|
||||||
|
<span class="button-text">签到</span>
|
||||||
|
</div>
|
||||||
|
<div class="button-item" @click="handlePublish">
|
||||||
|
<el-icon class="icon-item color-#C561F9!"><Promotion /></el-icon>
|
||||||
|
<span class="button-text">发布</span>
|
||||||
|
</div>
|
||||||
|
<div class="button-item mt-10px" @click="scrollToTop">
|
||||||
|
<el-icon class="icon-item"><Top /></el-icon>
|
||||||
|
<span class="button-text">顶部</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- 打开客服弹窗 弄成组件 -->
|
||||||
|
<KlService v-if="dialogVisible" v-model:dialog-visible="dialogVisible"></KlService>
|
||||||
|
<!-- vip组件 -->
|
||||||
|
<KlVip v-if="showVip" v-model="showVip"></KlVip>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, onMounted } from 'vue'
|
||||||
|
import useUserStore from '@/store/user'
|
||||||
|
import { Service, Top, Promotion, Checked, Trophy } from '@element-plus/icons-vue'
|
||||||
|
import KlService from './components/kl-service.vue'
|
||||||
|
|
||||||
|
const showVip = ref(false)
|
||||||
|
const handleVip = () => {
|
||||||
|
// 判断是否登录
|
||||||
|
const userStore = useUserStore()
|
||||||
|
if (!userStore.token) {
|
||||||
|
ElMessage.error('请先登录')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
showVip.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const scrollToTop = () => {
|
||||||
|
window.scrollTo({
|
||||||
|
top: 0,
|
||||||
|
behavior: 'smooth', // 平滑滚动
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePublish = () => {
|
||||||
|
// 判断是否登录
|
||||||
|
const userStore = useUserStore()
|
||||||
|
if (!userStore.token) {
|
||||||
|
ElMessage.error('请先登录')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 新开窗口 用router跳转 新窗口打开
|
||||||
|
navigateTo('/upnew/drawe')
|
||||||
|
}
|
||||||
|
|
||||||
|
const dialogVisible = ref(false)
|
||||||
|
const handleService = () => {
|
||||||
|
// 判断是否登录
|
||||||
|
const userStore = useUserStore()
|
||||||
|
if (!userStore.token) {
|
||||||
|
ElMessage.error('请先登录')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dialogVisible.value = true
|
||||||
|
// 读取未读消息
|
||||||
|
readCount.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 签到
|
||||||
|
const handleSign = () => {
|
||||||
|
// 判断是否登录
|
||||||
|
const userStore = useUserStore()
|
||||||
|
if (!userStore.token) {
|
||||||
|
ElMessage.error('请先登录')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
navigateTo('/sign-page')
|
||||||
|
}
|
||||||
|
|
||||||
|
const readCount = ref(false)
|
||||||
|
onMounted(() => {
|
||||||
|
const userStore = useUserStore()
|
||||||
|
userStore.mqttClient?.onMessage((topic: string, message: any) => {
|
||||||
|
if (topic.indexOf(`zbjk_message_kefu`) === -1) return
|
||||||
|
console.log('接收消息---------', topic, message)
|
||||||
|
const msg = JSON.parse(message)
|
||||||
|
if (msg.userId === userStore.userInfoRes.id) return
|
||||||
|
if (!dialogVisible.value) {
|
||||||
|
// 显示未读
|
||||||
|
readCount.value = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.fixed-button-group {
|
||||||
|
position: fixed;
|
||||||
|
right: 10px;
|
||||||
|
bottom: 120px;
|
||||||
|
z-index: 9;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
|
||||||
|
.button-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 41px;
|
||||||
|
height: 52px;
|
||||||
|
background-color: #fff;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
||||||
|
transition: all 0.3s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #10c55b;
|
||||||
|
.button-text,
|
||||||
|
.icon-item {
|
||||||
|
color: #fff !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-icon {
|
||||||
|
font-size: 20px;
|
||||||
|
color: #666;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-text {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #666;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-badge {
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
29
components/kl-register/index.ts
Normal file
29
components/kl-register/index.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { createApp, ref } from 'vue'
|
||||||
|
import GlobalPopup from './index.vue'
|
||||||
|
|
||||||
|
const popupInstance = ref()
|
||||||
|
|
||||||
|
const openRegister = () => {
|
||||||
|
if (!popupInstance.value) {
|
||||||
|
const app = createApp(GlobalPopup, {
|
||||||
|
visible: true,
|
||||||
|
onClose: () => {
|
||||||
|
closeRegister()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const container = document.createElement('div')
|
||||||
|
document.body.appendChild(container)
|
||||||
|
popupInstance.value = app.mount(container)
|
||||||
|
}
|
||||||
|
// popupInstance.value.$el.innerHTML = content
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeRegister = () => {
|
||||||
|
if (popupInstance.value) {
|
||||||
|
popupInstance.value.$el.parentNode.removeChild(popupInstance.value.$el)
|
||||||
|
popupInstance.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { openRegister, closeRegister }
|
||||||
333
components/kl-register/index.vue
Normal file
333
components/kl-register/index.vue
Normal file
@ -0,0 +1,333 @@
|
|||||||
|
<template>
|
||||||
|
<div v-if="visible" class="popup-overlay">
|
||||||
|
<div class="popup-content">
|
||||||
|
<div class="register-container relative">
|
||||||
|
<el-icon class="absolute right-0 top-0 cursor-pointer" @click="onClose()"><Close /></el-icon>
|
||||||
|
<!-- 左侧插图 -->
|
||||||
|
<div class="register-left">
|
||||||
|
<img src="@/assets/images/login-illustration.png" alt="register" class="register-img" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 右侧注册表单 -->
|
||||||
|
<div class="register-right">
|
||||||
|
<h2 class="register-title">快速注册</h2>
|
||||||
|
|
||||||
|
<!-- 注册表单 -->
|
||||||
|
<el-form ref="formRef" :model="registerForm" :rules="rules" class="register-form">
|
||||||
|
<!-- 手机号输入 -->
|
||||||
|
<el-form-item prop="phone">
|
||||||
|
<div class="phone-input">
|
||||||
|
<div class="area-code">+86</div>
|
||||||
|
<el-input v-model="registerForm.phone" placeholder="请输入注册手机号" class="phone-number w-280px!" />
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<!-- 验证码输入 -->
|
||||||
|
<el-form-item prop="code">
|
||||||
|
<div class="verify-code-input">
|
||||||
|
<el-input v-model="registerForm.code" placeholder="请输入短信验证码" />
|
||||||
|
<el-button type="primary" class="get-code-btn" :disabled="counting > 0" @click="handleSendCode">
|
||||||
|
{{ counting > 0 ? `${counting}s后重新获取` : '获取验证码' }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<!-- 注册按钮 -->
|
||||||
|
<el-button type="primary" class="register-button" @click="handleRegister"> 立即注册 </el-button>
|
||||||
|
|
||||||
|
<!-- 用户协议 -->
|
||||||
|
<div class="agreement">
|
||||||
|
<el-checkbox v-model="registerForm.agreement"> 我已阅读并同意<span class="link">《多多用户协议》</span> </el-checkbox>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 登录入口 -->
|
||||||
|
<div class="login-link"> 已有账号?<span class="link" @click="goToLogin">点击登录</span> </div>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, reactive } from 'vue'
|
||||||
|
import type { FormInstance } from 'element-plus'
|
||||||
|
import { Close } from '@element-plus/icons-vue'
|
||||||
|
import { sendSms } from '@/api/common/index'
|
||||||
|
import { loginByMobile } from '@/api/login/index'
|
||||||
|
const { $openLogin } = useNuxtApp()
|
||||||
|
|
||||||
|
import { refreshToken as REFRESHTOKEN } from '@/utils/axios'
|
||||||
|
import useUserStore from '@/store/user'
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
onClose: {
|
||||||
|
type: Function,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const formRef = ref<FormInstance>()
|
||||||
|
const counting = ref(0)
|
||||||
|
|
||||||
|
const registerForm = reactive({
|
||||||
|
phone: '',
|
||||||
|
code: '',
|
||||||
|
agreement: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
// 表单验证规则
|
||||||
|
const rules = {
|
||||||
|
phone: [
|
||||||
|
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||||
|
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' },
|
||||||
|
],
|
||||||
|
code: [
|
||||||
|
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||||
|
{ len: 6, message: '验证码长度应为6位', trigger: 'blur' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送验证码
|
||||||
|
const handleSendCode = async () => {
|
||||||
|
if (counting.value > 0) return
|
||||||
|
|
||||||
|
// 验证手机号
|
||||||
|
try {
|
||||||
|
await formRef.value?.validateField('phone')
|
||||||
|
} catch (error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: 调用发送验证码接口
|
||||||
|
const res = await sendSms({
|
||||||
|
mobile: registerForm.phone,
|
||||||
|
scene: 1, // 场景值,根据实际情况设置
|
||||||
|
})
|
||||||
|
if (res.code !== 0) return
|
||||||
|
if (res.code === 0) {
|
||||||
|
ElMessage.success('验证码发送成功')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始倒计时
|
||||||
|
counting.value = 60
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
counting.value--
|
||||||
|
if (counting.value <= 0) {
|
||||||
|
clearInterval(timer)
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注册处理
|
||||||
|
const handleRegister = async () => {
|
||||||
|
if (!registerForm.agreement) {
|
||||||
|
ElMessage.warning('请先同意用户协议')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await formRef.value?.validate()
|
||||||
|
// TODO: 调用注册接口
|
||||||
|
const res = await loginByMobile({
|
||||||
|
mobile: registerForm.phone,
|
||||||
|
code: registerForm.code,
|
||||||
|
})
|
||||||
|
if (res.code === 0) {
|
||||||
|
const data = res.data
|
||||||
|
REFRESHTOKEN.setToken(data.accessToken, data.refreshToken)
|
||||||
|
REFRESHTOKEN.setUserId(data.userId.toString())
|
||||||
|
REFRESHTOKEN.setUserName(registerForm.phone)
|
||||||
|
userStore.setToken(data.accessToken)
|
||||||
|
userStore.setUserId(data.userId.toString())
|
||||||
|
userStore.setUserName(registerForm.phone)
|
||||||
|
userStore.setRefreshToken(data.refreshToken)
|
||||||
|
ElMessage.success('注册成功')
|
||||||
|
props.onClose()
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 跳转到登录
|
||||||
|
const goToLogin = () => {
|
||||||
|
props.onClose()
|
||||||
|
// TODO: 触发切换到登录页面的事件
|
||||||
|
// emit('switch-to-login')
|
||||||
|
$openLogin && $openLogin()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.register-dialog {
|
||||||
|
.el-dialog {
|
||||||
|
border-radius: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-dialog__header {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-dialog__body {
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.popup-overlay {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 10;
|
||||||
|
.popup-content {
|
||||||
|
background-color: white;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.register-container {
|
||||||
|
display: flex;
|
||||||
|
height: 508px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: #f9faff;
|
||||||
|
width: 480px;
|
||||||
|
|
||||||
|
.register-img {
|
||||||
|
width: 438px;
|
||||||
|
height: 258px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-right {
|
||||||
|
padding: 22px 25px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-title {
|
||||||
|
font-size: 20px;
|
||||||
|
color: #333;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 40px;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-form {
|
||||||
|
width: 320px;
|
||||||
|
margin: 0 auto;
|
||||||
|
|
||||||
|
.phone-input {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
background: #f5f5f5;
|
||||||
|
border-radius: 4px;
|
||||||
|
|
||||||
|
.area-code {
|
||||||
|
padding: 0 12px;
|
||||||
|
color: #333;
|
||||||
|
font-size: 14px;
|
||||||
|
border-right: 1px solid #dcdfe6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phone-number {
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
:deep(.el-input__wrapper) {
|
||||||
|
background: transparent;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.verify-code-input {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
|
||||||
|
.el-input {
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
:deep(.el-input__wrapper) {
|
||||||
|
background: #f5f5f5;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.get-code-btn {
|
||||||
|
width: 120px;
|
||||||
|
height: 40px;
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
color: #999;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
border-color: #dcdfe6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-button {
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
margin-top: 24px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agreement {
|
||||||
|
margin: 16px 0;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
text-align: left;
|
||||||
|
|
||||||
|
.link {
|
||||||
|
color: #1677ff;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-link {
|
||||||
|
text-align: right;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
margin-top: 20px;
|
||||||
|
|
||||||
|
.link {
|
||||||
|
color: #1677ff;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-form-item) {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-input__wrapper) {
|
||||||
|
background: #f5f5f5;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-input__inner) {
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
28
components/kl-svg-icon/index.vue
Normal file
28
components/kl-svg-icon/index.vue
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<template>
|
||||||
|
<svg aria-hidden="true" class="svg-icon">
|
||||||
|
<use :xlink:href="symbolId" :fill="color" />
|
||||||
|
</svg>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
prefix: { type: String, default: 'icon' },
|
||||||
|
iconClass: { type: String, required: true },
|
||||||
|
color: { type: String, default: '' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const symbolId = computed(() => `#${props.prefix}-${props.iconClass}`)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.svg-icon {
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
vertical-align: -0.15em;
|
||||||
|
overflow: hidden;
|
||||||
|
fill: currentColor;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
150
components/kl-tab-bar/index.vue
Normal file
150
components/kl-tab-bar/index.vue
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
<template>
|
||||||
|
<el-tabs
|
||||||
|
v-model="tabActive"
|
||||||
|
:class="['demo-tabs', { 'no-border': !border, 'page-header': pageHeader }]"
|
||||||
|
:before-leave="() => !loading"
|
||||||
|
@tab-change="handleChange"
|
||||||
|
>
|
||||||
|
<el-tab-pane v-for="(item, index) in data" :key="index" :label="item.label" :name="item.value">
|
||||||
|
<template v-if="showNum" #label>
|
||||||
|
<img v-if="item.value === tabActive && showIcon" src="@/assets/images/2.png" alt="" srcset="" class="mr-7px" />
|
||||||
|
<span>{{ item.label }}</span>
|
||||||
|
<el-badge :value="item.num" class="item" :max="9999999999999" :hidden="!item.num" />
|
||||||
|
</template>
|
||||||
|
</el-tab-pane>
|
||||||
|
</el-tabs>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { TabPaneName } from 'element-plus'
|
||||||
|
import type { PropType } from 'vue'
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
const router = useRouter()
|
||||||
|
const props = defineProps({
|
||||||
|
data: {
|
||||||
|
type: Array as PropType<{ num?: number; label: string; value: string | number; [key: string]: any }[]>,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
loading: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
//是否显示底边框
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
showNum: {
|
||||||
|
//显示数量
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
pageHeader: {
|
||||||
|
//是否是页面头部
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
modelValue: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
/**切换是否是路由模式,true则会跳转到对应value值中的路由页面*/
|
||||||
|
route: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
showIcon: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const emits = defineEmits<{
|
||||||
|
(e: 'update:modelValue', value: number | string): void
|
||||||
|
(e: 'change', value: TabPaneName): void
|
||||||
|
}>()
|
||||||
|
const tabActive = computed({
|
||||||
|
get() {
|
||||||
|
return props.modelValue
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
emits('update:modelValue', val)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const handleChange = (name: TabPaneName) => {
|
||||||
|
if (props.route && name) {
|
||||||
|
router.push(name as string)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
emits('change', name)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
:deep(.el-tabs__nav-wrap::after) {
|
||||||
|
height: 1px;
|
||||||
|
}
|
||||||
|
.no-border :deep(.el-tabs__nav-wrap::after) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
:deep(.el-tabs__header) {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
:deep(.el-tabs__item) {
|
||||||
|
height: auto;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
color: #333333;
|
||||||
|
font-size: 20px;
|
||||||
|
margin-right: 40px;
|
||||||
|
}
|
||||||
|
:deep(.el-tabs__item > span) {
|
||||||
|
margin-right: 2px;
|
||||||
|
}
|
||||||
|
.page-header {
|
||||||
|
padding: 6px 10px 8px;
|
||||||
|
:deep(.el-tabs__header) {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.page-header :deep(.el-tabs__item) {
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
:deep(.el-tabs__item.is-active),
|
||||||
|
:deep(.el-tabs__item:hover) {
|
||||||
|
color: #1a65ff !important;
|
||||||
|
}
|
||||||
|
.page-table-wrap > .el-tabs.el-tabs--top :deep(.el-tabs__active-bar.is-top) {
|
||||||
|
height: 2px;
|
||||||
|
background-color: transparent;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box !important;
|
||||||
|
}
|
||||||
|
.page-table-wrap > .el-tabs.el-tabs--top :deep(.el-tabs__active-bar.is-top::before) {
|
||||||
|
content: '';
|
||||||
|
height: 2px;
|
||||||
|
display: block;
|
||||||
|
background: $color-primary;
|
||||||
|
width: var(--actbar-w);
|
||||||
|
}
|
||||||
|
.page-header :deep(.el-tabs__item.is-active) {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.page-header :deep(.el-tabs__active-bar.is-top) {
|
||||||
|
height: 4px;
|
||||||
|
background-color: transparent;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box !important;
|
||||||
|
}
|
||||||
|
.page-header :deep(.el-tabs__active-bar.is-top::before) {
|
||||||
|
content: '';
|
||||||
|
border-radius: 2px;
|
||||||
|
height: 4px;
|
||||||
|
width: 20px;
|
||||||
|
display: block;
|
||||||
|
background: $color-primary;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
:deep(.el-badge) {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
26
components/kl-tab-bar/v2/index.vue
Normal file
26
components/kl-tab-bar/v2/index.vue
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<template>
|
||||||
|
<el-button v-for="(item, index) in props.data" :key="index" :type="modelValue === item.value ? 'primary' : ''" @click="handleChange(item)">{{
|
||||||
|
item.label
|
||||||
|
}}</el-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type{ PropType } from 'vue'
|
||||||
|
const props = defineProps({
|
||||||
|
data: {
|
||||||
|
type: Array as PropType<{ num?: number; label: string; value: string | number; [key: string]: any }[]>,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const emits = defineEmits(['change'])
|
||||||
|
|
||||||
|
const modelValue = defineModel<number | string>('modelValue', {
|
||||||
|
required: true,
|
||||||
|
}) // 双向绑定的value
|
||||||
|
|
||||||
|
const handleChange = (value: { value: string | number; [key: string]: any }) => {
|
||||||
|
modelValue.value = value.value
|
||||||
|
emits('change', value)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
53
components/kl-tag/index.vue
Normal file
53
components/kl-tag/index.vue
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="kl-tag"
|
||||||
|
:style="{
|
||||||
|
color,
|
||||||
|
background: bgColor,
|
||||||
|
borderRadius,
|
||||||
|
border: showBorder ? '1px solid' : '',
|
||||||
|
borderColor: borderColor ? borderColor : color,
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<slot></slot>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { PropType } from 'vue'
|
||||||
|
defineProps({
|
||||||
|
color: {
|
||||||
|
//文字颜色
|
||||||
|
type: String as PropType<string>,
|
||||||
|
default: '#3A84F0',
|
||||||
|
},
|
||||||
|
bgColor: {
|
||||||
|
//背景色
|
||||||
|
type: String as PropType<string>,
|
||||||
|
default: '#EAF1FF',
|
||||||
|
},
|
||||||
|
showBorder: {
|
||||||
|
//是否需要边框
|
||||||
|
type: Boolean as PropType<boolean>,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
borderColor: {
|
||||||
|
//边框颜色
|
||||||
|
type: String as PropType<string>,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
borderRadius: {
|
||||||
|
//圆角大小
|
||||||
|
type: String as PropType<string>,
|
||||||
|
default: '4px',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.kl-tag {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 1px 4px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
418
components/kl-uploader/index.vue
Normal file
418
components/kl-uploader/index.vue
Normal file
@ -0,0 +1,418 @@
|
|||||||
|
<template>
|
||||||
|
<div class="upload-file">
|
||||||
|
<el-upload
|
||||||
|
ref="uploadRef"
|
||||||
|
v-loading="loading"
|
||||||
|
v-bind="$attrs"
|
||||||
|
:file-list="fileList"
|
||||||
|
drag
|
||||||
|
:disabled="disabled"
|
||||||
|
:multiple="limit > 1"
|
||||||
|
:on-error="handleUploadError"
|
||||||
|
:on-change="handleChange"
|
||||||
|
:auto-upload="false"
|
||||||
|
:show-file-list="listType === 'picture-card' ? true : false"
|
||||||
|
:list-type="listType"
|
||||||
|
:on-preview="handlePictureCardPreview"
|
||||||
|
:on-remove="handleRemove"
|
||||||
|
>
|
||||||
|
<slot>
|
||||||
|
<el-button type="primary" :disabled="disabled">选择文件</el-button>
|
||||||
|
</slot>
|
||||||
|
<template v-if="showTip" #tip>
|
||||||
|
<div class="m-t-10px leading-24px">
|
||||||
|
<slot name="des">
|
||||||
|
<div>
|
||||||
|
<!-- <span>附件内容说明:</span> -->
|
||||||
|
<span class="text-[#999999]">{{ tips }}</span>
|
||||||
|
</div>
|
||||||
|
</slot>
|
||||||
|
<!-- <slot name="tips">
|
||||||
|
<div>
|
||||||
|
<span>请上传 大小不超过</span>
|
||||||
|
<span class="color-#FA5940 m-l-2px m-r-2px">{{ size }}MB</span>
|
||||||
|
<span>格式为</span>
|
||||||
|
<span class="color-#FA5940 m-l-2px m-r-2px">{{ fileType.join('/') }}</span>
|
||||||
|
<span>的文件</span>
|
||||||
|
</div>
|
||||||
|
</slot> -->
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-if="listType === 'picture-card'" #file="{ file }">
|
||||||
|
<div v-if="!handelFileType(file.name)" class="custom-preview-card">
|
||||||
|
<div class="file-type-icon cursor-pointer" @click="handlePictureCardDown(file)">
|
||||||
|
<el-icon :size="32"><Document /></el-icon>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-upload>
|
||||||
|
<div v-if="loading" class="text-12px color-#999">{{ loadingtext }}</div>
|
||||||
|
|
||||||
|
<transition-group v-if="listType !== 'picture-card'" class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul">
|
||||||
|
<li v-for="(file, index) in fileList" :key="file.uid" class="el-upload-list__item ele-upload-list__item-content">
|
||||||
|
<div class="ele-upload-list__item-content upload-item">
|
||||||
|
<div class="curpor-pointer" @click="handlePictureCardDown(file)">
|
||||||
|
<span class="el-icon-document cursor-pointer pl-9px">{{ file.name }} </span>
|
||||||
|
</div>
|
||||||
|
<div class="ele-upload-list__item-content-action">
|
||||||
|
<el-link :underline="false" type="danger" :disabled="disabled" @click="handleDelete(index)">删除 </el-link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</transition-group>
|
||||||
|
|
||||||
|
<el-image-viewer v-if="dialogVisible" :url-list="[dialogImageUrl]" @close="dialogVisible = false" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { PropType } from 'vue'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { uploadV2, creatFile } from '@/api/common/index'
|
||||||
|
import { Document } from '@element-plus/icons-vue'
|
||||||
|
import type { UploadUserFile, UploadInstance } from 'element-plus'
|
||||||
|
import { accDiv } from '@/utils/utils'
|
||||||
|
// import CryptoJS from 'crypto-js' // 引入 crypto-js
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
/** 文件个数限制 */
|
||||||
|
limit: {
|
||||||
|
type: Number,
|
||||||
|
default: 1,
|
||||||
|
},
|
||||||
|
/** 文件大小限制(M) */
|
||||||
|
size: {
|
||||||
|
type: Number,
|
||||||
|
default: 100,
|
||||||
|
},
|
||||||
|
/** 文件类型 */
|
||||||
|
fileType: {
|
||||||
|
type: Array as PropType<string[]>,
|
||||||
|
// default: () => ['png', 'jpg', 'jpeg', 'doc', 'xls', 'ppt', 'pdf', 'txt'],
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
/** 上传地址 */
|
||||||
|
uploadUrl: {
|
||||||
|
type: String,
|
||||||
|
default: '/prod-api/app-api/infra/file/presigned-url',
|
||||||
|
},
|
||||||
|
/** 提示文案 */
|
||||||
|
tips: {
|
||||||
|
type: String,
|
||||||
|
default: '提供佐证变更有效的证明文件(邮件/聊天截图/情况说明)',
|
||||||
|
},
|
||||||
|
/** 提示文案 */
|
||||||
|
showTip: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
/** 是否预览cad */
|
||||||
|
cadShow: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
/** 组件类型 */
|
||||||
|
listType: {
|
||||||
|
type: String as PropType<'text' | 'picture' | 'picture-card'>,
|
||||||
|
default: 'text', // picture" | "text" | "picture-card
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits(['validate', 'preview'])
|
||||||
|
const uploadRef = ref<UploadInstance>()
|
||||||
|
const fileList = defineModel<any>('fileList', {
|
||||||
|
default: [],
|
||||||
|
})
|
||||||
|
|
||||||
|
const fileChange = ref()
|
||||||
|
const handleChange = async (uploadFile: UploadUserFile) => {
|
||||||
|
if (uploadFile.status !== 'ready') return
|
||||||
|
/** 上传前校验 */
|
||||||
|
if (handleBeforeUpload(uploadFile)) {
|
||||||
|
fileChange.value = uploadFile
|
||||||
|
// 新增:清除上传组件内部缓存
|
||||||
|
uploadRef.value?.handleRemove(fileChange.value) // 关键:主动触发上传组件的remove方法
|
||||||
|
return
|
||||||
|
}
|
||||||
|
/** 上传 */
|
||||||
|
await handleUploadFile(uploadFile)
|
||||||
|
}
|
||||||
|
/** 上传前校验 */
|
||||||
|
const handleBeforeUpload = (rawFile: UploadUserFile) => {
|
||||||
|
if (fileList.value.length + 1 > props.limit) {
|
||||||
|
handleExceed()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (props.size > 0 && rawFile.size && +accDiv(accDiv(rawFile.size, 1024), 1024) > props.size) {
|
||||||
|
ElMessage.error(`文件大小不能超过${props.size}M`)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
const ext = rawFile.name.split('.').pop()?.toLowerCase()
|
||||||
|
if (ext && props.fileType?.length && !props.fileType.includes(ext)) {
|
||||||
|
ElMessage.error(`文件格式不正确, 请上传${props.fileType.join('/')}格式文件!`)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const handleExceed = () => {
|
||||||
|
ElMessage.error(`最多只能上传 ${props.limit} 个文件`)
|
||||||
|
}
|
||||||
|
const handleUploadError = (err: any) => {
|
||||||
|
ElMessage.error('文件上传失败:' + err.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 上传 */
|
||||||
|
const loading = ref(false)
|
||||||
|
const loadingtext = ref('上传中...')
|
||||||
|
const uploadUrlV2 = ref('')
|
||||||
|
const fileUrl = ref('')
|
||||||
|
const configId = ref('')
|
||||||
|
const path = ref('')
|
||||||
|
const getUploadConfig = async (options: UploadUserFile) => {
|
||||||
|
path.value = `${options.uid}/${dayjs(new Date()).format('YYYY/MM/DD/HH/mm/ss')}/${options.name}`
|
||||||
|
try {
|
||||||
|
const response = await uploadV2(props.uploadUrl, { path: path.value })
|
||||||
|
if (response.code !== 0) return ElMessage.error(response.message)
|
||||||
|
uploadUrlV2.value = response.data.uploadUrl
|
||||||
|
fileUrl.value = response.data.url
|
||||||
|
configId.value = response.data.configId
|
||||||
|
} catch (err) {
|
||||||
|
loading.value = false
|
||||||
|
console.error('获取上传配置失败:', err)
|
||||||
|
alert('获取上传参数失败,请重试')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 上传到服务器 */
|
||||||
|
const UploadFilled = async (options: UploadUserFile) => {
|
||||||
|
try {
|
||||||
|
const res = await creatFile({
|
||||||
|
configId: Number(configId.value),
|
||||||
|
path: path.value,
|
||||||
|
name: options.name,
|
||||||
|
url: fileUrl.value,
|
||||||
|
size: options.size as number,
|
||||||
|
})
|
||||||
|
if (res.code !== 0) return ElMessage.error(res.message)
|
||||||
|
ElMessage.success('上传成功')
|
||||||
|
const newFile = {
|
||||||
|
name: options?.name,
|
||||||
|
url: fileUrl.value,
|
||||||
|
size: options?.size,
|
||||||
|
uid: options.uid,
|
||||||
|
title: options?.name,
|
||||||
|
fileId: res.data,
|
||||||
|
}
|
||||||
|
// 更新文件列表
|
||||||
|
fileList.value = [...fileList.value, newFile]
|
||||||
|
emit('validate')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取上传配置失败:', error)
|
||||||
|
alert('creatFile上传失败,请重试')
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** fetch 监听不了进度 需要改成xhr */
|
||||||
|
const uploadWithProgress = (url: string, file: any, onProgress: (percent: number) => void) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const xhr = new XMLHttpRequest()
|
||||||
|
xhr.open('PUT', url, true)
|
||||||
|
xhr.setRequestHeader('Content-Type', file.raw.type)
|
||||||
|
|
||||||
|
xhr.upload.onprogress = function (event) {
|
||||||
|
if (event.lengthComputable) {
|
||||||
|
const percent = Math.round((event.loaded / event.total) * 100)
|
||||||
|
onProgress(percent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.onload = function () {
|
||||||
|
if (xhr.status >= 200 && xhr.status < 300) {
|
||||||
|
resolve(xhr.response)
|
||||||
|
} else {
|
||||||
|
reject(new Error('上传失败'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.onerror = function () {
|
||||||
|
reject(new Error('网络错误'))
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.send(file.raw)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const handleUploadFile = async (options: UploadUserFile) => {
|
||||||
|
try {
|
||||||
|
loading.value = true
|
||||||
|
await getUploadConfig(options)
|
||||||
|
// 使用PUT或POST方法上传(根据后端要求)
|
||||||
|
// const response = await fetch(uploadUrlV2.value, {
|
||||||
|
// method: 'PUT', // 或 POST,根据后端预签名URL的规则
|
||||||
|
// body: options.raw,
|
||||||
|
// headers: {
|
||||||
|
// 'Content-Type': (options.raw as Blob).type, // 设置文件类型
|
||||||
|
// },
|
||||||
|
// // onUploadProgress: (progressEvent: ProgressEvent) => {
|
||||||
|
// // const percentCompleted = Math.round((progressEvent.loaded / progressEvent.total) * 100)
|
||||||
|
// // loadingtext.value = `上传中...${percentCompleted}%`
|
||||||
|
// // },
|
||||||
|
// })
|
||||||
|
|
||||||
|
// if (response.ok) {
|
||||||
|
// await UploadFilled(options)
|
||||||
|
// // 此时文件已上传至OSS,fileUrl即为访问地址
|
||||||
|
// console.log('文件访问URL:', fileUrl.value)
|
||||||
|
// } else {
|
||||||
|
// loading.value = false
|
||||||
|
// throw new Error('上传文件失败')
|
||||||
|
// }
|
||||||
|
const response = await uploadWithProgress(uploadUrlV2.value, options, (percent) => {
|
||||||
|
loadingtext.value = `上传中...${percent}%`
|
||||||
|
})
|
||||||
|
if (response) {
|
||||||
|
// 错误处理
|
||||||
|
loading.value = false
|
||||||
|
return ElMessage.error(options.name + '上传错误')
|
||||||
|
}
|
||||||
|
await UploadFilled(options)
|
||||||
|
} catch (error) {
|
||||||
|
loading.value = false
|
||||||
|
ElMessage.error(options.name + '上传错误')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** 删除 */
|
||||||
|
const handleDelete = (index: number) => {
|
||||||
|
fileList.value.splice(index, 1)
|
||||||
|
emit('validate')
|
||||||
|
}
|
||||||
|
|
||||||
|
const dialogImageUrl = ref('')
|
||||||
|
const dialogVisible = ref(false)
|
||||||
|
const handleRemove = (uploadFile: any, uploadFiles: any) => {
|
||||||
|
console.log(uploadFile, uploadFiles)
|
||||||
|
fileList.value = fileList.value.filter((item: any) => item.uid !== uploadFile.uid)
|
||||||
|
emit('validate')
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePictureCardPreview = (uploadFile: any) => {
|
||||||
|
dialogImageUrl.value = uploadFile.url
|
||||||
|
dialogVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePictureCardDown = (uploadFile: any) => {
|
||||||
|
if (props.cadShow) {
|
||||||
|
emit('preview', uploadFile)
|
||||||
|
} else {
|
||||||
|
window.open(uploadFile.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 生成 MD5 唯一标识符
|
||||||
|
// const generateMd5 = () => {
|
||||||
|
// const timestamp = new Date().getTime() // 获取当前时间戳
|
||||||
|
// const randomString = Math.random().toString(36).substring(2) // 生成随机字符串
|
||||||
|
// const data = `${timestamp}${randomString}` // 组合时间戳和随机字符串
|
||||||
|
// return CryptoJS.MD5(data).toString() // 生成 MD5 哈希值
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 判断是否是图片
|
||||||
|
const handelFileType = (fileName: string) => {
|
||||||
|
const ext = fileName.split('.').pop()?.toLowerCase() || ''
|
||||||
|
return ['png', 'jpg', 'jpeg'].includes(ext)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.custom-preview-card {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
.file-type-icon {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -40%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.upload-file {
|
||||||
|
::v-deep(.el-upload-dragger) {
|
||||||
|
border: none !important;
|
||||||
|
padding: 0;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-file-list .el-upload-list__item {
|
||||||
|
line-height: 2;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
position: relative;
|
||||||
|
min-width: 361px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-file-list .ele-upload-list__item-content {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-item {
|
||||||
|
border: 1px solid #e4e7ed;
|
||||||
|
border-radius: 5px;
|
||||||
|
flex: 1;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ele-upload-list__item-content-action .el-link {
|
||||||
|
margin-right: 10px;
|
||||||
|
width: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-upload-list--picture-card .el-upload-list__item {
|
||||||
|
height: 81px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ::v-deep(.el-upload--picture-card) {
|
||||||
|
// height: 81px !important;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ::v-deep(.el-upload-list--picture-card) {
|
||||||
|
// .el-upload-list__item {
|
||||||
|
// height: 82px !important;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
::v-deep(.el-upload-list--picture-card) {
|
||||||
|
.el-upload-list__item {
|
||||||
|
width: 161px;
|
||||||
|
height: 81px;
|
||||||
|
// margin: 0 8px 8px 0;
|
||||||
|
}
|
||||||
|
.el-upload--picture-card {
|
||||||
|
width: 161px;
|
||||||
|
height: 81px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
::v-deep(.el-loading-spinner) {
|
||||||
|
.circular {
|
||||||
|
width: 32px !important;
|
||||||
|
height: 32px !important;
|
||||||
|
margin-top: 5px !important;
|
||||||
|
|
||||||
|
.path {
|
||||||
|
stroke-width: 3px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
::v-deep(.el-loading-spinner i) {
|
||||||
|
font-size: 32px !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
145
components/kl-wallpaper-category/index.vue
Normal file
145
components/kl-wallpaper-category/index.vue
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
<template>
|
||||||
|
<!-- 面包屑 -->
|
||||||
|
<div v-if="level.length > 1" class="mb--10px mt-20px pl-20px">
|
||||||
|
<el-breadcrumb :separator-icon="ArrowRight">
|
||||||
|
<el-breadcrumb-item v-for="(item, index) in level" :key="item.name" class="cursor-pointer" @click="handleClickBread(item, index)">{{
|
||||||
|
item.name
|
||||||
|
}}</el-breadcrumb-item>
|
||||||
|
</el-breadcrumb>
|
||||||
|
</div>
|
||||||
|
<div class="mt-30px box-border w-100% border border-[#EEEEEE] rounded-12px border-solid bg-[#FFFFFF] px-20px py-26px">
|
||||||
|
<div class="mb-14px flex items-start">
|
||||||
|
<div class="flex-shrink-0 text-15px text-[#333333] font-normal">{{ computType }}分类</div>
|
||||||
|
<div class="ml-30px mt--6px flex flex-wrap">
|
||||||
|
<div
|
||||||
|
v-for="(item, index) in projectTypeList"
|
||||||
|
:key="index"
|
||||||
|
class="mb-8px mr-26px cursor-pointer rounded-15px px-15px py-6px text-14px text-[#666666] font-normal"
|
||||||
|
:class="item.id === query.projectType ? 'bg-#EBEEFE! !text-[#1A65FF]' : ''"
|
||||||
|
@click="handleClick(item)"
|
||||||
|
>{{ item.name }}</div
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-start">
|
||||||
|
<div class="flex-shrink-0 text-15px text-[#333333] font-normal">软件分类</div>
|
||||||
|
<div class="ml-30px mt--6px flex flex-wrap">
|
||||||
|
<div
|
||||||
|
v-for="(item, index) in editionsList"
|
||||||
|
:key="index"
|
||||||
|
class="mb-8px mr-26px cursor-pointer rounded-15px px-15px py-6px text-14px text-[#666666] font-normal"
|
||||||
|
:class="item.id === query.editions ? '!bg-[#EBEEFE] !text-[#1A65FF]' : ''"
|
||||||
|
@click="query.editions = item.id"
|
||||||
|
>{{ item.name }}</div
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- <div class="mb-14px flex items-start">
|
||||||
|
<div class="flex-shrink-0 text-18px text-[#333333] font-normal">文本类型</div>
|
||||||
|
<div class="ml-30px mt--6px flex flex-wrap">
|
||||||
|
<div
|
||||||
|
v-for="(item, index) in sourceList"
|
||||||
|
:key="index"
|
||||||
|
class="mb-8px mr-26px cursor-pointer rounded-15px px-15px py-8px text-14px text-[#666666] font-normal"
|
||||||
|
:class="item.id === query.source ? '!bg-[#EBEEFE] !text-[#1A65FF]' : ''"
|
||||||
|
@click="query.source = item.id"
|
||||||
|
>{{ item.name }}</div
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div> -->
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { parent } from '@/api/upnew/index'
|
||||||
|
import type { pageReq } from '@/api/upnew/types'
|
||||||
|
import { ArrowRight } from '@element-plus/icons-vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
type: {
|
||||||
|
type: Number,
|
||||||
|
default: 1,
|
||||||
|
},
|
||||||
|
id: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
groundId: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const query = defineModel<pageReq>('modelValue', {
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
const level = defineModel<{ id: string; name: string; isChildren?: boolean }[]>('level', {
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
const computType = computed(() => {
|
||||||
|
return props.type === 1 ? '图纸' : props.type === 3 ? '模型' : '文本'
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleParentId = (type?: string) => {
|
||||||
|
if (level.value.length > 1) {
|
||||||
|
if (type === 'init' && level.value.find((c: any) => c.isChildren)) {
|
||||||
|
return level.value[level.value.length - 2].id || '' // 获取最后一个元素的 id 或 defaul
|
||||||
|
}
|
||||||
|
return level.value[level.value.length - 1].id || '' // 获取最后一个元素的 id 或 defaul
|
||||||
|
}
|
||||||
|
return '0'
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectTypeList = ref<any>([])
|
||||||
|
/** 获取分类下拉框 */
|
||||||
|
const getParent = (type?: string) => {
|
||||||
|
parent({
|
||||||
|
type: 1,
|
||||||
|
// @ts-ignore
|
||||||
|
parentId: handleParentId(type),
|
||||||
|
}).then((res) => {
|
||||||
|
if (Array.isArray(res.data)) {
|
||||||
|
projectTypeList.value = [...[{ id: handleParentId(type), name: '全部' }], ...res.data]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
getParent('init')
|
||||||
|
|
||||||
|
/** 版本 */
|
||||||
|
const editionsList = ref<any>([])
|
||||||
|
const getEditionsList = () => {
|
||||||
|
parent({
|
||||||
|
type: 2,
|
||||||
|
parentId: 0,
|
||||||
|
}).then((res) => {
|
||||||
|
if (Array.isArray(res.data)) {
|
||||||
|
editionsList.value = [...[{ id: '', name: '全部' }], ...res.data]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
getEditionsList()
|
||||||
|
|
||||||
|
const handleClick = (row: any) => {
|
||||||
|
query.value.title = ''
|
||||||
|
query.value.projectType = row.id
|
||||||
|
if (row.name === '全部') return
|
||||||
|
const isChildren = level.value.find((c: any) => c.isChildren)
|
||||||
|
if (!row.isChildren && isChildren) {
|
||||||
|
const index = level.value.length - 1
|
||||||
|
level.value[index] = { id: row.id, name: row.name, isChildren: true }
|
||||||
|
} else if (!row.isChildren && !isChildren) {
|
||||||
|
level.value.push({ id: row.id, name: row.name, isChildren: true })
|
||||||
|
} else {
|
||||||
|
level.value.push({ id: row.id, name: row.name })
|
||||||
|
getParent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClickBread = (row: any, index: number) => {
|
||||||
|
level.value.splice(index + 1)
|
||||||
|
query.value.title = ''
|
||||||
|
query.value.projectType = row.id
|
||||||
|
getParent()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
37
composables/useDollarFetchRequest.ts
Normal file
37
composables/useDollarFetchRequest.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { isArray } from "~/utils/utils";
|
||||||
|
|
||||||
|
type FetchType = typeof $fetch;
|
||||||
|
export type FetchOptions = Parameters<FetchType>[1];
|
||||||
|
|
||||||
|
export const useClientRequest = <T = unknown>(
|
||||||
|
url: string,
|
||||||
|
opts?: FetchOptions
|
||||||
|
) => {
|
||||||
|
const token = useCookie<string | undefined>("token");
|
||||||
|
const runtimeConfig = useRuntimeConfig();
|
||||||
|
|
||||||
|
const defaultOptions: FetchOptions = {
|
||||||
|
baseURL: runtimeConfig.public.apiBase,
|
||||||
|
onRequest({ options }) {
|
||||||
|
options.headers = options.headers || 'application/json';
|
||||||
|
if (token.value) {
|
||||||
|
// @ts-ignore
|
||||||
|
options.headers["authorization"] = "Bearer " + token.value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onResponse({ response }) {
|
||||||
|
if (+response.status === 200 && +response._data.code !== 200) {
|
||||||
|
ElMessage.error(response._data.msg);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onResponseError({ response }) {
|
||||||
|
ElMessage.error(
|
||||||
|
isArray(response._data.data.msg)
|
||||||
|
? response._data.data.msg[0]
|
||||||
|
: response._data.data.msg
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return $fetch<T>(url, { ...defaultOptions, ...opts });
|
||||||
|
};
|
||||||
37
composables/useFetchRequest.ts
Normal file
37
composables/useFetchRequest.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { useFetch } from "#app";
|
||||||
|
import type { UseFetchOptions } from "#app";
|
||||||
|
import { isArray } from "~/utils/utils";
|
||||||
|
|
||||||
|
export const useServerRequest = <T>(
|
||||||
|
url: string,
|
||||||
|
opts?: UseFetchOptions<T, unknown>
|
||||||
|
) => {
|
||||||
|
const token = useCookie<string | undefined>("token");
|
||||||
|
const runtimeConfig = useRuntimeConfig();
|
||||||
|
|
||||||
|
const defaultOptions: UseFetchOptions<unknown> = {
|
||||||
|
baseURL: runtimeConfig.public.apiBase,
|
||||||
|
onRequest({ options }) {
|
||||||
|
options.headers = options.headers || "application/json";
|
||||||
|
if (token.value) {
|
||||||
|
// @ts-ignore
|
||||||
|
options.headers["authorization"] = "Bearer " + token.value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onResponse({ response }) {
|
||||||
|
if (+response.status === 200 && +response._data.code !== 200) {
|
||||||
|
process.client && ElMessage.error(response._data.msg);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onResponseError({ response }) {
|
||||||
|
process.client &&
|
||||||
|
ElMessage.error(
|
||||||
|
isArray(response._data.data.msg)
|
||||||
|
? response._data.data.msg[0]
|
||||||
|
: response._data.data.msg
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return useFetch<T>(url, { ...defaultOptions, ...opts } as any);
|
||||||
|
};
|
||||||
26
layout/default.vue
Normal file
26
layout/default.vue
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<template>
|
||||||
|
<div class="layout-wrap">
|
||||||
|
<div class="flex flex-1 flex-col">
|
||||||
|
<slot></slot>
|
||||||
|
<!-- 右侧固定按钮组 -->
|
||||||
|
<KlQuickMenu></KlQuickMenu>
|
||||||
|
</div>
|
||||||
|
<KlFooter></KlFooter>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import KlFooter from './kl-footer/index.vue'
|
||||||
|
import KlQuickMenu from '@/components/kl-quick-menu/index.vue'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.layout-wrap {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background-color: #fbfcff;
|
||||||
|
width: 100%;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
139
layout/kl-footer/index.vue
Normal file
139
layout/kl-footer/index.vue
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mt-30px bg-[#14213d] px-[40px] pb-[20px] pt-[50px] text-white lg:px-[80px] sm:px-[60px]">
|
||||||
|
<!-- 主内容区 -->
|
||||||
|
<div class="mb-[40px] flex flex-col items-start justify-between gap-[30px] lg:flex-row">
|
||||||
|
<!-- 左侧 Logo -->
|
||||||
|
<div class="mx-auto w-[200px] shrink-0 lg:mx0">
|
||||||
|
<img src="@/assets/images/logo5.png" class="h-auto w-full" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 中间部分 -->
|
||||||
|
<div class="grid grid-cols-2 mx-[80px] flex-1 gap-[10px] lg:grid-cols-3">
|
||||||
|
<div v-for="(col, index) in bannerList?.slice(0, 3)" :key="index">
|
||||||
|
<h3 v-if="handle(col)" class="ma-0px mb-[20px] pa-0px text-[16px]">{{ handle(col) }}</h3>
|
||||||
|
<ul>
|
||||||
|
<li
|
||||||
|
v-for="(item, i) in handle2(col)"
|
||||||
|
:key="i"
|
||||||
|
class="mb-[15px] cursor-pointer text-[15px] text-white/90"
|
||||||
|
:class="{ 'cursor-pointer hover:text-blue-400!': item.url }"
|
||||||
|
@click="handleClick(item)"
|
||||||
|
>
|
||||||
|
{{ item.name }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 右侧二维码 -->
|
||||||
|
<div class="flex shrink-0 flex-row gap-[30px]">
|
||||||
|
<div
|
||||||
|
v-for="(qr, i) in bannerList?.[3]"
|
||||||
|
:key="i"
|
||||||
|
class="text-center"
|
||||||
|
:class="{ 'cursor-pointer hover:text-blue-400!': qr.url }"
|
||||||
|
@click="handleClick(qr)"
|
||||||
|
>
|
||||||
|
<el-image :src="qr.content" class="mx-auto mb-[10px] w-[120px] rounded-lg bg-gray-400/20" />
|
||||||
|
<p class="text-[15px] text-white/90" :class="{ 'cursor-pointer hover:text-blue-400!': qr.url }">{{ qr.name }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 底部版权 -->
|
||||||
|
<div class="border-t border-white/20 pt-[20px] text-center text-[14px] text-white/70">
|
||||||
|
Copyright 2007-2025 图夕夕网络科技(成都)有限公司
|
||||||
|
<a href="http://beian.miit.gov.cn/" target="_blank" class="text-white/90 hover:text-blue-400!"> 蜀ICP备2025141494号-1</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-image-viewer v-if="showViewer" :url-list="previewImgList" :url-index="0" @close="showViewer = false"></el-image-viewer>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { reactive, ref } from 'vue'
|
||||||
|
|
||||||
|
import { getSettingPage } from '@/api/home/index'
|
||||||
|
import { PageResultIndexSettingRespVO } from '@/api/home/type'
|
||||||
|
|
||||||
|
// 导航数据
|
||||||
|
// const columns = [
|
||||||
|
// {
|
||||||
|
// title: '联系与合作',
|
||||||
|
// items: ['关于我们', '联系我们', '免责声明', '常见问题'],
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// title: '关注我们',
|
||||||
|
// items: ['微信订阅号:多多机械', '微信服务号:多多网', '技术交流群:点此加入', '创收平台:为设计师创造收益'],
|
||||||
|
// },
|
||||||
|
// ]
|
||||||
|
|
||||||
|
// 二维码数据(需要替换真实图片路径)
|
||||||
|
// const qrcodes = [
|
||||||
|
// {
|
||||||
|
// img: new URL('@/assets/images/logo2.png', import.meta.url).href,
|
||||||
|
// text: '抖音电商关注官方号',
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// img: new URL('@/assets/images/logo2.png', import.meta.url).href,
|
||||||
|
// text: '微信扫码关注官方助手',
|
||||||
|
// },
|
||||||
|
// ]
|
||||||
|
|
||||||
|
const pageReq = reactive({
|
||||||
|
type: 3,
|
||||||
|
status: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
const bannerList = ref<Array<PageResultIndexSettingRespVO[]>>([])
|
||||||
|
const getBanner = async () => {
|
||||||
|
const res = await getSettingPage(pageReq)
|
||||||
|
if (res.code === 0) {
|
||||||
|
const arr = res.data || []
|
||||||
|
const bannerListOne = arr.filter((item) => item.rowType === 1)?.sort((a, b) => a.sort - b.sort)
|
||||||
|
const bannerListTwo = arr.filter((item) => item.rowType === 2)?.sort((a, b) => a.sort - b.sort)
|
||||||
|
const bannerListThree = arr.filter((item) => item.rowType === 3)?.sort((a, b) => a.sort - b.sort)
|
||||||
|
const bannerListFour = arr.filter((item) => item.rowType === 4)?.sort((a, b) => a.sort - b.sort)
|
||||||
|
bannerList.value = [bannerListOne, bannerListTwo, bannerListThree, bannerListFour]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getBanner()
|
||||||
|
|
||||||
|
const handle = (col: PageResultIndexSettingRespVO[]) => {
|
||||||
|
if (col?.length > 0) {
|
||||||
|
return col[0].name
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const handle2 = (col: PageResultIndexSettingRespVO[]) => {
|
||||||
|
if (col?.length > 0) {
|
||||||
|
return col.slice(1)
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param item.innerType 区分 底部信息展示 0 文本 1 图片地址 2 站内链接地址 3 外部链接地址 4 富文本
|
||||||
|
*/
|
||||||
|
const showViewer = ref(false)
|
||||||
|
const previewImgList = ref<string[]>([])
|
||||||
|
const handleClick = (item: PageResultIndexSettingRespVO) => {
|
||||||
|
if (item.content && (item.innerType === 3 || item.innerType === 2)) {
|
||||||
|
window.open(item.content, '_blank')
|
||||||
|
} else if (item.content && (item.innerType === 4 || item.innerType === 0)) {
|
||||||
|
window.open(`/editor-view?content=${encodeURIComponent(item.content)}`, '_blank')
|
||||||
|
} else if (item.innerType === 1 && item.content) {
|
||||||
|
showViewer.value = true
|
||||||
|
previewImgList.value = [item.content]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
ul {
|
||||||
|
li {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
105
layout/kl-menus-v2/index.vue
Normal file
105
layout/kl-menus-v2/index.vue
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
<template>
|
||||||
|
<div class="box-border">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<div class="box-border h-100% h-55px w-221px flex items-center rounded-lg bg-[#1A65FF] pl-24px text-white">
|
||||||
|
<img src="@/assets/images/1.png" alt="" srcset="" />
|
||||||
|
<span class="ml-12px text-16px">全部资源分类</span>
|
||||||
|
</div>
|
||||||
|
<div class="item-center ml-45px w-660px flex justify-between">
|
||||||
|
<router-link
|
||||||
|
v-for="(item, index) in menuItems"
|
||||||
|
:key="index"
|
||||||
|
target="_blank"
|
||||||
|
:to="item.path"
|
||||||
|
class="parent-links relative rounded-lg px3 py2 text-[#1A65FF]"
|
||||||
|
>
|
||||||
|
{{ item.name }}
|
||||||
|
<img v-if="item.path === '/communication/channel'" src="@/assets/images/hot.png" alt="火" class="absolute right--15px top--2px" />
|
||||||
|
</router-link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="isLogin" class="flex flex-1 items-center justify-end">
|
||||||
|
<div class="h-36px w-36px cursor-pointer border-rd-[50%] bg-[#F5F5F5] text-center line-height-44px" @click="handleUserCenter">
|
||||||
|
<img src="@/assets/images/user.png" alt="" srcset="" class="h-19px w-17px" />
|
||||||
|
</div>
|
||||||
|
<div class="ml-8px h-36px w-36px cursor-pointer border-rd-[50%] text-center line-height-44px" @click="handleMessageCenter">
|
||||||
|
<el-icon size="20px" color="#999999"><BellFilled /></el-icon>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import useUserStore from '@/store/user'
|
||||||
|
const userStore = useUserStore()
|
||||||
|
import { BellFilled } from '@element-plus/icons-vue'
|
||||||
|
import { ref, computed } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
const router = useRouter()
|
||||||
|
const menuItems = ref([
|
||||||
|
{ name: '首页', path: '/index' },
|
||||||
|
{ name: '图纸', path: '/drawe' },
|
||||||
|
{ name: '文本', path: '/text' },
|
||||||
|
{ name: '模型', path: '/model' },
|
||||||
|
{ name: '国外专区', path: '/foreign' },
|
||||||
|
{ name: '工具箱', path: '/toolbox' },
|
||||||
|
{ name: '交流频道', path: '/communication/channel' },
|
||||||
|
// { name: '牛人社区', path: '/community' },
|
||||||
|
])
|
||||||
|
|
||||||
|
// 是否登录
|
||||||
|
const isLogin = computed(() => {
|
||||||
|
return !!userStore.token
|
||||||
|
})
|
||||||
|
|
||||||
|
// 用户中心
|
||||||
|
const handleUserCenter = () => {
|
||||||
|
router.push('/personal/center/info')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 消息中心
|
||||||
|
const handleMessageCenter = () => {
|
||||||
|
router.push('/personal/center/message')
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style scoped>
|
||||||
|
.fade-enter-active,
|
||||||
|
.fade-leave-active {
|
||||||
|
transition: opacity 0.3s ease;
|
||||||
|
}
|
||||||
|
.fade-enter-from,
|
||||||
|
.fade-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
/* 覆盖默认的input number样式 */
|
||||||
|
input[type='number']::-webkit-inner-spin-button,
|
||||||
|
input[type='number']::-webkit-outer-spin-button {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
/* 自定义滚动条样式 */
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
}
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: #f1f1f1;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: #c1c1c1;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: #a8a8a8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.parent-links {
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 16px;
|
||||||
|
color: #1a65ff;
|
||||||
|
&:hover {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
66
layout/kl-menus/index.vue
Normal file
66
layout/kl-menus/index.vue
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<template>
|
||||||
|
<div class="kl-menu">
|
||||||
|
<el-scrollbar height="100%">
|
||||||
|
<el-menu class="el-menu-vertical" :default-active="activeRouteComputed" router>
|
||||||
|
<KlMenuItem
|
||||||
|
v-for="menu in childRoutes"
|
||||||
|
:key="menu?.component?.toString()"
|
||||||
|
:title="menu?.meta?.title + ''"
|
||||||
|
:children="menu.children"
|
||||||
|
:index="menu.path"
|
||||||
|
/>
|
||||||
|
</el-menu>
|
||||||
|
</el-scrollbar>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import KlMenuItem from './kl-menu-item.vue'
|
||||||
|
import { RouteRecordRaw, useRoute } from 'vue-router'
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
const modulesFiles = import.meta.globEager('@/router/modules/*.ts')
|
||||||
|
const childRoutes: RouteRecordRaw[] = []
|
||||||
|
Object.keys(modulesFiles).forEach((path: string) => {
|
||||||
|
const module = modulesFiles[path] as any
|
||||||
|
if (module?.default) {
|
||||||
|
childRoutes.push(...module.default)
|
||||||
|
}
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const activeRouteComputed = computed(() => {
|
||||||
|
return route.path
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.kl-menu {
|
||||||
|
height: 100%;
|
||||||
|
::v-deep(.el-scrollbar) {
|
||||||
|
.el-scrollbar__bar.is-vertical {
|
||||||
|
display: block !important;
|
||||||
|
.el-scrollbar__thumb {
|
||||||
|
width: 0px;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.el-menu-vertical {
|
||||||
|
border: none;
|
||||||
|
.el-sub-menu__title,
|
||||||
|
.el-menu-item {
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
.el-menu-item.is-active {
|
||||||
|
background-color: #ebf1ff;
|
||||||
|
border-right: 4px solid $color-primary;
|
||||||
|
}
|
||||||
|
.el-sub-menu {
|
||||||
|
.el-menu-item {
|
||||||
|
text-indent: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
58
layout/kl-menus/kl-menu-item.vue
Normal file
58
layout/kl-menus/kl-menu-item.vue
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<template>
|
||||||
|
<el-menu-item v-if="!props.children?.length" :index="props.index">
|
||||||
|
<template #title>
|
||||||
|
<span>{{ props.title }}</span>
|
||||||
|
</template>
|
||||||
|
</el-menu-item>
|
||||||
|
<el-sub-menu v-else-if="props.children.length" :index="props.index + props.title">
|
||||||
|
<template #title>
|
||||||
|
<span>{{ props.title }}</span>
|
||||||
|
</template>
|
||||||
|
<KlMenuItem v-for="menu in props.children" :key="menu.path" :title="menu.meta?.title || ''" :children="menu.children" :index="menu.path"></KlMenuItem>
|
||||||
|
</el-sub-menu>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { PropType } from 'vue'
|
||||||
|
import { RouteRecordRaw } from 'vue-router'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
title: {
|
||||||
|
type: String as PropType<string>,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
children: {
|
||||||
|
type: Array as PropType<RouteRecordRaw[]>,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
index: {
|
||||||
|
type: String as PropType<string>,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
::v-deep(.el-sub-menu) {
|
||||||
|
.el-menu-item {
|
||||||
|
display: flex;
|
||||||
|
span {
|
||||||
|
text-indent: 6px;
|
||||||
|
flex: 1;
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
display: inline-block;
|
||||||
|
width: 4px;
|
||||||
|
height: 4px;
|
||||||
|
background-color: #bcbfc5;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin-left: -4px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
153
layout/kl-search/index.vue
Normal file
153
layout/kl-search/index.vue
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<header class="h-106px">
|
||||||
|
<div class="mx-a ml--250px h-full flex items-center justify-center">
|
||||||
|
<!-- Logo区域 -->
|
||||||
|
<div class="h-100% flex cursor-pointer items-center" @click="router.push('/index')">
|
||||||
|
<img src="@/assets/images/logo5.png" alt="图夕夕" class="h-51px w-182px" />
|
||||||
|
</div>
|
||||||
|
<!-- 搜索区域 -->
|
||||||
|
<div class="relative ml-49px w-647px px4 p-r-0px!">
|
||||||
|
<div class="search-input relative w-100%">
|
||||||
|
<el-input
|
||||||
|
v-model="searchQuery"
|
||||||
|
type="text"
|
||||||
|
placeholder="搜一搜"
|
||||||
|
:prefix-icon="Search"
|
||||||
|
class="no-right-border box-border h40 w-100% rounded-bl-4px rounded-br-0px rounded-tl-4px rounded-tr-0px bg-[#F8F8F8] text-14px outline-#999"
|
||||||
|
@focus="handleHot(), (showHotList = true)"
|
||||||
|
@input="handleInput"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<!-- 搜索框 获取到焦点 显示热门列表 -->
|
||||||
|
<div
|
||||||
|
v-if="showHotList"
|
||||||
|
v-loading="loading"
|
||||||
|
class="absolute z-100 w-625px border-width-1px border-color-#1A65FF rounded-bl-4px rounded-br-4px rounded-tl-0px rounded-tr-0px border-solid bg-[#fff] pa-10px"
|
||||||
|
>
|
||||||
|
<!-- 这里放置热门列表的内容 -->
|
||||||
|
<ul class="flex flex-col gap-6px">
|
||||||
|
<li
|
||||||
|
v-for="(item, index) in hotItems"
|
||||||
|
:key="index"
|
||||||
|
class="flex flex-row cursor-pointer items-center justify-between text-13px"
|
||||||
|
@click="handleHotItem(item)"
|
||||||
|
>
|
||||||
|
<span class="color-#333333">{{ item.projectTypeName }}</span>
|
||||||
|
<span v-if="item.count" class="color-#999999">{{ item.count }}份图纸</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div v-if="!hotItems.length" class="text-12px color-#999">无数据</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- 按钮区域 -->
|
||||||
|
<div class="flex items-center">
|
||||||
|
<button
|
||||||
|
class="h-40px w-111px cursor-pointer border-width-1px border-color-#1A65FF rounded-bl-0px rounded-br-4px rounded-tl-0px rounded-tr-4px border-none border-solid text-center text-14px color-#fff bg-#1A65FF!"
|
||||||
|
>
|
||||||
|
搜索
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="m-l-16px h-40px w-111px cursor-pointer border-width-1px border-color-#E7B03B rounded-bl-6px rounded-br-6px rounded-tl-4px rounded-tr-6px border-none border-solid text-14px color-#fff bg-#E7B03B!"
|
||||||
|
@click="handleUpload"
|
||||||
|
>
|
||||||
|
上传图纸
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
import { Search } from '@element-plus/icons-vue'
|
||||||
|
import useUserStore from '@/store/user'
|
||||||
|
import router from '@/router'
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
|
import { top } from '@/api/home/index'
|
||||||
|
import type { ProjectDrawStatisticAppRespVO } from '@/api/home/type'
|
||||||
|
import { page } from '@/api/upnew/index'
|
||||||
|
|
||||||
|
const searchQuery = ref('')
|
||||||
|
const showHotList = ref(false)
|
||||||
|
const hotItems = ref<ProjectDrawStatisticAppRespVO[]>([])
|
||||||
|
|
||||||
|
const handleUpload = () => {
|
||||||
|
// 是否登录
|
||||||
|
if (!userStore.token) return ElMessage.error('请先登录')
|
||||||
|
// 新开窗口 用router跳转 新窗口打开
|
||||||
|
window.open('/upnew/drawe', '_blank')
|
||||||
|
}
|
||||||
|
|
||||||
|
const loading = ref(false)
|
||||||
|
const handleHot = async () => {
|
||||||
|
loading.value = true
|
||||||
|
const res = await top({
|
||||||
|
limit: 10,
|
||||||
|
type: 1, // 1 图纸 2 模型 3 文本
|
||||||
|
})
|
||||||
|
hotItems.value = res.data
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
handleHot()
|
||||||
|
|
||||||
|
const timer = ref(0)
|
||||||
|
const handleInput = (val: string) => {
|
||||||
|
searchQuery.value = val
|
||||||
|
loading.value = true
|
||||||
|
if (timer.value) {
|
||||||
|
window.clearTimeout(timer.value)
|
||||||
|
}
|
||||||
|
timer.value = window.setTimeout(async () => {
|
||||||
|
console.log('searchQuery', searchQuery.value)
|
||||||
|
const res = await page({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
type: 1, // 1 图纸 2 模型 3 文本
|
||||||
|
title: searchQuery.value, // 1 图纸 2 模型 3 文本
|
||||||
|
})
|
||||||
|
if (res.code === 0) {
|
||||||
|
hotItems.value = res.data.list.map((c) => {
|
||||||
|
return { ...c, projectTypeName: c.title }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
loading.value = false
|
||||||
|
}, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleHotItem = (item: ProjectDrawStatisticAppRespVO) => {
|
||||||
|
const normal = { id: '0', name: '图纸库', isChildren: false }
|
||||||
|
const level = item.pairs?.filter(Boolean).map((item) => ({ id: item?.id, name: item?.name, isChildren: false })) || []
|
||||||
|
level.unshift(normal)
|
||||||
|
if (item.type === 1) {
|
||||||
|
window.open(`/drawe?level=${JSON.stringify(level)}&keywords=${item.title || ''}`, '_blank')
|
||||||
|
} else if (item.type === 2) {
|
||||||
|
window.open(`/text?level=${JSON.stringify(level)}&keywords=${item.title || ''}`, '_blank')
|
||||||
|
} else if (item.type === 3) {
|
||||||
|
window.open(`/model?level=${JSON.stringify(level)}&keywords=${item.title || ''}`, '_blank')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
// 监听点击事件
|
||||||
|
document.addEventListener('click', (event) => {
|
||||||
|
const target = event.target as HTMLElement
|
||||||
|
if (!target.closest('.search-input')) {
|
||||||
|
showHotList.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<style scoped>
|
||||||
|
.no-right-border :deep(.el-input__wrapper) {
|
||||||
|
border-right: none !important;
|
||||||
|
/* box-shadow: -1px 0 0 0 var(--el-input-border-color, var(--el-border-color)) inset !important; */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 如果需要调整右侧圆角,可以添加 */
|
||||||
|
.no-right-border :deep(.el-input__wrapper) {
|
||||||
|
border-top-right-radius: 0 !important;
|
||||||
|
border-bottom-right-radius: 0 !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
127
nuxt.config.ts
127
nuxt.config.ts
@ -1,18 +1,17 @@
|
|||||||
|
// import { base_api } from '~/constants/index'
|
||||||
// https://nuxt.com/docs/api/configuration/nuxt-config
|
// https://nuxt.com/docs/api/configuration/nuxt-config
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
devServer: {
|
devServer: {
|
||||||
port: 8888,
|
port: 6188,
|
||||||
host: '0.0.0.0'
|
|
||||||
},
|
},
|
||||||
|
|
||||||
devtools: {
|
devtools: {
|
||||||
enabled: process.env.NODE_ENV === 'development'
|
enabled: process.env.NODE_ENV === "development",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
ssr: true,
|
ssr: true,
|
||||||
modules: ['@unocss/nuxt', '@pinia/nuxt','@element-plus/nuxt'],
|
modules: ["@unocss/nuxt", "@pinia/nuxt", "@element-plus/nuxt"],
|
||||||
css: ['@unocss/reset/tailwind.css', 'element-plus/dist/index.css'],
|
css: ["@unocss/reset/tailwind.css", "element-plus/dist/index.css"],
|
||||||
vite: {
|
vite: {
|
||||||
css: {
|
css: {
|
||||||
preprocessorOptions: {
|
preprocessorOptions: {
|
||||||
@ -32,111 +31,89 @@ export default defineNuxtConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
include: ['naive-ui']
|
include: ["naive-ui"],
|
||||||
},
|
},
|
||||||
// 生产环境构建优化
|
// 生产环境构建优化
|
||||||
build: {
|
build: {
|
||||||
// 生产环境移除 console 和 debugger
|
// 生产环境移除 console 和 debugger
|
||||||
minify: 'esbuild',
|
minify: "esbuild",
|
||||||
target: 'es2020'
|
target: "es2020",
|
||||||
},
|
},
|
||||||
esbuild: {
|
esbuild: {
|
||||||
// 生产环境下移除所有 console 语句和 debugger
|
// 生产环境下移除所有 console 语句和 debugger
|
||||||
drop: process.env.NODE_ENV === 'production' ? ['console', 'debugger'] : []
|
drop:
|
||||||
}
|
process.env.NODE_ENV === "production" ? ["console", "debugger"] : [],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// 页面过渡配置
|
// 页面过渡配置
|
||||||
app: {
|
app: {
|
||||||
pageTransition: {
|
pageTransition: {
|
||||||
name: 'page',
|
name: "page",
|
||||||
mode: 'out-in',
|
mode: "out-in",
|
||||||
duration: 400
|
duration: 400,
|
||||||
},
|
},
|
||||||
layoutTransition: {
|
layoutTransition: {
|
||||||
name: 'layout',
|
name: "layout",
|
||||||
mode: 'out-in',
|
mode: "out-in",
|
||||||
duration: 400
|
duration: 400,
|
||||||
},
|
},
|
||||||
head: {
|
head: {
|
||||||
title: 'xlCig - 专业PC硬件产品和装机服务',
|
title: "xlCig - 专业PC硬件产品和装机服务",
|
||||||
htmlAttrs: {
|
htmlAttrs: {
|
||||||
lang: 'en',
|
lang: "en",
|
||||||
},
|
},
|
||||||
meta: [
|
meta: [
|
||||||
{ charset: 'utf-8' },
|
{ charset: "utf-8" },
|
||||||
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
{ name: "viewport", content: "width=device-width, initial-scale=1" },
|
||||||
{ name: 'description', content: '专业的PC硬件产品和装机建议,助您打造梦想中的高性能电脑' },
|
{
|
||||||
{ name: 'keywords', content: 'xlCig,PC硬件,电脑配置,显卡,CPU,装机' },
|
name: "description",
|
||||||
{ name: 'author', content: 'xlCig' },
|
content: "专业的PC硬件产品和装机建议,助您打造梦想中的高性能电脑",
|
||||||
|
},
|
||||||
|
{ name: "keywords", content: "xlCig,PC硬件,电脑配置,显卡,CPU,装机" },
|
||||||
|
{ name: "author", content: "xlCig" },
|
||||||
// 百度站点验证
|
// 百度站点验证
|
||||||
{ name: 'baidu-site-verification', content: 'codeva-2z90c1PlRw' },
|
{ name: "baidu-site-verification", content: "codeva-2z90c1PlRw" },
|
||||||
// SEO meta tags
|
// SEO meta tags
|
||||||
{ property: 'og:title', content: 'xlCig - 专业PC硬件产品和装机服务' },
|
{ property: "og:title", content: "xlCig - 专业PC硬件产品和装机服务" },
|
||||||
{ property: 'og:description', content: '专业的PC硬件产品和装机建议,助您打造梦想中的高性能电脑' },
|
{
|
||||||
{ property: 'og:type', content: 'website' },
|
property: "og:description",
|
||||||
{ property: 'og:url', content: 'https://www.xlcig.cn' },
|
content: "专业的PC硬件产品和装机建议,助您打造梦想中的高性能电脑",
|
||||||
{ property: 'og:site_name', content: 'xlCig' },
|
},
|
||||||
{ name: 'theme-color', content: '#00f5ff' },
|
{ property: "og:type", content: "website" },
|
||||||
|
{ property: "og:url", content: "https://www.xlcig.cn" },
|
||||||
|
{ property: "og:site_name", content: "xlCig" },
|
||||||
|
{ name: "theme-color", content: "#00f5ff" },
|
||||||
// robots meta
|
// robots meta
|
||||||
{ name: 'robots', content: 'index, follow' }
|
{ name: "robots", content: "index, follow" },
|
||||||
],
|
],
|
||||||
link: [
|
link: [
|
||||||
{ rel: 'icon', type: 'image/png', href: '/logo.png' },
|
{ rel: "icon", type: "image/png", href: "/logo.png" },
|
||||||
{ rel: 'apple-touch-icon', sizes: '180x180', href: '/logo.png' },
|
{ rel: "apple-touch-icon", sizes: "180x180", href: "/logo.png" },
|
||||||
{ rel: 'icon', type: 'image/png', sizes: '32x32', href: '/logo.png' },
|
{ rel: "icon", type: "image/png", sizes: "32x32", href: "/logo.png" },
|
||||||
{ rel: 'icon', type: 'image/png', sizes: '16x16', href: '/logo.png' }
|
{ rel: "icon", type: "image/png", sizes: "16x16", href: "/logo.png" },
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
public: {
|
public: {
|
||||||
// API 基础地址
|
// API 基础地址
|
||||||
apiBase: process.env.NUXT_PUBLIC_API_BASE || (
|
apiBase: 'https://tuxixi.net',
|
||||||
process.env.NODE_ENV === 'production'
|
|
||||||
? 'https://api.xlcig.cn' // 生产环境
|
|
||||||
: 'http://192.168.11.194:9999' // 开发环境
|
|
||||||
),
|
|
||||||
|
|
||||||
// WebSocket 地址
|
|
||||||
wsUrl: process.env.NUXT_PUBLIC_WS_URL || (
|
|
||||||
process.env.NODE_ENV === 'production'
|
|
||||||
? 'wss://api.xlcig.cn/websocket' // 生产环境使用wss
|
|
||||||
: 'ws://192.168.11.194:9999/websocket' // 开发环境使用ws
|
|
||||||
),
|
|
||||||
|
|
||||||
// 应用信息
|
// 应用信息
|
||||||
appName: process.env.NUXT_PUBLIC_APP_NAME || 'xlCig',
|
appName: "xlCig",
|
||||||
appVersion: process.env.NUXT_PUBLIC_APP_VERSION || '1.0.0',
|
appVersion: "1.0.0",
|
||||||
|
|
||||||
// 调试模式
|
// 调试模式
|
||||||
debug: process.env.NUXT_PUBLIC_DEBUG === 'true' || process.env.NODE_ENV === 'development',
|
debug: process.env.NODE_ENV === "development",
|
||||||
|
|
||||||
// 环境标识
|
// 环境标识
|
||||||
environment: process.env.NODE_ENV || 'development'
|
environment: process.env.NODE_ENV || "development",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
build: {
|
build: {
|
||||||
transpile: ['naive-ui', 'vueuc', '@css-render/vue3-ssr']
|
transpile: ["vueuc", "@css-render/vue3-ssr"],
|
||||||
},
|
},
|
||||||
|
});
|
||||||
// 优化SSR性能和开发代理
|
|
||||||
nitro: {
|
|
||||||
compressPublicAssets: true,
|
|
||||||
// 开发环境代理配置
|
|
||||||
devProxy: {
|
|
||||||
'/api': {
|
|
||||||
target: 'http://192.168.11.194:9999/api',
|
|
||||||
changeOrigin: true,
|
|
||||||
prependPath: true,
|
|
||||||
},
|
|
||||||
'/websocket': {
|
|
||||||
target: 'ws://192.168.11.194:9999',
|
|
||||||
ws: true,
|
|
||||||
changeOrigin: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|||||||
@ -21,8 +21,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import KlSearch from '@/layout/kl-search/index.vue'
|
import KlSearch from '~/layout/kl-search/index.vue'
|
||||||
import KlMenuV2 from '@/layout/kl-menus-v2/index.vue'
|
import KlMenuV2 from '~/layout/kl-menus-v2/index.vue'
|
||||||
import SideMenu from './components/SideMenu.vue'
|
import SideMenu from './components/SideMenu.vue'
|
||||||
import MainContent from './components/MainContent.vue'
|
import MainContent from './components/MainContent.vue'
|
||||||
import RecommendedColumns from './components/RecommendedColumns.vue'
|
import RecommendedColumns from './components/RecommendedColumns.vue'
|
||||||
|
|||||||
16
plugins/global.ts
Normal file
16
plugins/global.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { openLogin } from "~/components/kl-login";
|
||||||
|
import { closeLogin } from "~/components/kl-login";
|
||||||
|
import { openRegister } from "~/components/kl-register";
|
||||||
|
import { closeRegister } from "~/components/kl-register";
|
||||||
|
import { openLoginEmail } from "~/components/kl-email";
|
||||||
|
import { closeLoginEmail } from "~/components/kl-email";
|
||||||
|
|
||||||
|
// plugins/global.ts
|
||||||
|
export default defineNuxtPlugin((nuxtApp) => {
|
||||||
|
nuxtApp.vueApp.config.globalProperties.$openLogin = openLogin;
|
||||||
|
nuxtApp.vueApp.config.globalProperties.$closeLogin = closeLogin;
|
||||||
|
nuxtApp.vueApp.config.globalProperties.$openRegister = openRegister;
|
||||||
|
nuxtApp.vueApp.config.globalProperties.$closeRegister = closeRegister;
|
||||||
|
nuxtApp.vueApp.config.globalProperties.$openLoginEmail = openLoginEmail;
|
||||||
|
nuxtApp.vueApp.config.globalProperties.$closeLoginEmail = closeLoginEmail;
|
||||||
|
});
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
// import { getPermissions } from '@/api/common'
|
// import { getPermissions } from '@/api/common'
|
||||||
import { IPermissions } from '~/api/common/types'
|
import type { IPermissions } from '~/api/common/types'
|
||||||
|
|
||||||
// type TPayload = {
|
// type TPayload = {
|
||||||
// menuId: string
|
// menuId: string
|
||||||
|
|||||||
111
store/user.ts
111
store/user.ts
@ -1,99 +1,112 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from "pinia";
|
||||||
import { refreshToken as REFRESHTOKEN } from '~/utils/axios'
|
import refreshToken from "~/utils/RefreshToken";
|
||||||
import router from '@/router'
|
import { getUserInfo } from "~/api/common/index";
|
||||||
import { getUserInfo } from '~/api/common/index'
|
import type { AppMemberUserInfoRespVO } from "~/api/common/types";
|
||||||
import { AppMemberUserInfoRespVO } from '~/api/common/types'
|
import MQTTClient from "~/utils/mqttClient";
|
||||||
import MQTTClient from '~/utils/mqttClient'
|
import { socialLoginByCode } from "~/api/pay";
|
||||||
import { socialLoginByCode } from '~/api/pay'
|
// const {
|
||||||
import app from '@/main'
|
// $openLogin,
|
||||||
|
// $closeLogin,
|
||||||
|
// $openRegister,
|
||||||
|
// $closeRegister,
|
||||||
|
// $openLoginEmail,
|
||||||
|
// $closeLoginEmail,
|
||||||
|
// } = useNuxtApp();
|
||||||
|
|
||||||
export default defineStore('useUserStore', {
|
export default defineStore("useUserStore", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
token: REFRESHTOKEN.getToken().token || '',
|
token: refreshToken.getToken().token || "",
|
||||||
refreshToken: REFRESHTOKEN.getToken().refreshToken || '',
|
refreshToken: refreshToken.getToken().refreshToken || "",
|
||||||
userId: REFRESHTOKEN.getToken().userId || '',
|
userId: refreshToken.getToken().userId || "",
|
||||||
userName: REFRESHTOKEN.getToken().userName || '',
|
userName: refreshToken.getToken().userName || "",
|
||||||
userInfoRes: (REFRESHTOKEN.getToken().userInfo || {}) as AppMemberUserInfoRespVO,
|
userInfoRes: (refreshToken.getToken().userInfo ||
|
||||||
|
{}) as AppMemberUserInfoRespVO,
|
||||||
mqttClient: null as MQTTClient | null,
|
mqttClient: null as MQTTClient | null,
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
setToken(token: string) {
|
setToken(token: string) {
|
||||||
this.token = token
|
this.token = token;
|
||||||
},
|
},
|
||||||
setRefreshToken(refreshToken: string) {
|
setRefreshToken(refreshToken: string) {
|
||||||
this.refreshToken = refreshToken
|
this.refreshToken = refreshToken;
|
||||||
},
|
},
|
||||||
setUserId(userId: string) {
|
setUserId(userId: string) {
|
||||||
this.userId = userId
|
this.userId = userId;
|
||||||
},
|
},
|
||||||
setUserName(userName: string) {
|
setUserName(userName: string) {
|
||||||
this.userName = userName
|
this.userName = userName;
|
||||||
},
|
},
|
||||||
logout() {
|
logout() {
|
||||||
REFRESHTOKEN.removeToken()
|
refreshToken.removeToken();
|
||||||
if (self === top) {
|
if (self === top) {
|
||||||
router.push('/index')
|
navigateTo("/index");
|
||||||
} else {
|
} else {
|
||||||
window.top?.postMessage({ event: 'logout' }, '*')
|
window.top?.postMessage({ event: "logout" }, "*");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async getUserInfo() {
|
async getUserInfo() {
|
||||||
const res = await getUserInfo()
|
const res = await getUserInfo();
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
this.userInfoRes = res.data
|
this.userInfoRes = res.data;
|
||||||
REFRESHTOKEN.setUserInfo(res.data)
|
refreshToken.setUserInfo(res.data);
|
||||||
// 建立连接mqtt
|
// 建立连接mqtt
|
||||||
this.connectMqtt()
|
this.connectMqtt();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 建立连接mqtt
|
// 建立连接mqtt
|
||||||
async connectMqtt() {
|
async connectMqtt() {
|
||||||
this.mqttClient = new MQTTClient('wss://www.tuxixi.net/mqtt', {
|
this.mqttClient = new MQTTClient("wss://www.tuxixi.net/mqtt", {
|
||||||
clientId: this.userInfoRes.id,
|
clientId: this.userInfoRes.id,
|
||||||
})
|
});
|
||||||
await this.mqttClient.connect()
|
await this.mqttClient.connect();
|
||||||
await this.mqttClient?.subscribe(`zbjk_message_single/${this.userInfoRes.id}`)
|
await this.mqttClient?.subscribe(
|
||||||
await this.mqttClient?.subscribe(`zbjk_message_kefu/${this.userInfoRes.id}`)
|
`zbjk_message_single/${this.userInfoRes.id}`
|
||||||
|
);
|
||||||
|
await this.mqttClient?.subscribe(
|
||||||
|
`zbjk_message_kefu/${this.userInfoRes.id}`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
async getToken(row: any) {
|
async getToken(row: any) {
|
||||||
try {
|
try {
|
||||||
// 验证state
|
// 验证state
|
||||||
if (localStorage.getItem('wechat_login_state') !== row.state && localStorage.getItem('qq_login_state') !== row.state) {
|
if (
|
||||||
ElMessage.error('验证失败,请重新登录')
|
localStorage.getItem("wechat_login_state") !== row.state &&
|
||||||
return
|
localStorage.getItem("qq_login_state") !== row.state
|
||||||
|
) {
|
||||||
|
ElMessage.error("验证失败,请重新登录");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await socialLoginByCode({
|
const res = await socialLoginByCode({
|
||||||
code: row.code,
|
code: row.code,
|
||||||
state: row.state,
|
state: row.state,
|
||||||
type: Number(row.type), // type: 32-微信开放平台 35-腾讯QQ
|
type: Number(row.type), // type: 32-微信开放平台 35-腾讯QQ
|
||||||
})
|
});
|
||||||
|
|
||||||
const { code, data } = res
|
const { code, data } = res;
|
||||||
if (code === 0 && data.openid) {
|
if (code === 0 && data.openid) {
|
||||||
// 打开登录界面
|
// 打开登录界面
|
||||||
if (!data.accessToken) {
|
if (!data.accessToken) {
|
||||||
ElMessage.error('因你未绑定手机号,请先绑定手机号')
|
ElMessage.error("因你未绑定手机号,请先绑定手机号");
|
||||||
if (app) {
|
// @ts-ignore
|
||||||
app.config.globalProperties.$openLogin('verify', row.code, row.type, row.state)
|
// $openLogin("verify", row.code, row.type, row.state);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
REFRESHTOKEN.setToken(data.accessToken, data.refreshToken)
|
refreshToken.setToken(data.accessToken, data.refreshToken);
|
||||||
REFRESHTOKEN.setUserId(data.userId.toString())
|
refreshToken.setUserId(data.userId.toString());
|
||||||
// REFRESHTOKEN.setUserName(loginForm.mobile)
|
// refreshToken.setUserName(loginForm.mobile)
|
||||||
this.setToken(data.accessToken)
|
this.setToken(data.accessToken);
|
||||||
this.setUserId(data.userId.toString())
|
this.setUserId(data.userId.toString());
|
||||||
// userStore.setUserName(loginForm.mobile)
|
// userStore.setUserName(loginForm.mobile)
|
||||||
this.setRefreshToken(data.refreshToken)
|
this.setRefreshToken(data.refreshToken);
|
||||||
// 获取信息
|
// 获取信息
|
||||||
await this.getUserInfo()
|
await this.getUserInfo();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error('获取token失败:', res.msg)
|
console.error("获取token失败:", res.msg);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('getToken error:', error)
|
console.error("getToken error:", error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|||||||
38
types/global.d.ts
vendored
38
types/global.d.ts
vendored
@ -1,38 +1,38 @@
|
|||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
interface IResponse<T = any> {
|
interface IResponse<T = any> {
|
||||||
statusCode: string
|
statusCode: string;
|
||||||
code: number | string
|
code: number | string;
|
||||||
data: T
|
data: T;
|
||||||
message: string
|
message: string;
|
||||||
msg: string
|
msg: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Window {
|
interface Window {
|
||||||
/**
|
/**
|
||||||
* 当前APP运行环境
|
* 当前APP运行环境
|
||||||
* */
|
* */
|
||||||
APP_RUN_ENV: 'local' | 'dev' | 'test' | 'prod' | 'pre'
|
APP_RUN_ENV: "local" | "dev" | "test" | "prod" | "pre";
|
||||||
// 是否存在无界
|
// 是否存在无界
|
||||||
__POWERED_BY_WUJIE__?: boolean
|
__POWERED_BY_WUJIE__?: boolean;
|
||||||
// 子应用公共加载路径
|
// 子应用公共加载路径
|
||||||
__WUJIE_PUBLIC_PATH__: string
|
__WUJIE_PUBLIC_PATH__: string;
|
||||||
// 原生的querySelector
|
// 原生的querySelector
|
||||||
__WUJIE_RAW_DOCUMENT_QUERY_SELECTOR__: typeof Document.prototype.querySelector
|
__WUJIE_RAW_DOCUMENT_QUERY_SELECTOR__: typeof Document.prototype.querySelector;
|
||||||
// 原生的querySelectorAll
|
// 原生的querySelectorAll
|
||||||
__WUJIE_RAW_DOCUMENT_QUERY_SELECTOR_ALL__: typeof Document.prototype.querySelectorAll
|
__WUJIE_RAW_DOCUMENT_QUERY_SELECTOR_ALL__: typeof Document.prototype.querySelectorAll;
|
||||||
// 原生的window对象
|
// 原生的window对象
|
||||||
__WUJIE_RAW_WINDOW__: Window
|
__WUJIE_RAW_WINDOW__: Window;
|
||||||
// 子应用沙盒实例
|
// 子应用沙盒实例
|
||||||
__WUJIE: WuJie
|
__WUJIE: WuJie;
|
||||||
// 子应用mount函数
|
// 子应用mount函数
|
||||||
__WUJIE_MOUNT: () => void
|
__WUJIE_MOUNT: () => void;
|
||||||
// 子应用unmount函数
|
// 子应用unmount函数
|
||||||
__WUJIE_UNMOUNT: () => void
|
__WUJIE_UNMOUNT: () => void;
|
||||||
// 注入对象
|
// 注入对象
|
||||||
$wujie: {
|
$wujie: {
|
||||||
bus: EventBus
|
bus: EventBus;
|
||||||
shadowRoot?: ShadowRoot
|
shadowRoot?: ShadowRoot;
|
||||||
props?: { [key: string]: any }
|
props?: { [key: string]: any };
|
||||||
location?: object
|
location?: object;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,133 +1,75 @@
|
|||||||
import axios, { AxiosRequestConfig, AxiosInstance, AxiosResponse } from 'axios'
|
import type { AppMemberUserInfoRespVO } from "@/api/common/types";
|
||||||
import type { AppMemberUserInfoRespVO } from '@/api/common/types'
|
export type onRefreshTokenResponse = (
|
||||||
export type onRefreshTokenResponse = (data: AxiosResponse | boolean) => { token: string; refreshToken: string } | false
|
data: AxiosResponse | boolean
|
||||||
|
) => { token: string; refreshToken: string } | false;
|
||||||
|
|
||||||
export type TRefreshTokenConstructorConfig = {
|
class RefreshToken {
|
||||||
refreshTokenApiUrl: string
|
static instance: RefreshToken;
|
||||||
refreshTokenKey?: string
|
static SOTRAGE_REFRESH_TOKEN_KEY = "kl-tk";
|
||||||
tokenKey?: string
|
static SOTRAGE_TOKENKEY = "kl-rfk";
|
||||||
axiosInstance: AxiosInstance
|
static SOTRAGE_USERID = "kl-userId";
|
||||||
onRefreshTokenResponse: onRefreshTokenResponse
|
static SOTRAGE_USERNAME = "kl-userName";
|
||||||
onRefreshTokenResquest?: () => {
|
static SOTRAGE_USERINFO = "kl-userInfo";
|
||||||
config?: AxiosRequestConfig
|
public pending = false;
|
||||||
data?: any
|
public callbacks: any[] = [];
|
||||||
}
|
|
||||||
}
|
|
||||||
export default class RefreshToken {
|
|
||||||
static instance: RefreshToken
|
|
||||||
static SOTRAGE_REFRESH_TOKEN_KEY = 'kl-tk'
|
|
||||||
static SOTRAGE_TOKENKEY = 'kl-rfk'
|
|
||||||
static SOTRAGE_USERID = 'kl-userId'
|
|
||||||
static SOTRAGE_USERNAME = 'kl-userName'
|
|
||||||
static SOTRAGE_USERINFO = 'kl-userInfo'
|
|
||||||
private REFRESH_TOKEN_API_URL: string
|
|
||||||
public pending = false
|
|
||||||
private axios: AxiosInstance
|
|
||||||
public callbacks: any[] = []
|
|
||||||
private onRefreshTokenResponse: onRefreshTokenResponse
|
|
||||||
private onRefreshTokenResquest?: () => {
|
|
||||||
config?: AxiosRequestConfig
|
|
||||||
data?: any
|
|
||||||
}
|
|
||||||
|
|
||||||
protected constructor(config: TRefreshTokenConstructorConfig) {
|
protected constructor(config: TRefreshTokenConstructorConfig) {
|
||||||
RefreshToken.SOTRAGE_REFRESH_TOKEN_KEY = config?.refreshTokenKey || 'kl-tk'
|
RefreshToken.SOTRAGE_REFRESH_TOKEN_KEY = config?.refreshTokenKey || "kl-tk";
|
||||||
RefreshToken.SOTRAGE_TOKENKEY = config?.refreshTokenKey || 'kl-rfk'
|
RefreshToken.SOTRAGE_TOKENKEY = config?.refreshTokenKey || "kl-rfk";
|
||||||
RefreshToken.SOTRAGE_USERID = config?.refreshTokenKey || 'kl-userId'
|
RefreshToken.SOTRAGE_USERID = config?.refreshTokenKey || "kl-userId";
|
||||||
this.REFRESH_TOKEN_API_URL = config?.refreshTokenApiUrl || ''
|
|
||||||
this.axios = config.axiosInstance
|
|
||||||
this.onRefreshTokenResponse = config.onRefreshTokenResponse
|
|
||||||
this.onRefreshTokenResquest = config.onRefreshTokenResquest
|
|
||||||
}
|
|
||||||
|
|
||||||
static create(config: TRefreshTokenConstructorConfig) {
|
|
||||||
if (!RefreshToken.instance) {
|
|
||||||
RefreshToken.instance = new RefreshToken(config)
|
|
||||||
}
|
|
||||||
return RefreshToken.instance
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置token
|
// 设置token
|
||||||
setToken(token: string, refreshToken: string) {
|
static setToken(token: string, refreshToken: string) {
|
||||||
window.localStorage.setItem(RefreshToken.SOTRAGE_TOKENKEY, token)
|
window.localStorage.setItem(RefreshToken.SOTRAGE_TOKENKEY, token);
|
||||||
window.localStorage.setItem(RefreshToken.SOTRAGE_REFRESH_TOKEN_KEY, refreshToken)
|
window.localStorage.setItem(
|
||||||
|
RefreshToken.SOTRAGE_REFRESH_TOKEN_KEY,
|
||||||
|
refreshToken
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清除token
|
// 清除token
|
||||||
removeToken() {
|
static removeToken() {
|
||||||
window.localStorage.removeItem(RefreshToken.SOTRAGE_TOKENKEY)
|
window.localStorage.removeItem(RefreshToken.SOTRAGE_TOKENKEY);
|
||||||
window.localStorage.removeItem(RefreshToken.SOTRAGE_REFRESH_TOKEN_KEY)
|
window.localStorage.removeItem(RefreshToken.SOTRAGE_REFRESH_TOKEN_KEY);
|
||||||
//清除token,一起把userID也清除了
|
//清除token,一起把userID也清除了
|
||||||
window.localStorage.removeItem(RefreshToken.SOTRAGE_USERID)
|
window.localStorage.removeItem(RefreshToken.SOTRAGE_USERID);
|
||||||
window.localStorage.removeItem(RefreshToken.SOTRAGE_USERNAME)
|
window.localStorage.removeItem(RefreshToken.SOTRAGE_USERNAME);
|
||||||
window.localStorage.removeItem(RefreshToken.SOTRAGE_USERINFO)
|
window.localStorage.removeItem(RefreshToken.SOTRAGE_USERINFO);
|
||||||
}
|
}
|
||||||
//设置userID
|
//设置userID
|
||||||
setUserId(userId: string) {
|
static setUserId(userId: string) {
|
||||||
window.localStorage.setItem(RefreshToken.SOTRAGE_USERID, userId)
|
window.localStorage.setItem(RefreshToken.SOTRAGE_USERID, userId);
|
||||||
}
|
}
|
||||||
setUserName(userName: string) {
|
static setUserName(userName: string) {
|
||||||
window.localStorage.setItem(RefreshToken.SOTRAGE_USERNAME, userName)
|
window.localStorage.setItem(RefreshToken.SOTRAGE_USERNAME, userName);
|
||||||
}
|
}
|
||||||
setUserInfo(userInfo: AppMemberUserInfoRespVO) {
|
static setUserInfo(userInfo: AppMemberUserInfoRespVO) {
|
||||||
window.localStorage.setItem(RefreshToken.SOTRAGE_USERINFO, JSON.stringify(userInfo))
|
window.localStorage.setItem(
|
||||||
|
RefreshToken.SOTRAGE_USERINFO,
|
||||||
|
JSON.stringify(userInfo)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// 获取token
|
// 获取token
|
||||||
getToken() {
|
static getToken() {
|
||||||
const token = window.localStorage.getItem(RefreshToken.SOTRAGE_TOKENKEY) || ''
|
const token =
|
||||||
const refreshToken = window.localStorage.getItem(RefreshToken.SOTRAGE_REFRESH_TOKEN_KEY) || ''
|
window.localStorage.getItem(RefreshToken.SOTRAGE_TOKENKEY) || "";
|
||||||
const userId = window.localStorage.getItem(RefreshToken.SOTRAGE_USERID) || ''
|
const refreshToken =
|
||||||
const userName = window.localStorage.getItem(RefreshToken.SOTRAGE_USERNAME) || ''
|
window.localStorage.getItem(RefreshToken.SOTRAGE_REFRESH_TOKEN_KEY) || "";
|
||||||
const userInfo = window.localStorage.getItem(RefreshToken.SOTRAGE_USERINFO) || ''
|
const userId =
|
||||||
|
window.localStorage.getItem(RefreshToken.SOTRAGE_USERID) || "";
|
||||||
|
const userName =
|
||||||
|
window.localStorage.getItem(RefreshToken.SOTRAGE_USERNAME) || "";
|
||||||
|
const userInfo =
|
||||||
|
window.localStorage.getItem(RefreshToken.SOTRAGE_USERINFO) || "";
|
||||||
return {
|
return {
|
||||||
token,
|
token,
|
||||||
refreshToken,
|
refreshToken,
|
||||||
userId,
|
userId,
|
||||||
userName,
|
userName,
|
||||||
userInfo: userInfo ? JSON.parse(userInfo) : {},
|
userInfo: userInfo ? JSON.parse(userInfo) : {},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 刷新token
|
|
||||||
refresh() {
|
export default RefreshToken;
|
||||||
return new Promise<{ token: string; refreshToken: string } | boolean>((resolve) => {
|
|
||||||
this.pending = true
|
|
||||||
const config = (this.onRefreshTokenResquest && this.onRefreshTokenResquest()) || {}
|
|
||||||
axios
|
|
||||||
.post(this.REFRESH_TOKEN_API_URL, config.data || {}, config.config)
|
|
||||||
.then((res) => {
|
|
||||||
const ac = this.onRefreshTokenResponse(res)
|
|
||||||
if (ac) {
|
|
||||||
// 设置新的token
|
|
||||||
this.setToken(ac.token, ac.refreshToken)
|
|
||||||
resolve(ac)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
resolve(false)
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
console.log(e)
|
|
||||||
this.onRefreshTokenResponse(false)
|
|
||||||
resolve(false)
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.pending = false
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// 推入刷新token成功 回调队列
|
|
||||||
pushCallbacks(config: AxiosRequestConfig) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
this.callbacks.push(() => {
|
|
||||||
resolve(this.axios(config))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// 推出队列回调
|
|
||||||
releaseQueue() {
|
|
||||||
// const tokens = this.getToken()
|
|
||||||
this.callbacks.forEach((item) => {
|
|
||||||
item()
|
|
||||||
})
|
|
||||||
this.callbacks = []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -96,3 +96,13 @@ export const downloadFile = (url: string, filename: string) => {
|
|||||||
a.click()
|
a.click()
|
||||||
document.body.removeChild(a)
|
document.body.removeChild(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断传入的参数是否为数组
|
||||||
|
* @param arr - 需要判断的参数
|
||||||
|
* @returns {boolean} 如果参数是数组则返回true,否则返回false
|
||||||
|
*/
|
||||||
|
export const isArray = (arr: any) => { // 定义一个名为isArray的导出函数,接收任意类型的参数arr
|
||||||
|
return Array.isArray(arr)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user