Skip to content

Commit

Permalink
feat: change default avatar and username
Browse files Browse the repository at this point in the history
  • Loading branch information
Pleasurecruise committed Nov 14, 2024
1 parent 192ae1b commit bb4f88f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,26 @@ public Student wxLogin(StudentLoginDTO studentLoginDTO) {
}
Student student = studentMapper.findByOpenid(openid);
if (student == null) {
String[] avatars = {
"https://yiming1234.oss-cn-beijing.aliyuncs.com/zhongli.jpg",
"https://yiming1234.oss-cn-beijing.aliyuncs.com/xiao.jpg",
"https://yiming1234.oss-cn-beijing.aliyuncs.com/puren.jpg",
"https://yiming1234.oss-cn-beijing.aliyuncs.com/wendi.jpg",
"https://yiming1234.oss-cn-beijing.aliyuncs.com/ganyu.jpg",
"https://yiming1234.oss-cn-beijing.aliyuncs.com/linren.jpg",
"https://yiming1234.oss-cn-beijing.aliyuncs.com/linhua.jpg",
"https://yiming1234.oss-cn-beijing.aliyuncs.com/leidian.jpg",
"https://yiming1234.oss-cn-beijing.aliyuncs.com/naxida.jpg",
"https://yiming1234.oss-cn-beijing.aliyuncs.com/diluke.jpg",
"https://yiming1234.oss-cn-beijing.aliyuncs.com/jiaming.jpg",
"https://yiming1234.oss-cn-beijing.aliyuncs.com/default.jpg",
};
String avatar = avatars[(int) (Math.random() * avatars.length)];
student = Student.builder()
.openid(openid)
.username("飞天裤衩")
.username("传奇绳匠" + System.currentTimeMillis())
.sex("1")
.avatar("https://yiming1234.oss-cn-beijing.aliyuncs.com/default.jpg")
.avatar(avatar)
.createTime(LocalDateTime.now())
.build();
studentMapper.insert(student);
Expand Down
13 changes: 10 additions & 3 deletions uniapp/.idea/workspace.xml

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

2 changes: 1 addition & 1 deletion uniapp/src/pages/favorites/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

<script>
import uniNoticeBar from '@dcloudio/uni-ui/lib/uni-notice-bar/uni-notice-bar.vue';
import uniSection from "@dcloudio/uni-ui/lib/uni-section/uni-section.vue";
import TopicComponent from './components/topic.vue';
import { fetchCollectedTopics} from "@/api/collect";
import uniSection from "@dcloudio/uni-ui/lib/uni-section/uni-section.vue";
export default {
components: {
Expand Down
40 changes: 22 additions & 18 deletions uniapp/src/pages/person/editInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,31 @@
</template>

<script>
import { baseUrl } from "@/utils/env"; // 引入环境变量
import {baseUrl} from "@/utils/env";
import View from "@/pages/person/editInfo.vue";
export default {
/**
* 页面的初始数据
*/
components: {
View
},
data() {
return {
avatarUrl: '', // 初始化头像URL
originalAvatarUrl: '', // 保存从服务器获取的原始头像URL
avatarUrl: '',
originalAvatarUrl: '',
nickName: '',
selectedSex: 'Male', // 默认选择
sexValueMap: { // 性别值映射
studentid: '',
selectedSex: 'Male',
sexValueMap: {
'Male': 1,
'Female': 2,
},
studentid: '' // 初始化学生号
};
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
// 获取用户信息
uni.request({
url: baseUrl + '/student/get/info',
method: 'GET',
Expand All @@ -67,7 +68,7 @@ export default {
if (res.data.code === 1) {
this.nickName = res.data.data.username;
this.avatarUrl = res.data.data.avatar;
this.originalAvatarUrl = res.data.data.avatar; // 保存原始头像URL
this.originalAvatarUrl = res.data.data.avatar;
this.studentid = res.data.data.studentid;
this.selectedSex = res.data.data.sex === "1" ? 'Male' : 'Female';
console.log('获取用户信息成功:', res.data.data);
Expand Down Expand Up @@ -103,6 +104,7 @@ export default {
logError(error) {
console.error('Error:', error);
},
/**
* 提交表单
*/
Expand All @@ -115,7 +117,7 @@ export default {
return;
}
if (this.avatarUrl === this.originalAvatarUrl) {
this.updateUserInfo(this.avatarUrl);
this.updateUserInfo(this.originalAvatarUrl);
} else {
uni.uploadFile({
url: baseUrl + '/student/common/upload',
Expand All @@ -128,8 +130,7 @@ export default {
try {
const responseData = JSON.parse(res.data);
if (responseData.code === 1) {
const avatar = responseData.data;
this.updateUserInfo(avatar);
this.updateUserInfo(responseData);
} else {
console.log('上传失败:', responseData.msg);
uni.showToast({
Expand Down Expand Up @@ -157,25 +158,28 @@ export default {
});
}
},
/**
* 更新用户信息
* @param avatarUrl 头像 URL
*/
updateUserInfo(avatarUrl) {
updateUserInfo() {
console.log('更新用户信息:', this.nickName, this.avatarUrl, this.sexValueMap[this.selectedSex], this.studentid),
uni.request({
url: baseUrl + '/student/update/info',
method: 'PUT',
header: {
token: uni.getStorageSync('token')
token: uni.getStorageSync('token'),
'Content-Type': 'application/json'
},
data: {
username: this.nickName,
avatar: avatarUrl[0],
avatar: this.avatarUrl,
sex: this.sexValueMap[this.selectedSex],
studentid: this.studentid
},
success: (res) => {
if (res.data.code === 1) {
console.log(res.data.data);
uni.showToast({
title: '更新成功',
icon: 'success',
Expand Down
17 changes: 1 addition & 16 deletions uniapp/src/pages/topic/view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ export default {
this.loadComments();
},
methods: {
/**
* 获取用户信息
* @param authorID
* @returns {Object}
*/
getUserInfo(authorID) {
if (!authorID) {
Expand All @@ -207,8 +206,6 @@ export default {
/**
* 异步获取用户信息
* @param authorID
* @returns {Promise<void>}
*/
async fetchUserInfo(authorID) {
if (!this.userInfoMap[authorID]) {
Expand All @@ -224,7 +221,6 @@ export default {
/**
* 加载评论
* @returns {Promise<void>}
*/
async loadComments() {
if (this.loadMoreStatus === 'loading' || this.loadMoreStatus === 'noMore') {
Expand Down Expand Up @@ -278,7 +274,6 @@ export default {
/**
* 显示评论操作菜单
* @param {Object} comment
*/
showCommentActionSheet(comment) {
const isAuthor = String(this.currentUserId) === String(comment.userId);
Expand Down Expand Up @@ -312,7 +307,6 @@ export default {
// 创建话题不在该页面
/**
* 删除话题
* @returns {Promise<void>}
*/
async deleteTopic() {
try {
Expand All @@ -331,7 +325,6 @@ export default {
/**
* 处理点赞操作
* @returns {Promise<void>}
*/
async handleLike() {
try {
Expand All @@ -354,7 +347,6 @@ export default {
/**
* 处理收藏操作
* @returns {Promise<void>}
*/
async handleCollect() {
try {
Expand All @@ -373,7 +365,6 @@ export default {
/**
* 提交评论
* @returns {Promise<void>}
*/
async submitComment() {
if (!this.commentContent.trim()) {
Expand All @@ -394,7 +385,6 @@ export default {
/**
* 刷新评论列表和计数
* @returns {Promise<void>}
*/
async refreshComments() {
try {
Expand All @@ -414,8 +404,6 @@ export default {
/**
* 删除评论
* @param {Object} comment
* @returns {Promise<void>}
*/
async deleteCommentAction(comment) {
try {
Expand All @@ -440,7 +428,6 @@ export default {
/**
* 回复评论
* @param {Object} comment
*/
async replyToComment(comment) {
// TODO: 实现回复评论功能
Expand All @@ -449,8 +436,6 @@ export default {
/**
* 点赞/取消点赞评论
* @param {Object} comment
* @returns {Promise<void>}
*/
async toggleCommentLike(comment) {
try {
Expand Down

0 comments on commit bb4f88f

Please sign in to comment.