diff --git a/components/ImgCropper.vue b/components/ImgCropper.vue
index b5d7383..b127bcd 100644
--- a/components/ImgCropper.vue
+++ b/components/ImgCropper.vue
@@ -75,21 +75,7 @@ export default {
methods: {
onSubmit() {
this.$refs.cropper.getCropData(data => {
- console.log(data)
this.$emit('onSubmit',data)
-
- // _ts.$axios.$patch('/api/user-info/update', user).then(function (res) {
- // if (res) {
- // if (res.message) {
- // _ts.$message.error(res.message);
- // } else {
- // _ts.$set(_ts, 'user', res);
- // _ts.$set(_ts, 'avatarUrl', res.avatarUrl);
- // _ts.$store.commit('setUserInfo', res);
- // _ts.$message.success('更新成功 !');
- // }
- // }
- // })
});
/*
@@ -106,17 +92,12 @@ export default {
this.$emit('update:visible', false)
},
realTime(data) {
- console.log(data)
this.cropImg = data;
// this.$emit('cropImg', data)
},
handleAvatarSuccess(res) {
let _ts = this;
if (res && res.data && res.data.url) {
- console.log(res.data.url)
- // let user = _ts.user;
- // user.avatarUrl = res.data.url;
- user.avatarType = '0';
_ts.$set(_ts, 'newAvatarUrl', res.data.url);
} else {
_ts.$message.error('上传失败!');
diff --git a/pages/user/settings.vue b/pages/user/settings.vue
index 4a5eac6..0a3ed13 100644
--- a/pages/user/settings.vue
+++ b/pages/user/settings.vue
@@ -10,10 +10,10 @@
基本信息
-
-
- 我的头像
-
+
+
+
+
账户安全
diff --git a/pages/user/settings/account.vue b/pages/user/settings/account.vue
index 6db53fd..e02d6aa 100644
--- a/pages/user/settings/account.vue
+++ b/pages/user/settings/account.vue
@@ -3,13 +3,30 @@
- 基本信息
+ 基本信息
-
-
+
+
+
+ {{ randomTitle }}
+
@@ -63,7 +80,7 @@
-
+
@@ -73,12 +90,16 @@
import {mapState} from 'vuex';
import ImgCropper from "~/components/ImgCropper.vue";
import VueCropper from "vue-cropper";
+import saveSvg from "save-svg-as-png";
+import Avataaars from 'vuejs-avataaars';
+
+const {generateRandomAvatar} = require('~/plugins/avataaars/generator/generateAvatar');
export default {
name: "account",
middleware: 'auth',
components: {
- ImgCropper, VueCropper
+ ImgCropper, VueCropper, Avataaars
},
computed: {
...mapState({
@@ -100,31 +121,35 @@ export default {
]
},
loading: false,
- visible: false
+ cropperVisible: false,
+ randomTitle: '随机施法',
+ avatar: {},
}
},
watch: {
- user() {
- console.log(this.user)
- }
},
methods: {
updateUser(data) {
- let _ts = this;
- let user = _ts.user;
- user.avatarUrl = data
- _ts.$axios.$patch('/api/user-info/update', user).then(function (res) {
- if (res) {
- if (res.message) {
- _ts.$message.error(res.message);
- } else {
- _ts.$set(_ts, 'user', res);
- // _ts.$set(_ts, 'avatarUrl', res.avatarUrl);
- // _ts.$store.commit('setUserInfo', res);
- _ts.$message.success('更新成功 !');
+ if (data) {
+ let _ts = this;
+ let user = _ts.user;
+ user.avatarUrl = data
+ user.avatarType = 1
+ _ts.$axios.$patch('/api/user-info/update', user).then(function (res) {
+ if (res) {
+ if (res.message) {
+ _ts.$message.error(res.message);
+ } else {
+ _ts.$set(_ts, 'user', res);
+ // _ts.$set(_ts, 'avatarUrl', res.avatarUrl);
+ // _ts.$store.commit('setUserInfo', res);
+ _ts.$message.success('更新成功 !');
+ _ts.cropperVisible = false
+ }
}
- }
- })
+ })
+ } else _ts.$message.error('失败,请重试');
+
},
getData() {
@@ -169,7 +194,23 @@ export default {
_ts.$message.success('更新成功 !');
}
})
- }
+ },
+ genAvatar() {
+ let _ts = this;
+ const avatar = generateRandomAvatar();
+ _ts.$set(_ts, 'avatar', avatar);
+
+ setTimeout(function () {
+ saveSvg.svgAsPngUri(document.getElementById('avatarSvg'), {}).then(uri => {
+ if (uri) {
+ _ts.updateUser(uri)
+ _ts.randomTitle = '‧★,:*:‧\\( ̄▽ ̄)/‧:*‧°★* 再来一次'
+ } else {
+ _ts.$message.error('头像上传失败 !');
+ }
+ });
+ }, 300);
+ },
},
mounted() {
this.$store.commit('setActiveMenu', 'account');
@@ -179,5 +220,9 @@ export default {