perf: menu selected and user info view
This commit is contained in:
+5
-1
@@ -3,5 +3,9 @@ import App from './App.vue'
|
|||||||
import Antd from 'ant-design-vue';
|
import Antd from 'ant-design-vue';
|
||||||
import 'ant-design-vue/dist/antd.less';
|
import 'ant-design-vue/dist/antd.less';
|
||||||
import router from './router/index';
|
import router from './router/index';
|
||||||
|
import { createPinia } from 'pinia'
|
||||||
|
|
||||||
createApp(App).use(Antd).use(router).mount('#app')
|
const pinia = createPinia()
|
||||||
|
const app = createApp(App)
|
||||||
|
|
||||||
|
app.use(Antd).use(router).use(pinia).mount('#app')
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
import { createPinia, defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
|
||||||
const pinia = createPinia();
|
export const useStore = defineStore('main', () => {
|
||||||
|
const selectedKeys = ref('dashboard')
|
||||||
export const useSpinStore = defineStore('spin', () => {
|
return { selectedKeys }
|
||||||
const spinning = ref(true)
|
|
||||||
return { spinning }
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const spinStore = useSpinStore(pinia)
|
|
||||||
+64
-98
@@ -8,7 +8,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<a-menu style="border-right: none;" v-model:selectedKeys="selectedKeys" mode="inline">
|
<a-menu style="border-right: none;" v-model:selectedKeys="selectedKeys" mode="inline">
|
||||||
<a-menu-item :key="item.key" v-for="item in menuItem">
|
<a-menu-item :key="item.key" v-for="item in menuItem">
|
||||||
<router-link :to="item.to">
|
<router-link :to="item.to" @click="store.selectedKeys = item.key" replace>
|
||||||
<component :is="item.icon" />
|
<component :is="item.icon" />
|
||||||
<span>{{ item.name }}</span>
|
<span>{{ item.name }}</span>
|
||||||
</router-link>
|
</router-link>
|
||||||
@@ -36,60 +36,40 @@
|
|||||||
</template>
|
</template>
|
||||||
</a-button>
|
</a-button>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
<!-- 个人信息 -->
|
<a-popover trigger="click" v-model:visible="popoverVisible" placement="bottomRight">
|
||||||
<a-dropdown :trigger="['click']">
|
<template #title>
|
||||||
<a-avatar @click="toMine" class="avatar" :size="28">U</a-avatar>
|
<div
|
||||||
<template #overlay>
|
style="display: flex;align-items: center;justify-content:space-between;flex-direction: row;padding: 10px 0;">
|
||||||
<a-menu>
|
<a-avatar @click="toMine" class="avatar" :size="50">U</a-avatar>
|
||||||
<a-menu-item key="0">
|
<div
|
||||||
<a @click="onMail">
|
style="display: flex;align-items:flex-start;flex-direction: column;margin: 0 10px;font-weight: normal;">
|
||||||
<MailOutlined /> 修改邮箱
|
<span>{{ user.email }}</span>
|
||||||
</a>
|
<sapn style="font-size: 12px;color: #476FFF;"><crown-two-tone style="font-size:15px;"
|
||||||
</a-menu-item>
|
two-tone-color="#476FFF" /> {{ user.versionText }}</sapn>
|
||||||
<a-menu-item key="1">
|
</div>
|
||||||
<a @click="onDelete">
|
</div>
|
||||||
<ClearOutlined /> 注销账号
|
</template>
|
||||||
</a>
|
<template #content>
|
||||||
</a-menu-item>
|
<div style="display: flex;align-items: center;justify-content:space-between;flex-direction: row;">
|
||||||
<a-menu-divider />
|
<a-button type="text" style="color: #476FFF;" @click="onDelete">注销账号</a-button>
|
||||||
<a-menu-item key="2">
|
<a-divider type="vertical" />
|
||||||
<a @click="onLogout">
|
<a-button type="text" @click="onLogout">退出登录</a-button>
|
||||||
<LogoutOutlined /> 退出账号
|
</div>
|
||||||
</a>
|
</template>
|
||||||
</a-menu-item>
|
<a-avatar @click="popoverVisible = true" class="avatar" :size="28">U</a-avatar>
|
||||||
</a-menu>
|
</a-popover>
|
||||||
</template>
|
|
||||||
</a-dropdown>
|
|
||||||
</div>
|
</div>
|
||||||
<!-- 修改邮箱弹出框 -->
|
|
||||||
<a-modal v-model:visible="visible" title="修改邮箱" @ok="onSave" @cancel="onCancel" cancelText="取消" okText="保存"
|
|
||||||
width="450px" style="top: 120px">
|
|
||||||
<a-form :model="user" layout="vertical" @finish="onSubmit" :rules="rules">
|
|
||||||
<a-form-item name="email">
|
|
||||||
<a-input v-model:value="user.email" size="large" placeholder="邮箱" disabled />
|
|
||||||
</a-form-item>
|
|
||||||
<a-form-item name="code">
|
|
||||||
<a-input v-model:value="user.code" size="large" style="width: 55%;" placeholder="验证码" />
|
|
||||||
<a-button @click="onGetCode" size="large" style="width: 40%;float: right;" :loading="loading"
|
|
||||||
:disabled="disabled">
|
|
||||||
{{ buttonText }}</a-button>
|
|
||||||
</a-form-item>
|
|
||||||
<a-form-item name="newEmail">
|
|
||||||
<a-input v-model:value="user.newEmail" size="large" placeholder="新邮箱" />
|
|
||||||
</a-form-item>
|
|
||||||
</a-form>
|
|
||||||
</a-modal>
|
|
||||||
<!-- 注销账号弹出框 -->
|
<!-- 注销账号弹出框 -->
|
||||||
<a-modal v-model:visible="delUserVisible" title="注销账号" @ok="onConfirm" @cancel="onCancel" cancelText="取消"
|
<a-modal v-model:visible="delUserVisible" title="注销账号" @ok="onConfirm" @cancel="onCancel" cancelText="取消"
|
||||||
okText="注销" width="450px" style="top: 120px">
|
okText="注销" width="360px" style="top: 120px">
|
||||||
|
<a-alert message="账号注销后,会清空账号相关的所有数据" banner /><br />
|
||||||
<a-form :model="user" layout="vertical" @finish="onSubmit" :rules="rules">
|
<a-form :model="user" layout="vertical" @finish="onSubmit" :rules="rules">
|
||||||
<a-form-item name="email">
|
<a-form-item name="email">
|
||||||
<a-input v-model:value="user.email" size="large" placeholder="邮箱" disabled />
|
<a-input v-model:value="user.email" placeholder="邮箱" disabled />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item name="code">
|
<a-form-item name="code">
|
||||||
<a-input v-model:value="user.code" size="large" style="width: 55%;" placeholder="验证码" />
|
<a-input v-model:value="user.code" style="width: 55%;" placeholder="验证码" />
|
||||||
<a-button @click="onGetCode" size="large" style="width: 40%;float: right;" :loading="loading"
|
<a-button @click="onGetCode" style="width: 40%;float: right;" :loading="loading" :disabled="disabled">
|
||||||
:disabled="disabled">
|
|
||||||
{{ buttonText }}</a-button>
|
{{ buttonText }}</a-button>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
@@ -107,14 +87,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { reactive, ref, onMounted } from 'vue';
|
import { reactive, ref, onBeforeMount } from 'vue';
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
import { useStore } from '../store/index';
|
||||||
import { message } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
import { getUserInfo, updateMail, getVerifyCode, userDelete } from '../api/user';
|
import { getUserInfo, getVerifyCode, userDelete } from '../api/user';
|
||||||
import { DashboardOutlined, SmileOutlined, MehOutlined, ShoppingOutlined } from '@ant-design/icons-vue';
|
import { DashboardOutlined, SmileOutlined, MehOutlined, ShoppingOutlined } from '@ant-design/icons-vue';
|
||||||
import { CrownOutlined, MenuUnfoldOutlined, MenuFoldOutlined, QuestionCircleFilled } from '@ant-design/icons-vue';
|
import { CrownOutlined, MenuUnfoldOutlined, MenuFoldOutlined, QuestionCircleFilled } from '@ant-design/icons-vue';
|
||||||
import { SmileFilled, BellFilled, MailOutlined, ClearOutlined } from '@ant-design/icons-vue';
|
import { SmileFilled, BellFilled } from '@ant-design/icons-vue';
|
||||||
import { LogoutOutlined, ExclamationCircleOutlined } from '@ant-design/icons-vue';
|
import { ExclamationCircleOutlined, CrownTwoTone } from '@ant-design/icons-vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -128,10 +109,8 @@ export default {
|
|||||||
QuestionCircleFilled,
|
QuestionCircleFilled,
|
||||||
SmileFilled,
|
SmileFilled,
|
||||||
BellFilled,
|
BellFilled,
|
||||||
MailOutlined,
|
|
||||||
ClearOutlined,
|
|
||||||
LogoutOutlined,
|
|
||||||
ExclamationCircleOutlined,
|
ExclamationCircleOutlined,
|
||||||
|
CrownTwoTone,
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
// 菜单选项
|
// 菜单选项
|
||||||
@@ -174,20 +153,17 @@ export default {
|
|||||||
trigger: 'blur',
|
trigger: 'blur',
|
||||||
}],
|
}],
|
||||||
code: [{ required: true, message: '请输入验证码!' }],
|
code: [{ required: true, message: '请输入验证码!' }],
|
||||||
newEmail: [{
|
|
||||||
required: true,
|
|
||||||
message: '请输入邮箱!',
|
|
||||||
trigger: 'blur',
|
|
||||||
}, {
|
|
||||||
pattern: /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/,
|
|
||||||
message: '邮箱格式不正确',
|
|
||||||
trigger: 'blur',
|
|
||||||
}],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectedKeys = ref(['dashboard'])
|
const store = useStore();
|
||||||
|
|
||||||
|
const selectedKeys = ref([store.selectedKeys])
|
||||||
const collapsed = ref(false)
|
const collapsed = ref(false)
|
||||||
|
|
||||||
|
store.$subscribe((mutation, state) => {
|
||||||
|
selectedKeys.value = [state.selectedKeys]
|
||||||
|
})
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const user = reactive({
|
const user = reactive({
|
||||||
@@ -195,10 +171,11 @@ export default {
|
|||||||
email: undefined,
|
email: undefined,
|
||||||
verison: undefined,
|
verison: undefined,
|
||||||
code: undefined,
|
code: undefined,
|
||||||
newEmail: undefined
|
versionText: undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
const visible = ref(false)
|
const visible = ref(false)
|
||||||
|
const popoverVisible = ref(false)
|
||||||
const visibleLogo = ref(false)
|
const visibleLogo = ref(false)
|
||||||
const delUserVisible = ref(false)
|
const delUserVisible = ref(false)
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@@ -206,7 +183,11 @@ export default {
|
|||||||
const buttonText = ref('获取验证码')
|
const buttonText = ref('获取验证码')
|
||||||
|
|
||||||
// 初始化数据
|
// 初始化数据
|
||||||
onMounted(() => { userInfo() })
|
onBeforeMount(() => {
|
||||||
|
userInfo()
|
||||||
|
store.selectedKeys = 'dashboard'
|
||||||
|
router.push('dashboard')
|
||||||
|
})
|
||||||
|
|
||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
const userInfo = () => {
|
const userInfo = () => {
|
||||||
@@ -214,35 +195,20 @@ export default {
|
|||||||
if (res.data.code == 0) {
|
if (res.data.code == 0) {
|
||||||
user.name = res.data.data.name
|
user.name = res.data.data.name
|
||||||
user.email = res.data.data.email
|
user.email = res.data.data.email
|
||||||
user.version = res.data.data.version
|
switch (res.data.data.version) {
|
||||||
|
case 1:
|
||||||
|
user.versionText = '基础版'
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
user.versionText = '专业版'
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
user.versionText = '高级版'
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
user.versionText = ''
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 点击升级到专业版
|
|
||||||
const onUpgrade = () => {
|
|
||||||
router.push('/subscribe')
|
|
||||||
}
|
|
||||||
|
|
||||||
// 点击修改邮箱
|
|
||||||
const onMail = () => {
|
|
||||||
visible.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确认修改邮箱
|
|
||||||
const onSave = () => {
|
|
||||||
let param = {
|
|
||||||
email: user.email,
|
|
||||||
code: user.code,
|
|
||||||
newEmail: user.newEmail
|
|
||||||
}
|
|
||||||
updateMail(param).then((res) => {
|
|
||||||
if (res.data.code == 0) {
|
|
||||||
router.push('/')
|
|
||||||
message.success('修改成功,请重新登录!')
|
|
||||||
}
|
|
||||||
if (res.data.code == 10005) {
|
|
||||||
message.error('验证码错误');
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -272,6 +238,7 @@ export default {
|
|||||||
|
|
||||||
// 点击注销账号
|
// 点击注销账号
|
||||||
const onDelete = () => {
|
const onDelete = () => {
|
||||||
|
popoverVisible.value = false
|
||||||
delUserVisible.value = true
|
delUserVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,6 +279,7 @@ export default {
|
|||||||
user,
|
user,
|
||||||
visible,
|
visible,
|
||||||
visibleLogo,
|
visibleLogo,
|
||||||
|
popoverVisible,
|
||||||
delUserVisible,
|
delUserVisible,
|
||||||
loading,
|
loading,
|
||||||
disabled,
|
disabled,
|
||||||
@@ -319,12 +287,10 @@ export default {
|
|||||||
userInfo,
|
userInfo,
|
||||||
onDelete,
|
onDelete,
|
||||||
onLogout,
|
onLogout,
|
||||||
onMail,
|
|
||||||
onGetCode,
|
onGetCode,
|
||||||
onSave,
|
|
||||||
onConfirm,
|
onConfirm,
|
||||||
onCancel,
|
onCancel,
|
||||||
onUpgrade,
|
store,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ import { reactive } from 'vue';
|
|||||||
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue';
|
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue';
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { userLogin } from '../api/user';
|
import { userLogin } from '../api/user';
|
||||||
import { initData } from '../api/common';
|
|
||||||
import { message } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
import { initData } from '../api/common';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -60,10 +60,10 @@ export default {
|
|||||||
}
|
}
|
||||||
userLogin(param).then((res) => {
|
userLogin(param).then((res) => {
|
||||||
if (res.data.code == 0) {
|
if (res.data.code == 0) {
|
||||||
|
initSysData()
|
||||||
localStorage.setItem('uid', res.data.data.uid)
|
localStorage.setItem('uid', res.data.data.uid)
|
||||||
localStorage.setItem('ver', res.data.data.ver)
|
localStorage.setItem('ver', res.data.data.ver)
|
||||||
localStorage.setItem('token', res.data.data.token)
|
localStorage.setItem('token', res.data.data.token)
|
||||||
initSysData()
|
|
||||||
router.push("/home")
|
router.push("/home")
|
||||||
}
|
}
|
||||||
if (res.data.code == 10002) {
|
if (res.data.code == 10002) {
|
||||||
@@ -95,7 +95,7 @@ export default {
|
|||||||
message.success('初始化数据成功!')
|
message.success('初始化数据成功!')
|
||||||
}
|
}
|
||||||
if (res.data.code == 11) {
|
if (res.data.code == 11) {
|
||||||
message.success('初始化数据失败!')
|
message.error('初始化数据失败!')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,8 @@ export default {
|
|||||||
onLogin,
|
onLogin,
|
||||||
onLoginFailed,
|
onLoginFailed,
|
||||||
forgotPass,
|
forgotPass,
|
||||||
toRegister
|
toRegister,
|
||||||
|
initSysData,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,13 +10,16 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
import { useStore } from '../store/index';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setup() {
|
setup() {
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const store = useStore()
|
||||||
|
|
||||||
const onBuy = () => {
|
const onBuy = () => {
|
||||||
|
store.selectedKeys = 'subscribe'
|
||||||
router.push('/subscribe')
|
router.push('/subscribe')
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user