Files
LingXi-CRM/web/src/views/Home.vue
T

419 lines
12 KiB
Vue
Raw Normal View History

2022-11-28 16:38:45 +08:00
<template>
<a-layout style="min-height: 100vh">
<a-layout-sider width="180" class="sider" v-model:collapsed="collapsed" :trigger="null" collapsible>
<div class="logo">
2023-01-15 18:26:07 +08:00
<div><img src="../assets/logo.svg" style="width: 35px;height: 35px;filter: drop-shadow(2px 2px 6px #79bbff);" />
2022-11-28 16:38:45 +08:00
</div>
<div v-if="collapsed == false" class="title"><b>Z</b>O<b style="color: #1283FF;">C</b>RM</div>
</div>
<a-menu style="border-right: none;" v-model:selectedKeys="selectedKeys" mode="inline">
<a-menu-item :key="item.key" v-for="item in menuItem">
2022-12-24 19:45:54 +08:00
<router-link :to="item.to" @click="store.selectedKeys = item.key" replace>
2022-11-28 16:38:45 +08:00
<component :is="item.icon" />
<span>{{ item.name }}</span>
</router-link>
</a-menu-item>
</a-menu>
</a-layout-sider>
<a-layout>
<a-layout-header class="header">
<div>
<menu-unfold-outlined v-if="collapsed" class="trigger" @click="() => (collapsed = !collapsed)" />
<menu-fold-outlined v-else class="trigger" @click="() => (collapsed = !collapsed)" />
</div>
<div style="display: flex;align-items: center;justify-items: center;">
2023-01-02 11:00:29 +08:00
<a-popover placement="bottomRight" :overlayStyle="{ width: '180px' }" trigger="click">
<template #content>
2023-01-04 23:19:32 +08:00
<a-image :width="150" src="https://zocrm.cloud/gzh_qrcode.jpg" :preview="false" />
2022-11-28 16:38:45 +08:00
</template>
2023-01-02 11:00:29 +08:00
<QuestionCircleFilled style="color: #909399; font-size: 18px;margin: 0 15px;" />
</a-popover>
<a-popover placement="bottomRight" :overlayStyle="{ width: '320px' }" trigger="click">
2022-12-24 19:45:54 +08:00
<template #content>
2023-01-02 11:00:29 +08:00
<div style="max-height: 250px;overflow-y: scroll;">
<a-list item-layout="horizontal" :data-source="data.noticeList" size="small">
<template #renderItem="{ item }">
<a-list-item style="cursor: pointer;" @click="onReadNotice(item.id)">
<div style="display: inline-flex;align-items: center;">
<a-avatar shape="square" :size="20" v-if="item.status == 1">
<template #icon>
<BellFilled style="font-size: 12px;" />
</template>
</a-avatar>
<a-avatar shape="square" style="color: #476FFF; background-color: #ccd6fa" :size="20" v-else>
<template #icon>
<BellFilled style="font-size: 12px;" />
</template>
</a-avatar>
<div v-if="item.status == 1" style="color: #717171;">&nbsp;&nbsp;&nbsp;{{ item.content }}</div>
<div v-else>&nbsp;&nbsp;&nbsp;{{ item.content }}</div>
</div>
<template #actions>
<span v-if="item.status == 2" style="color: black;">{{ formatDate(item.created) }}</span>
<span v-else>{{ formatDate(item.created) }}</span>
</template>
</a-list-item>
</template>
</a-list>
</div>
<div style="margin-top: 10px;display: flex;align-items: center;justify-content: center;">
<a-button v-if="data.noticeList.length != 0" @click="onDeleteNotice" type="primary" style="width: 92%;"
shape="round">清空全部 {{ data.noticeList.length }} 条通知</a-button>
2022-12-24 19:45:54 +08:00
</div>
</template>
2023-01-02 11:00:29 +08:00
<a-badge :count="data.noticeCount">
<BellFilled style="color: #909399; font-size: 20px;cursor: pointer;" @click="onNotice" />
</a-badge>
2022-12-24 19:45:54 +08:00
</a-popover>
2023-01-02 11:00:29 +08:00
<a-dropdown :trigger="['click']">
<a-avatar @click="onUserAvatar" class="avatar" :size="32">U</a-avatar>
<template #overlay>
<a-menu>
<a-menu-item @click="visible = true">
<ExclamationCircleOutlined /> 注销账号
</a-menu-item>
<a-menu-item @click="onLogout">
<LogoutOutlined /> 退出登录
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
2022-11-28 16:38:45 +08:00
</div>
<!-- 注销账号弹出框 -->
2023-01-02 11:00:29 +08:00
<a-modal v-model:visible="visible" title="注销账号" @ok="onConfirm" @cancel="onCancel" cancelText="取消" okText="注销"
width="360px" :centered="true">
2022-12-24 19:45:54 +08:00
<a-alert message="账号注销后,会清空账号相关的所有数据" banner /><br />
2022-12-10 22:57:58 +08:00
<a-form :model="user" layout="vertical" @finish="onSubmit" :rules="rules">
<a-form-item name="email">
2022-12-24 19:45:54 +08:00
<a-input v-model:value="user.email" placeholder="邮箱" disabled />
2022-11-28 16:38:45 +08:00
</a-form-item>
2022-12-10 22:57:58 +08:00
<a-form-item name="code">
2022-12-24 19:45:54 +08:00
<a-input v-model:value="user.code" style="width: 55%;" placeholder="验证码" />
<a-button @click="onGetCode" style="width: 40%;float: right;" :loading="loading" :disabled="disabled">
2022-11-28 16:38:45 +08:00
{{ buttonText }}</a-button>
</a-form-item>
</a-form>
</a-modal>
</a-layout-header>
<a-layout-content :style="{ margin: '10px', padding: '18px 18px 12px 18px', background: '#fff' }">
<transition name="fade">
<router-view v-slot="{ Component }">
<component :is="Component" />
</router-view>
</transition>
</a-layout-content>
</a-layout>
</a-layout>
</template>
<script>
2022-12-24 19:45:54 +08:00
import { reactive, ref, onBeforeMount } from 'vue';
2022-11-28 16:38:45 +08:00
import { useRouter } from 'vue-router'
2022-12-24 19:45:54 +08:00
import { useStore } from '../store/index';
2022-11-28 16:38:45 +08:00
import { message } from 'ant-design-vue';
2022-12-24 19:45:54 +08:00
import { getUserInfo, getVerifyCode, userDelete } from '../api/user';
2023-01-02 11:00:29 +08:00
import { updateNotice, getNoticeCount, getNoticeList, deleteNotice } from '../api/notice';
2022-11-28 16:38:45 +08:00
import { DashboardOutlined, SmileOutlined, MehOutlined, ShoppingOutlined } from '@ant-design/icons-vue';
2023-01-02 11:00:29 +08:00
import { CrownOutlined, MenuUnfoldOutlined, MenuFoldOutlined, WechatFilled } from '@ant-design/icons-vue';
import { QuestionCircleFilled, BellFilled } from '@ant-design/icons-vue';
import { ExclamationCircleOutlined, CrownFilled, LogoutOutlined, DownCircleOutlined, DeleteOutlined } from '@ant-design/icons-vue';
import moment from 'moment'
2022-11-28 16:38:45 +08:00
export default {
components: {
DashboardOutlined,
SmileOutlined,
MehOutlined,
ShoppingOutlined,
CrownOutlined,
MenuUnfoldOutlined,
MenuFoldOutlined,
2023-01-02 11:00:29 +08:00
WechatFilled,
2022-11-28 16:38:45 +08:00
QuestionCircleFilled,
BellFilled,
ExclamationCircleOutlined,
2022-12-24 22:27:55 +08:00
CrownFilled,
2023-01-02 11:00:29 +08:00
LogoutOutlined,
DownCircleOutlined,
DeleteOutlined
2022-11-28 16:38:45 +08:00
},
setup() {
// 菜单选项
const menuItem = reactive([{
key: "dashboard",
to: "/dashboard",
icon: "dashboard-outlined",
name: "仪表盘"
}, {
key: "customer",
to: "/customer",
icon: "smile-outlined",
name: "客户"
}, {
key: "contract",
to: "/contract",
icon: "meh-outlined",
name: "合同"
}, {
key: "product",
to: "/product",
icon: "shopping-outlined",
name: "产品"
}, {
key: "subscribe",
to: "/subscribe",
icon: "crown-outlined",
name: "订阅"
}])
2022-12-10 22:57:58 +08:00
// 表单校验
const rules = {
email: [{
required: true,
message: '请输入邮箱!',
trigger: 'blur',
}, {
pattern: /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/,
message: '邮箱格式不正确',
trigger: 'blur',
}],
code: [{ required: true, message: '请输入验证码!' }],
};
2022-12-24 19:45:54 +08:00
const store = useStore();
const selectedKeys = ref([store.selectedKeys])
2022-11-28 16:38:45 +08:00
const collapsed = ref(false)
2023-01-02 11:00:29 +08:00
const data = reactive({
noticeCount: 0,
noticeList: []
})
2022-12-24 19:45:54 +08:00
store.$subscribe((mutation, state) => {
selectedKeys.value = [state.selectedKeys]
})
2022-11-28 16:38:45 +08:00
const router = useRouter()
const user = reactive({
name: undefined,
email: undefined,
verison: undefined,
code: undefined,
2022-12-24 19:45:54 +08:00
versionText: undefined
2022-11-28 16:38:45 +08:00
})
const visible = ref(false)
const visibleLogo = ref(false)
2022-12-02 22:00:23 +08:00
const loading = ref(false)
2022-11-28 16:38:45 +08:00
const disabled = ref(false)
const buttonText = ref('获取验证码')
// 初始化数据
2022-12-24 19:45:54 +08:00
onBeforeMount(() => {
store.selectedKeys = 'dashboard'
router.push('dashboard')
2023-01-02 11:00:29 +08:00
noticeCount()
2022-12-24 19:45:54 +08:00
})
2022-11-28 16:38:45 +08:00
2022-12-24 22:27:55 +08:00
// 点击用户头像
const onUserAvatar = () => {
2022-11-28 16:38:45 +08:00
getUserInfo().then((res) => {
if (res.data.code == 0) {
user.name = res.data.data.name
user.email = res.data.data.email
2022-12-24 22:27:55 +08:00
user.version = res.data.data.version
2022-11-28 16:38:45 +08:00
}
})
}
// 点击获取验证码
const onGetCode = () => {
if (user.email == '') {
message.warn('邮箱不能为空')
2022-12-02 22:00:23 +08:00
return
2022-11-28 16:38:45 +08:00
}
2022-12-02 22:00:23 +08:00
loading.value = true
2022-11-28 16:38:45 +08:00
let param = {
email: user.email
}
getVerifyCode(param).then((res) => {
if (res.data.code == 0) {
2022-12-02 22:00:23 +08:00
loading.value = false
2022-11-28 16:38:45 +08:00
disabled.value = true
buttonText.value = '验证码已发送'
}
2022-12-02 22:00:23 +08:00
if (res.data.code == 10004) {
loading.value = false
message.error('验证码发送失败')
}
2022-11-28 16:38:45 +08:00
})
}
// 点击确认注销账号
const onConfirm = () => {
let param = {
email: user.email,
code: user.code
}
userDelete(param).then((res) => {
if (res.data.code == 0) {
router.push('/')
message.success('账号已注销')
}
})
}
2023-01-02 11:00:29 +08:00
// 日期格式化
const formatDate = (timeStamp) => {
let now = (Date.parse(new Date())) / 1000
if (now - timeStamp < 60) {
return "刚刚"
}
if ((new Date().getDate()) == (new Date(timeStamp * 1000).getDate())) {
return "今天 " + moment(timeStamp * 1000).format('HH:mm')
}
return moment(timeStamp * 1000).format('YYYY-MM-DD')
}
// 点击读取通知
const onReadNotice = (id) => {
updateNotice({ id: id }).then((res) => {
if (res.data.code == 0) {
onNotice()
noticeCount()
}
})
}
// 获取通知数量
const noticeCount = () => {
getNoticeCount().then((res) => {
if (res.data.code == 0) {
data.noticeCount = res.data.data.count
}
})
}
// 获取通知列表
const onNotice = () => {
getNoticeList().then((res) => {
if (res.data.code == 0) {
data.noticeList = res.data.data
}
})
}
// 删除通知
const onDeleteNotice = () => {
let ids = []
for (let index = 0; index < data.noticeList.length; index++) {
ids[index] = data.noticeList[index].id
}
deleteNotice({ ids: ids }).then((res) => {
if (res.data.code == 0) {
data.noticeList = res.data.data
onNotice()
}
})
}
2022-11-28 16:38:45 +08:00
// 点击退出账号
const onLogout = () => {
2022-12-17 20:37:03 +08:00
localStorage.removeItem("uid")
localStorage.removeItem("token")
router.push('/')
2022-11-28 16:38:45 +08:00
}
// 点击取消按钮
const onCancel = () => {
2022-12-02 22:00:23 +08:00
disabled.value = false
2022-11-28 16:38:45 +08:00
modalFormRef.value.resetFields()
visible.value = false
};
return {
menuItem,
2022-12-10 22:57:58 +08:00
rules,
2022-11-28 16:38:45 +08:00
selectedKeys,
collapsed,
user,
visible,
visibleLogo,
2022-12-02 22:00:23 +08:00
loading,
2022-11-28 16:38:45 +08:00
disabled,
buttonText,
2022-12-24 22:27:55 +08:00
onUserAvatar,
2022-11-28 16:38:45 +08:00
onLogout,
onGetCode,
onConfirm,
2023-01-02 11:00:29 +08:00
onNotice,
onReadNotice,
noticeCount,
onDeleteNotice,
2022-11-28 16:38:45 +08:00
onCancel,
2022-12-24 19:45:54 +08:00
store,
2023-01-02 11:00:29 +08:00
formatDate,
data
2022-11-28 16:38:45 +08:00
};
},
}
</script>
<style scoped>
.sider {
background: #fff;
border-right: 0.5px solid #F0F2F5;
}
.header {
padding: 0 12px;
display: flex;
align-items: center;
justify-content: space-between;
background: #fff;
}
.trigger {
font-size: 18px;
padding: 0 8px;
cursor: pointer;
transition: color 0.3s;
}
.trigger:hover {
color: #476FFF;
}
.logo {
height: 32px;
margin: 16px;
display: flex;
align-items: center;
justify-content: center;
}
.avatar {
color: #f56a00;
background-color: #fde3cf;
cursor: pointer;
2023-01-02 11:00:29 +08:00
margin-left: 20px;
2022-11-28 16:38:45 +08:00
}
.popover {
display: flex;
align-items: center;
justify-content: center;
padding: 10px 0;
}
.title {
font-size: 25px;
color: rgba(31, 31, 31, 0.85);
font-weight: 620;
margin-left: 10px;
overflow: hidden;
}
</style>