admin-add.html 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>添加管理员</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <!-- 所有的 css & js 资源 -->
  8. <link rel="stylesheet" href="https://unpkg.com/element-ui@2.13.0/lib/theme-chalk/index.css">
  9. <link rel="stylesheet" href="../../static/sa.css">
  10. <script src="../../static/kj/vue.min.js"></script>
  11. <script src="../../static/kj/element-ui/index.js"></script>
  12. <script src="../../static/kj/httpVueLoader.js"></script>
  13. <script src="../../static/kj/jquery.min.js"></script>
  14. <script src="../../static/kj/layer/layer.js"></script>
  15. <script src="../../static/sa.js"></script>
  16. <script src="../../static/kj/upload-util.js"></script>
  17. </head>
  18. <body>
  19. <div class="vue-box" style="display: none;" :style="'display: block;'">
  20. <!-- 参数栏 -->
  21. <div class="c-panel">
  22. <h4 class="c-title">添加一个管理员</h4>
  23. <el-form>
  24. <!-- 防止密码框被填充 -->
  25. <div style="height: 0px; overflow: hidden;">
  26. <el-input></el-input>
  27. <el-input type="password"></el-input>
  28. </div>
  29. <!-- 表单 -->
  30. <sa-item type="img" name="头像" v-model="m.avatar" br></sa-item>
  31. <sa-item type="text" name="名称" v-model="m.name" br></sa-item>
  32. <sa-item type="password" name="密码" v-model="m.password" br></sa-item>
  33. <sa-item name="角色" br>
  34. <el-select v-model="m.roleId">
  35. <el-option label="请选择" :value="0" disabled></el-option>
  36. <el-option v-for="role in roleList" :key="role.id" :label="role.name" :value="role.id"></el-option>
  37. </el-select>
  38. </sa-item>
  39. <sa-item name="" br>
  40. <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
  41. </sa-item>
  42. </el-form>
  43. </div>
  44. </div>
  45. <script type="text/javascript">
  46. function crateModel() {
  47. return {
  48. id: 0,
  49. name: '',
  50. avatar: '',
  51. password: '',
  52. roleId: 0
  53. }
  54. }
  55. </script>
  56. <script>
  57. var app = new Vue({
  58. components: {
  59. "sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue')
  60. },
  61. el: '.vue-box',
  62. data: {
  63. sa: sa, // 超级对象
  64. m: crateModel(),
  65. roleList: []
  66. },
  67. methods: {
  68. // 修改
  69. ok: function(){
  70. // 表单校验
  71. let m = this.m;
  72. sa.checkNull(m.avatar, '请选择一个头像');
  73. sa.checkNull(m.name, '请输入昵称');
  74. sa.checkNull(m.password, '请输入密码');
  75. sa.checkNull(m.roleId, '请选择角色');
  76. // 添加
  77. sa.ajax('/sp-admin/admin/add', m, function(res){
  78. sa.alert('添加成功, 账号id为:' + res.data, function(){
  79. this.m = crateModel();
  80. // location.reload();
  81. }.bind(this));
  82. }.bind(this));
  83. }
  84. },
  85. mounted: function(){
  86. // 加载角色
  87. sa.ajax('/sp-admin/role/getList', function(res){
  88. this.roleList = res.data; // 数据
  89. }.bind(this), {msg: null});
  90. }
  91. })
  92. </script>
  93. </body>
  94. </html>