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>
|
||||
Reference in New Issue
Block a user