finished avatar upload and some little functions.

DEV
PeterAlbus 3 years ago
parent 9ec450989f
commit 94ccb9a657

@ -76,4 +76,14 @@ public class AdminController
} }
return "error"; return "error";
} }
@ResponseBody
@RequestMapping("/setAdmin")
public String setAdmin(Long userId)
{
if(userService.setAdmin(userId)>0)
{
return "success";
}
return "error";
}
} }

@ -93,4 +93,11 @@ public class UserService
{ {
return userDao.selectById(userId); return userDao.selectById(userId);
} }
public int setAdmin(Long userId)
{
User user=userDao.selectById(userId);
user.setUserClass(0);
return userDao.updateById(user);
}
} }

@ -20,11 +20,16 @@
</head> </head>
<body> <body>
<div id="app"> <div id="app">
<Modal
v-model="modal1"
title="如何创建管理员?">
<p>如果需要创建管理员账号,请先注册一个任意类型的新账号,然后联系网站管理员将您设为管理员</p>
</Modal>
<Row class="login-box"> <Row class="login-box">
<i-col span="12"> <i-col span="12">
<img src="${pageContext.request.contextPath}/img/1.jpeg" alt="" class="login-img"/> <img src="${pageContext.request.contextPath}/img/1.jpeg" alt="" class="login-img"/>
</i-col> </i-col>
<i-col span="12"> <i-col span="12" style="overflow: hidden">
<i-form ref="form" :model="form" :rules="rule" :label-width="80" class="login-form"> <i-form ref="form" :model="form" :rules="rule" :label-width="80" class="login-form">
<h1 class="login-title">用户注册</h1> <h1 class="login-title">用户注册</h1>
<Alert type="error" show-icon v-if="info!==''">{{info}}</Alert> <Alert type="error" show-icon v-if="info!==''">{{info}}</Alert>
@ -32,7 +37,10 @@
<Avatar :src="form.avatarSrc" size="large"></Avatar> <Avatar :src="form.avatarSrc" size="large"></Avatar>
</Form-item> </Form-item>
<Form-item> <Form-item>
<Upload action="#" on-success="uploadSuccess"> <Upload action="https://www.peteralbus.com:8089/photo/customUpload/"
:data="upData"
:default-file-list="fileList"
:on-success="handleAvatarSuccess">
<i-button type="primary" icon="ios-cloud-upload-outline">上传头像</i-button> <i-button type="primary" icon="ios-cloud-upload-outline">上传头像</i-button>
</Upload> </Upload>
</Form-item> </Form-item>
@ -69,7 +77,7 @@
</i-select> </i-select>
</Form-item> </Form-item>
<Form-item> <Form-item>
<Checkbox v-model="canRegister">我同意本站的许可条款</Checkbox> <Checkbox v-model="canRegister">我同意本站的许可条款</Checkbox><Icon type="ios-help" @click="modal1=true"></Icon>
</Form-item> </Form-item>
<Form-item> <Form-item>
<i-button type="primary" @click="handleSubmit('form')" size="large" shape="circle" :loading="loading" :disabled="!canRegister">注册</i-button> <i-button type="primary" @click="handleSubmit('form')" size="large" shape="circle" :loading="loading" :disabled="!canRegister">注册</i-button>
@ -93,8 +101,10 @@
} }
}; };
return { return {
fileList:[],
canRegister:false, canRegister:false,
loading:false, loading:false,
modal1:false,
info:'', info:'',
form: { form: {
username: '', username: '',
@ -171,9 +181,34 @@
} }
}) })
}, },
handleSuccess (res, file) { handleAvatarSuccess(res, file, fileList) {
console.log(res.data) console.log(res)
this.form.avatarSrc = res;
this.fileList=[]
this.$Message.success('上传头像成功!')
},
uuid() {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
var uuid = s.join("");
return uuid;
}
}, },
computed:{
upData:function () {
let uuid=this.uuid();
return {
path: 'social/',
saveName: uuid
}
}
} }
}) })
</script> </script>

@ -60,9 +60,10 @@
<el-form-item label="头像"> <el-form-item label="头像">
<el-upload <el-upload
class="avatar-uploader" class="avatar-uploader"
action="https://jsonplaceholder.typicode.com/posts/" action="https://www.peteralbus.com:8089/photo/customUpload/"
:show-file-list="false" :show-file-list="false"
<%-- :on-success="handleAvatarSuccess"--%> :data="upData"
:on-success="handleAvatarSuccess"
<%-- :before-upload="beforeAvatarUpload"--%> <%-- :before-upload="beforeAvatarUpload"--%>
> >
<img v-if="user.avatarSrc" :src="user.avatarSrc" class="avatar"/> <img v-if="user.avatarSrc" :src="user.avatarSrc" class="avatar"/>
@ -82,7 +83,9 @@
<el-input type="text" v-model="user.userPhone" placeholder="phone number"></el-input> <el-input type="text" v-model="user.userPhone" placeholder="phone number"></el-input>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="handleSubmit('form')" size="large" :loading="loading">保存</el-button> <el-button type="primary" @click="handleSubmit('form')" size="large" :loading="loading">
保存
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
@ -134,6 +137,11 @@
this.user.userPhone = '${userPhone}' this.user.userPhone = '${userPhone}'
}, },
methods: { methods: {
handleAvatarSuccess(res, file) {
console.log(res)
this.user.avatarSrc = res;
this.$message.success('上传头像成功!点击保存进行保存')
},
goBack() { goBack() {
window.history.go(-1); window.history.go(-1);
}, },
@ -154,12 +162,9 @@
}) })
.then(res => { .then(res => {
this.loading = false this.loading = false
if(res.data==="success") if (res.data === "success") {
{
location.reload() location.reload()
} } else {
else
{
this.info = '修改失败!'; this.info = '修改失败!';
} }
}) })
@ -168,6 +173,28 @@
}, },
changePass() { changePass() {
location.href = '/user/changePassword?oldPassword=' + this.oldPassword + '&newPassword=' + this.newPassword location.href = '/user/changePassword?oldPassword=' + this.oldPassword + '&newPassword=' + this.newPassword
},
uuid() {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
var uuid = s.join("");
return uuid;
}
},
computed: {
upData: function () {
let uuid = this.uuid();
return {
path: 'social/',
saveName: uuid
}
} }
} }
}; };

@ -73,6 +73,14 @@
<el-table-column prop="version" label="版本"></el-table-column> <el-table-column prop="version" label="版本"></el-table-column>
<el-table-column prop="gmtCreate" label="创建时间" width="250"></el-table-column> <el-table-column prop="gmtCreate" label="创建时间" width="250"></el-table-column>
<el-table-column prop="gmtModified" label="上次更改" width="250"></el-table-column> <el-table-column prop="gmtModified" label="上次更改" width="250"></el-table-column>
<el-table-column width="120">
<template #header>
给与权限
</template>
<template #default="scope">
<el-button size="mini" @click="setAdmin(scope.row.userId)" type="danger" v-if="scope.row.userClass!=='0'">设为管理员</el-button>
</template>
</el-table-column>
<el-table-column align="right" fixed="right" width="100"> <el-table-column align="right" fixed="right" width="100">
<template #header> <template #header>
<el-input v-model="keyWord" size="mini" placeholder="搜索用户"></el-input> <el-input v-model="keyWord" size="mini" placeholder="搜索用户"></el-input>
@ -166,6 +174,32 @@
} }
}) })
}) })
},
setAdmin(id){
this.$messageBox.confirm(
'确认要将该用户设置为管理员吗?',
'警告',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
}
)
.then(() => {
axios({
method: "get",
url: "/admin/setAdmin?userId="+id,
}).then(res=>{
if(res.data==="error")
{
this.$message.error('设置失败!')
}
else
{
this.$message.success('设置成功!')
}
})
})
} }
}, },
computed:{ computed:{

@ -5,7 +5,7 @@
<div class="navbar"> <div class="navbar">
<div class="hamburger-container"><i class="el-icon-s-grid"></i> 社会实践活动管理系统-{{title}}</div> <div class="hamburger-container"><i class="el-icon-s-grid"></i> 社会实践活动管理系统-{{title}}</div>
<div class="right-menu"> <div class="right-menu">
<el-avatar :src="user.avatarSrc" size="small"></el-avatar>&emsp; <el-avatar :src="user.avatarSrc" size="small" onclick="location.href='/userCenter'"></el-avatar>&emsp;
<shiro:hasRole name="student">欢迎学生:{{user.realName}}!</shiro:hasRole> <shiro:hasRole name="student">欢迎学生:{{user.realName}}!</shiro:hasRole>
<shiro:hasRole name="teacher">欢迎老师:{{user.realName}}!</shiro:hasRole> <shiro:hasRole name="teacher">欢迎老师:{{user.realName}}!</shiro:hasRole>
<shiro:hasRole name="admin">欢迎管理员:{{user.realName}}!</shiro:hasRole> <shiro:hasRole name="admin">欢迎管理员:{{user.realName}}!</shiro:hasRole>

@ -139,7 +139,11 @@
<h4>成员信息</h4> <h4>成员信息</h4>
<el-table :data="memberList" style="width: 100%" stripe> <el-table :data="memberList" style="width: 100%" stripe>
<el-table-column prop="username" label="用户名"></el-table-column> <el-table-column prop="username" label="用户名"></el-table-column>
<el-table-column prop="realName" label="姓名"></el-table-column> <el-table-column prop="realName" label="姓名">
<template #default="scope">
<el-link type="primary" :href="'/user?userId='+scope.row.userId">{{scope.row.realName}}</el-link>
</template>
</el-table-column>
<el-table-column align="right" label="加入状态"> <el-table-column align="right" label="加入状态">
<template #default="scope"> <template #default="scope">
<el-tag type="success" v-if="scope.row.isAccept">已通过</el-tag> <el-tag type="success" v-if="scope.row.isAccept">已通过</el-tag>

@ -116,7 +116,11 @@
</template> </template>
<el-table :data="item.memberList" style="width: 100%" stripe> <el-table :data="item.memberList" style="width: 100%" stripe>
<el-table-column prop="username" label="用户名"></el-table-column> <el-table-column prop="username" label="用户名"></el-table-column>
<el-table-column prop="realName" label="姓名"></el-table-column> <el-table-column prop="realName" label="姓名">
<template #default="scope">
<el-link type="primary" :href="'/user?userId='+scope.row.userId">{{scope.row.realName}}</el-link>
</template>
</el-table-column>
<el-table-column align="right" label="加入状态"> <el-table-column align="right" label="加入状态">
<template #default="scope"> <template #default="scope">
<el-tag type="success" v-if="scope.row.isAccept">已通过</el-tag> <el-tag type="success" v-if="scope.row.isAccept">已通过</el-tag>

Loading…
Cancel
Save