Skip to content

Commit

Permalink
feat: Setting
Browse files Browse the repository at this point in the history
  • Loading branch information
xinufo committed Sep 1, 2019
1 parent a1eccf4 commit 87e1021
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 10 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"nprogress": "^0.2.0",
"viser-vue": "^2.4.6",
"vue": "^2.6.10",
"vue-cropper": "^0.4.9",
"vue-ls": "^3.2.1",
"vue-router": "^3.0.1",
"vue-svg-component-runtime": "^1.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/config/router.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ export const asyncRouterMap = [
path: '/account/settings',
name: 'settings',
component: () => import('@/views/account/settings/Index'),
meta: { title: '个人设置', hideHeader: true, permission: ['user'] },
meta: { title: '个人设置', hideHeader: true },
redirect: '/account/settings/base',
hideChildrenInMenu: true,
children: [
{
path: '/account/settings/base',
name: 'BaseSettings',
component: () => import('@/views/account/settings/BaseSetting'),
meta: { title: '基本设置', hidden: true, permission: ['user'] }
meta: { title: '基本设置', hidden: true }
},
{
path: '/account/settings/security',
Expand Down
111 changes: 111 additions & 0 deletions src/views/account/settings/AvatarModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<template>
<a-modal
title="修改头像"
:visible="visible"
:maskClosable="false"
:confirmLoading="confirmLoading"
:width="800"
@cancel="cancelHandel"
>
<a-row>
<a-col :xs="24" :md="12" :style="{height: '350px'}">
<vue-cropper
ref="cropper"
:img="options.img"
:info="options.info"
:outputSize="options.outputSize"
:outputType="options.outputType"
:canScale="options.canScale"
:autoCrop="options.autoCrop"
:autoCropWidth="options.autoCropWidth"
:autoCropHeight="options.autoCropHeight"
:fixed="options.fixed"
:fixedNumber="options.fixedNumber"
@realTime="realTime"
></vue-cropper>
</a-col>
<a-col :xs="24" :md="12" :style="{height: '350px'}">
<div class="avatar-upload-preview">
<img :src="previews.url" :style="previews.img" />
</div>
</a-col>
</a-row>

<template slot="footer">
<a-button key="back" @click="cancelHandel">取消</a-button>
<a-button key="submit" type="primary" :loading="confirmLoading" @click="okHandel">保存</a-button>
</template>
</a-modal>
</template>
<script>
import { VueCropper } from 'vue-cropper'
export default {
components: {
VueCropper
},
data () {
return {
imgFile: '',
visible: false,
confirmLoading: false,
options: {
img: '', // 裁剪图片的地址
info: true, // 裁剪框的大小信息
outputSize: 1, // 裁剪生成图片的质量
outputType: 'jpeg', // 裁剪生成图片的格式
canScale: false, // 图片是否允许滚轮缩放
autoCrop: true, // 是否默认生成截图框
autoCropWidth: 200, // 默认生成截图框宽度
autoCropHeight: 200, // 默认生成截图框高度
fixed: true, // 是否开启截图框宽高固定比例
fixedNumber: [1, 1]// 截图框的宽高比例
},
previews: {}
}
},
methods: {
edit (avatar) {
this.options.img = avatar
this.visible = true
},
close () {
this.visible = false
},
cancelHandel () {
this.close()
},
okHandel () {
const vm = this
vm.confirmLoading = true
setTimeout(() => {
vm.confirmLoading = false
vm.close()
vm.$message.success('上传头像成功')
}, 2000)
},
realTime (data) {
this.previews = data
}
}
}
</script>

<style lang="less" scoped>
.avatar-upload-preview {
position: absolute;
top: 50%;
transform: translate(50%, -50%);
width: 180px;
height: 180px;
border-radius: 50%;
box-shadow: 0 0 4px #ccc;
overflow: hidden;
img {
width: 100%;
height: 100%;
}
}
</style>
87 changes: 87 additions & 0 deletions src/views/account/settings/BaseSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,109 @@
</a-form-item>
</a-form>
</a-col>
<a-col :md="24" :lg="8" :style="{ minHeight: '180px' }">
<div class="ant-upload-preview" @click="$refs.modal.edit(avatar)">
<a-icon type="cloud-upload-o" class="upload-icon" />
<div class="mask">
<a-icon type="plus" />
</div>
<img :src="avatar" />
</div>
</a-col>
</a-row>
<avatar-modal ref="modal" />
</div>
</template>

<script>
import { mapGetters } from 'vuex'
import AvatarModal from './AvatarModal'
export default {
components: {
AvatarModal
},
data () {
return {
option: {
img: undefined,
info: true,
size: 1,
outputType: 'jpeg',
canScale: false,
autoCrop: true,
// 只有自动截图开启 宽度高度才生效
autoCropWidth: 180,
autoCropHeight: 180,
fixedBox: true,
// 开启宽度和高度比例
fixed: true,
fixedNumber: [1, 1]
}
}
},
computed: {
...mapGetters(['avatar'])
},
methods: {
}
}
</script>

<style lang="less" scoped>
.avatar-upload-wrapper {
height: 200px;
width: 100%;
}
.ant-upload-preview {
position: relative;
margin: 0 auto;
width: 100%;
max-width: 180px;
border-radius: 50%;
box-shadow: 0 0 4px #ccc;
.upload-icon {
position: absolute;
top: 0;
right: 10px;
font-size: 1.4rem;
padding: 0.5rem;
background: rgba(222, 221, 221, 0.7);
border-radius: 50%;
border: 1px solid rgba(0, 0, 0, 0.2);
}
.mask {
opacity: 0;
position: absolute;
background: rgba(0, 0, 0, 0.4);
cursor: pointer;
transition: opacity 0.4s;
&:hover {
opacity: 1;
}
i {
font-size: 2rem;
position: absolute;
top: 50%;
left: 50%;
margin-left: -1rem;
margin-top: -1rem;
color: #d6d6d6;
}
}
img,
.mask {
width: 100%;
max-width: 180px;
height: 100%;
border-radius: 50%;
overflow: hidden;
}
}
</style>
14 changes: 6 additions & 8 deletions src/views/dashboard/Workplace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<script>
import moment from 'moment'
import { timeFix } from '@/utils/util'
import { mapState } from 'vuex'
import { mapGetters } from 'vuex'
import { PageView } from '@/layouts'
import { TagCloud } from '@/components'
Expand Down Expand Up @@ -161,13 +161,11 @@ export default {
}
},
computed: {
...mapState({
nickname: (state) => state.user.nickname,
welcome: (state) => state.user.welcome
}),
userInfo () {
return this.$store.getters.userInfo
}
...mapGetters([
'nickname',
'welcome',
'userInfo'
])
},
created () {
this.user = this.userInfo
Expand Down

0 comments on commit 87e1021

Please sign in to comment.