Browse Source

h5端用户管理

qzyReal 3 years ago
parent
commit
563c248b6a

+ 0 - 3
app/App.vue

@@ -1,14 +1,11 @@
 <script>
 	export default {
 		onLaunch: function() {
-			console.log('App Launch')
 		},
 		onShow: function() {
-			console.log('show')
 			this.getAuth();
 		},
 		onHide: function() {
-			console.log('App Hide')
 		},
 		methods:{
 			getAuth(){

+ 13 - 0
app/apis/api.js

@@ -164,5 +164,18 @@ export default {
 	},
 	checkUserType() {
 		return ajax.get('/api/checkUserType')
+	},
+	getRoleList(data){
+		return ajax.get('/role/getCustomerRoleList',data)
+	},
+	getUserList(data){
+	 return ajax.get('/admin/getCustomerAdminList',data)	
+	},
+	addCustomerAdmin(data){
+		return ajax.postForm('/admin/addCustomerAdmin',data)
+	},
+	editCustomerAdmin(data){
+		return ajax.postForm('/admin/editCustomerAdmin',data)
 	}
+
 }

+ 21 - 0
app/pages.json

@@ -252,6 +252,27 @@
 		
 		},
 		{
+			"path": "pages/user/user-index",
+			"style": {
+				"navigationBarTitleText": ""
+			}
+		
+		},
+		{
+			"path": "pages/user/addUser",
+			"style": {
+				"navigationBarTitleText": ""
+			}
+		
+		},
+		{
+			"path": "pages/user/addUserSuccess",
+			"style": {
+				"navigationBarTitleText": ""
+			}
+		
+		},
+		{
 			"path": "pages/business-order/partner-business-item",
 			"style": {
 				"navigationBarTitleText": ""

+ 1 - 1
app/pages/customer-management/customer-info.vue

@@ -22,7 +22,7 @@
 					<u-input maxlength="11" v-model="form.phone" placeholder="输入电话号码" />
 				</view>
 			</view>
-			<view class="item">
+			<view class="item" v-if="form.type==='0'">
 				<view class="l">结算方式:</view>
 				<view class="r">
 					<radio-group @change="payChange">

+ 24 - 2
app/pages/index/index.vue

@@ -69,7 +69,15 @@
 					icon: '../../static/home-icon-03.png',
 					text: '我的业务',
 					url: '/pages/business-order/partner-business-item',
-				}],
+				},
+				{
+					id:'admin-list',
+					auth: true,
+					icon: '../../static/home-icon-04.png',
+					text: '用户管理',
+					url: '/pages/user/user-index',
+				},
+				],
 				customerList: [{
 						id: 'tb-costomer-account',
 						auth: true,
@@ -111,7 +119,14 @@
 						icon: '../../static/home-icon-05.png',
 						text: '放行记录',
 						url: '/pages/inout-record/inout-record',
-					}
+					},
+					{
+						id:'admin-list',
+						auth: true,
+						icon: '../../static/home-icon-04.png',
+						text: '用户管理',
+						url: '/pages/user/user-index',
+					},
 				],
 				adminList: [{
 						id: 'tb-business-add',
@@ -135,6 +150,13 @@
 						text: '放行记录',
 						url: '/pages/inout-record/inout-record',
 					},
+					{
+						id:'admin-list',
+						auth: true,
+						icon: '../../static/home-icon-04.png',
+						text: '用户管理',
+						url: '/pages/user/user-index',
+					},
 				]
 			}
 		},

+ 184 - 0
app/pages/user/addUser.vue

@@ -0,0 +1,184 @@
+<template>
+	<view>
+		<view class="box">
+			<view class="top">
+				<text class="title" v-if="!form.id">添加用户</text>
+				<text class="title" v-else>编辑用户</text>
+			</view>
+			<view class="item">
+				<view class="l"><text style="color: red;">*</text>用户名:</view>
+				<view class="r">
+					<u-input placeholder="用户名" v-model="form.name">
+					</u-input>
+				</view>
+			</view>
+			<view class="item" v-if="!form.id">
+				<view class="l"><text style="color: red;">*</text>密码:</view>
+				<view class="r">
+					<u-input placeholder="密码" type="password" v-model="form.password">
+					</u-input>
+				</view>
+			</view>
+			<view class="item" v-if="!form.id">
+				<view class="l"><text style="color: red;">*</text>再输一次:</view>
+				<view class="r">
+					<u-input placeholder="再输一次" type="password" v-model="form.againPassword">
+					</u-input>
+				</view>
+			</view>
+			<view class="item">
+				<view class="l"><text style="color: red;">*</text>角色:</view>
+			</view>
+			<view class="item">
+				<view class="l">
+					<u-checkbox-group v-model="roleList">
+						<u-checkbox :customStyle="{marginBottom: '10px',marginLeft:'10px'}"
+							v-for="(item, index) in checkboxList" :key="index" :label="item.name" :name="item.id">
+						</u-checkbox>
+					</u-checkbox-group>
+				</view>
+			</view>
+			<view class="item" v-show="form.id">
+				<view class="l">
+					状态:
+				</view>
+				<view class="r">
+					<radio-group @change="statusChange">
+						<label class="radio">
+							<radio value="1"  :checked="form.status==1" />可用
+						</label>
+						<label class="radio" style="margin-left: 20rpx;">
+							<radio value="2"  :checked="form.status==2"/>禁用
+						</label>
+					</radio-group>
+				</view>
+			</view>
+
+		</view>
+		<u-button type="primary" text="确定" @click="saveFn"></u-button>
+		<!-- ---------------------------------------------------------- -->
+		<view class="bottom-safety"></view>
+
+	</view>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				roleList: [],
+				checkboxList: [],
+				form: {
+					id: '',
+					status: 1,
+					customerId: '',
+					name: '',
+					password: '',
+					againPassword: '',
+				},
+				perList: []
+			}
+		},
+		onLoad(options) {
+			this.form.id = options.id;
+			this.form.name = options.name;
+			this.form.status = options.status;
+			this.roleList = options.roleId ? options.roleId.split(',').map(id => parseInt(id)) : [];
+			console.log(this.roleList)
+			let info = uni.getStorageSync('userInfo');
+			let customerId = info.customerId;
+			this.form.customerId = customerId;
+			this.getRoleList();
+		},
+		onShow() {
+			this.perList = uni.getStorageSync('perList');
+		},
+		onBackPress() {
+			this.$common.to('/pages/user/user-index');
+			return true;
+		},
+		methods: {
+			statusChange(e) {
+				this.form.status = e.detail.value
+			},
+			getRoleList() {
+				this.$api.getRoleList({
+					customerId: this.form.customerId
+				}).then(resp => {
+					this.checkboxList = resp.data;
+				})
+			},
+			saveFn() {
+				if (!this.form.name) {
+					this.$common.toast('请填写用户名');
+					return;
+				}
+				if (!this.form.password &&!this.form.id) {
+					this.$common.toast('请填写密码');
+					return;
+				}
+				if (this.form.password != this.form.againPassword) {
+					this.$common.toast('两次密码不一致');
+					return;
+				}
+				if (this.roleList.length == 0) {
+					this.$common.toast('请选择用户角色');
+					return;
+				}
+				this.form.roleId = this.roleList.join(',');
+				if (this.form.id) {
+					this.$api.editCustomerAdmin(this.$common.removeNull(this.form)).then(resp => {
+						if (resp.code == 200) {
+							this.$common.to('/pages/user/addUserSuccess')
+						}
+					})
+				} else {
+					this.$api.addCustomerAdmin(this.$common.removeNull(this.form)).then(resp => {
+						if (resp.code == 200) {
+							this.$common.to('/pages/user/addUserSuccess')
+						}
+					})
+				}
+			},
+		},
+
+	}
+</script>
+
+<style lang="scss">
+	page {
+		background-color: #fff;
+	}
+
+	.hs-item {
+		text-align: center;
+	}
+
+	.item-line {
+		color: #a2a2a2;
+		padding: 5px 0 10px 29px;
+		border-bottom: 1px solid #E5E5E5;
+	}
+
+	.hj {
+		padding: 50rpx;
+		font-size: 40rpx;
+		color: red;
+		font-weight: bold;
+	}
+
+	.save-btn {
+		background-color: #ff4200;
+		height: 88rpx;
+		display: flex;
+		justify-content: center;
+		align-items: center;
+		margin: 60rpx;
+		color: #fff;
+		font-size: 30rpx;
+		font-weight: bold;
+		border-radius: 10rpx;
+	}
+
+	@import '@/common/common.scss'
+</style>

+ 57 - 0
app/pages/user/addUserSuccess.vue

@@ -0,0 +1,57 @@
+<template>
+	<view class="box">
+		<u-icon name="checkmark-circle-fill" color="#07c160" size="200"></u-icon>
+		<text class="text">提交成功!</text>
+		<view class="count-down-box">
+			<view @click="goback">返回</view>
+		</view>
+	</view>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				timestamp: 3,
+			}
+		},
+		onBackPress() {
+			this.goback();
+			return true;
+		},
+		methods: {
+			goback() {
+				this.$common.to('/pages/user/user-index');
+			}
+		}
+	}
+</script>
+
+<style lang="scss">
+	page {
+		background-color: #fff;
+	}
+
+	.box {
+		display: flex;
+		flex: 1;
+		align-items: center;
+		justify-content: center;
+		flex-direction: column;
+		padding: 100rpx 0;
+
+		.text {
+			color: #191919;
+			font-size: 36rpx;
+			font-weight: bold;
+			margin-top: 40rpx;
+		}
+
+		.count-down-box {
+			display: flex;
+			align-items: center;
+			justify-content: center;
+			margin-top: 30rpx;
+		}
+	}
+</style>

+ 66 - 0
app/pages/user/user-index.vue

@@ -0,0 +1,66 @@
+<template>
+	<view>
+		<view class="box">
+			<view class="top">
+				<text class="title">用户管理</text>
+				<text class="add" @click="addUser">+添加
+				</text>
+			</view>
+		</view>
+		<view>
+			<u-cell-group>
+				<u-cell :isLink="true" arrow-direction="right" @click="toUserFn(item)"
+				:value="item.roleName"
+				 v-for="(item,index) in userList">
+					<u-icon name="account" slot="icon" size="30"></u-icon>
+					<text slot="title" style="font-size: 40rpx;">{{item.name}}</text>
+				</u-cell>
+			</u-cell-group>
+		</view>
+	</view>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				customerId: '',
+				userList:[]
+			}
+		},
+		onShow() {
+			let info = uni.getStorageSync('userInfo');
+			this.customerId = info.customerId;
+			this.getUserList();
+		},
+		onBackPress() {
+			this.$common.to('/');
+			return true;
+		},
+		methods: {
+			getUserList() {
+				this.$api.getUserList({customerId:this.customerId}).then(resp=>{
+					this.userList=resp.data;
+				})
+			},
+			toUserFn(data){
+				this.$common.to('/pages/user/addUser?id='+data.id+'&name='+data.name+'&roleId='+data.roleId+'&status='+data.status)
+			},
+			addUser() {
+				this.$common.to('/pages/user/addUser')
+			}
+		}
+	}
+</script>
+<style lang="scss">
+	.add {
+		position: absolute;
+		right: 40rpx;
+		top: -60rpx;
+		z-index: 999;
+		font-size: 40rpx;
+		color: white;
+	}
+
+	@import '@/common/common.scss'
+</style>

+ 3 - 3
app/utils/request.js

@@ -1,6 +1,6 @@
-// const server = 'http://127.0.0.1:8099/pro';
-// const server = 'http://47.101.143.145/pro';
-const server = 'https://dxkaa1.bgigc.com/pro';
+const server = 'http://127.0.0.1:8099/pro';
+// const server = 'http://pco.aseanbusiness.cn/pro';
+//const server = 'https://dxkaa1.bgigc.com/pro';
 
 import common from '../common/js/common.js';
 

+ 2 - 2
sp-admin/static/sa.js

@@ -14,7 +14,7 @@ var sa = {
 	}
 	// 服务器测试环境
 	var cfg_test = {
-		api_url: 'http://47.101.143.145/pro',
+		api_url: 'http://pco.aseanbusiness.cn/pro',
 		web_url: 'http://www.baidu.com'
 	}
 	// 正式生产环境
@@ -22,7 +22,7 @@ var sa = {
 		api_url: 'https://dxkaa1.bgigc.com/pro',
 		web_url: 'http://www.baidu.com'
 	}
-	sa.cfg = cfg_dev; // 最终环境 , 上线前请选择正确的环境
+	sa.cfg = cfg_test; // 最终环境 , 上线前请选择正确的环境
 })();
 
 

+ 1 - 1
sp-server/app.pid

@@ -1 +1 @@
-28988
+29408

+ 5 - 0
sp-server/src/main/java/com/pj/project4sp/admin/SpAdminController.java

@@ -146,6 +146,11 @@ public class SpAdminController {
         spAdminService.add(spAdmin);
         return AjaxJson.getSuccess();
     }
+    @RequestMapping("editCustomerAdmin")
+    AjaxJson editCustomerAdmin(SpAdmin spAdmin) {
+        spAdminService.editCustomerAdmin(spAdmin);
+        return AjaxJson.getSuccess();
+    }
 
     @RequestMapping("addPartnerAdmin")
     AjaxJson addPartnerAdmin(SpAdmin spAdmin) {

+ 2 - 0
sp-server/src/main/java/com/pj/project4sp/admin/SpAdminMapper.java

@@ -78,4 +78,6 @@ public interface SpAdminMapper {
     List<SpAdmin> findByCustomerId(@Param("customerId")String customerId);
 
 	void updateOpenid(SpAdmin admin);
+
+	void updateAdmin(SpAdmin db);
 }

+ 3 - 0
sp-server/src/main/java/com/pj/project4sp/admin/SpAdminMapper.xml

@@ -18,6 +18,9 @@
     <update id="updateOpenid">
 			update sp_admin set openid=#{openid} where id=#{id}
 	</update>
+    <update id="updateAdmin">
+        update sp_admin set name=#{name},role_id=#{roleId},status=#{status} where id=#{id}
+    </update>
 
 
     <!-- 删 -->

+ 49 - 38
sp-server/src/main/java/com/pj/project4sp/admin/SpAdminService.java

@@ -1,5 +1,6 @@
 package com.pj.project4sp.admin;
 
+import com.pj.current.config.SystemObject;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
@@ -14,49 +15,51 @@ import java.util.List;
 
 /**
  * Service: admin管理员
- * @author kong
  *
+ * @author kong
  */
 @Service
 public class SpAdminService {
 
-	
-	@Autowired
-	SpAdminMapper spAdminMapper;
-	
-	@Autowired
-	SpAdminPasswordService spAdminPasswordService;
-	
-	
-	/**
-	 * 管理员添加一个管理员 
-	 * @param admin
-	 * @return
-	 */
-	@Transactional(rollbackFor = Exception.class, propagation=Propagation.REQUIRED)	
-	public long add(SpAdmin admin) {
-		// 检查姓名是否合法
-		SpAdminUtil.checkAdmin(admin);
-		
-		// 创建人,为当前账号  
-		admin.setCreateByAid(StpUtil.getLoginIdAsLong());	
-		// 开始添加
-		spAdminMapper.add(admin);	
-		// 获取主键
-		long id = SP.publicMapper.getPrimarykey();
-		// 更改密码(md5与明文)
-		spAdminPasswordService.updatePassword(id, admin.getPassword2());	
-		
-		// 返回主键 
-		return id;
-	}
+
+    @Autowired
+    SpAdminMapper spAdminMapper;
+
+    @Autowired
+    SpAdminPasswordService spAdminPasswordService;
+
+
+    /**
+     * 管理员添加一个管理员
+     *
+     * @param admin
+     * @return
+     */
+    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
+    public long add(SpAdmin admin) {
+        // 检查姓名是否合法
+        SpAdminUtil.checkAdmin(admin);
+
+        // 创建人,为当前账号
+        admin.setCreateByAid(StpUtil.getLoginIdAsLong());
+        // 开始添加
+        spAdminMapper.add(admin);
+        // 获取主键
+        long id = SP.publicMapper.getPrimarykey();
+        // 更改密码(md5与明文)
+        spAdminPasswordService.updatePassword(id, admin.getPassword2());
+
+        // 返回主键
+        return id;
+    }
 
     /**
      * h5企业注册时添加一个账号
+     *
      * @param admin
      * @return
      */
-    @Transactional(rollbackFor = Exception.class, propagation=Propagation.REQUIRED)
+    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
     public long addWhenRegister(SpAdmin admin) {
         // 检查姓名是否合法
         SpAdminUtil.checkAdmin(admin);
@@ -73,11 +76,19 @@ public class SpAdminService {
     }
 
 
-	public SpAdmin findByOpenid(String openid) {
-		return spAdminMapper.findByOpenid(openid);
-	}
+    public SpAdmin findByOpenid(String openid) {
+        return spAdminMapper.findByOpenid(openid);
+    }
+
+    public List<SpAdmin> findByCustomerId(String businessCustomerId) {
+        return spAdminMapper.findByCustomerId(businessCustomerId);
+    }
 
-	public List<SpAdmin> findByCustomerId(String businessCustomerId) {
-		return spAdminMapper.findByCustomerId(businessCustomerId);
-	}
+    public void editCustomerAdmin(SpAdmin spAdmin) {
+        SpAdmin db = spAdminMapper.getById(spAdmin.getId());
+        db.setName(spAdmin.getName());
+        db.setRoleId(spAdmin.getRoleId());
+        db.setStatus(spAdmin.getStatus());
+        spAdminMapper.updateAdmin(db);
+    }
 }

+ 2 - 2
sp-server/src/main/java/com/pj/project4sp/admin/SpAdminUtil.java

@@ -39,7 +39,7 @@ public class SpAdminUtil {
 	 * @param name
 	 * @return
 	 */
-	public static boolean checkName(long adminId, String name) {
+	public static boolean checkName(Long adminId, String name) {
 		if(NbUtil.isNull(name)) {
 			throw AjaxError.get("账号名称不能为空");
 		}
@@ -51,7 +51,7 @@ public class SpAdminUtil {
 //		}
 		// 如果能查出来数据,而且不是本人,则代表与已有数据重复
 		SpAdmin a2 = spAdminMapper.getByName(name);
-		if(a2 != null && a2.getId() != adminId) {	
+		if(a2 != null && !a2.getId().equals(adminId)) {
 			throw AjaxError.get("账号名称已有账号使用,请更换");
 		} 
 		return true;

+ 3 - 2
sp-server/src/main/java/com/pj/project4sp/admin4password/SpAdminPasswordService.java

@@ -20,8 +20,9 @@ public class SpAdminPasswordService {
 	/** 修改一个admin的密码为  */
 	@Transactional(rollbackFor = Exception.class, propagation=Propagation.REQUIRED)	
 	public int updatePassword(long adminId, String password) {
-		// 更改密码 
-		SP.publicMapper.updateColumnById("sp_admin", "password", SystemObject.getPasswordMd5(adminId, password), adminId);
+		// 更改密码
+		String dePassword= SystemObject.getPasswordMd5(adminId, password);
+		SP.publicMapper.updateColumnById("sp_admin", "password",dePassword, adminId);
 		if(SystemObject.config.getIsPw()) {
 			// 明文密码 
 			SP.publicMapper.updateColumnById("sp_admin", "pw", password, adminId);