index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <div class="template">
  3. <div class="top">
  4. <div class="location">数据管理 / <span>用户管理</span></div>
  5. </div>
  6. <div class="conten">
  7. <div class="search">
  8. <div class="txt">筛选查询</div>
  9. <div class="row">
  10. <span>用户名:</span>
  11. <el-input v-model="form.searchKey" placeholder="请输入"></el-input>
  12. </div>
  13. <div class="btn" @click="search">搜 索</div>
  14. </div>
  15. <!-- 表格 -->
  16. <div class="table">
  17. <div class="title">
  18. <div class="txt">用户列表</div>
  19. <div class="addBtn" @click="addUser">+ 新增</div>
  20. </div>
  21. <el-table
  22. :header-cell-style="{ background: '#e3e6e9' }"
  23. :data="tableData"
  24. stripe
  25. style="width: 100%"
  26. >
  27. <el-table-column label="序号" width="80">
  28. <template slot-scope="scope">
  29. {{ scope.$index + (form.pageNum - 1) * form.pageSize + 1 }}
  30. </template>
  31. </el-table-column>
  32. <el-table-column prop="realName" label="用户名"></el-table-column>
  33. <el-table-column prop="roleName" label="用户角色"></el-table-column>
  34. <el-table-column prop="dept" label="部门"> </el-table-column>
  35. <el-table-column prop="createTime" label="创建时间"> </el-table-column>
  36. <el-table-column prop="remark" label="备注"> </el-table-column>
  37. <el-table-column label="操作">
  38. <template #default='{row}'>
  39. <el-button type="text" @click="editUser(row.id)">编 辑</el-button>
  40. <el-button type="text" @click="delUserById(row.id)" v-if="row.roleId!==1">删 除</el-button>
  41. <el-button type="text" @click="resetPass(row.id)" v-if="row.roleId!==1">重置密码</el-button>
  42. </template>
  43. </el-table-column>
  44. </el-table>
  45. </div>
  46. <!-- 分页 -->
  47. <div class="paging">
  48. <el-pagination layout="prev, pager, next,sizes,jumper"
  49. :total="total"
  50. :current-page='form.pageNum'
  51. @current-change="currentChange"
  52. @size-change="sizeChange"
  53. >
  54. </el-pagination>
  55. </div>
  56. </div>
  57. <!-- 点击新增的弹窗 -->
  58. <Tab4Add :isShow.sync="isShow" @update='getUserList(form)' ref="myUser"/>
  59. </div>
  60. </template>
  61. <script>
  62. import Tab4Add from './tab4_add.vue'
  63. import { getUserList, delUserById, resetPass } from '@/apis/tab4'
  64. export default {
  65. name: 'tab3',
  66. components: { Tab4Add },
  67. data () {
  68. // 这里存放数据
  69. return {
  70. isShow: false,
  71. total: 0,
  72. form: {
  73. pageNum: 1,
  74. pageSize: 10,
  75. searchKey: ''
  76. },
  77. tableData: []
  78. }
  79. },
  80. // 监听属性 类似于data概念
  81. computed: {},
  82. // 监控data中的数据变化
  83. watch: {},
  84. // 方法集合
  85. methods: {
  86. // 点击搜索
  87. search () {
  88. this.form.pageNum = 1
  89. this.getUserList(this.form)
  90. },
  91. // 点击重置密码
  92. resetPass (id) {
  93. this.$confirm('确定重置密码吗?', '提示', {
  94. confirmButtonText: '确定',
  95. cancelButtonText: '取消',
  96. type: 'warning'
  97. })
  98. .then(async () => {
  99. const res = await resetPass(id)
  100. if (res.code === 0) {
  101. this.getUserList(this.form)
  102. this.$message.success('重置密码成功!')
  103. }
  104. console.log(999, res)
  105. })
  106. .catch(() => {
  107. this.$message.info('已取消重置!')
  108. })
  109. },
  110. // 点击删除
  111. delUserById (id) {
  112. this.$confirm('确定删除吗?', '提示', {
  113. confirmButtonText: '确定',
  114. cancelButtonText: '取消',
  115. type: 'warning'
  116. })
  117. .then(async () => {
  118. const res = await delUserById(id)
  119. if (res.code === 0) {
  120. this.getUserList(this.form)
  121. this.$message.success('删除成功!')
  122. }
  123. console.log(999, res)
  124. })
  125. .catch(() => {
  126. this.$message.info('已取消删除!')
  127. })
  128. },
  129. // 点击编辑
  130. editUser (id) {
  131. this.$refs.myUser.getUserDetailById(id)
  132. this.isShow = true
  133. },
  134. // 点击新增
  135. addUser () {
  136. this.isShow = true
  137. },
  138. // 封装获取文物列表方法
  139. async getUserList (data) {
  140. const res = await getUserList(data)
  141. this.tableData = res.data.list
  142. this.total = res.data.total
  143. },
  144. // 分页器方法
  145. currentChange (val) {
  146. // console.log('当前页改变了', val)
  147. this.form.pageNum = val
  148. this.getUserList(this.form)
  149. },
  150. sizeChange (val) {
  151. // console.log('条数改变了', val)
  152. this.form.pageNum = 1
  153. this.form.pageSize = val
  154. this.getUserList(this.form)
  155. }
  156. },
  157. // 生命周期 - 创建完成(可以访问当前this实例)
  158. created () {
  159. this.getUserList(this.form)
  160. },
  161. // 生命周期 - 挂载完成(可以访问DOM元素)
  162. mounted () {},
  163. beforeCreate () {}, // 生命周期 - 创建之前
  164. beforeMount () {}, // 生命周期 - 挂载之前
  165. beforeUpdate () {}, // 生命周期 - 更新之前
  166. updated () {}, // 生命周期 - 更新之后
  167. beforeDestroy () {}, // 生命周期 - 销毁之前
  168. destroyed () {}, // 生命周期 - 销毁完成
  169. activated () {} // 如果页面有keep-alive缓存功能,这个函数会触发
  170. }
  171. </script>
  172. <style lang='less' scoped>
  173. .template {
  174. /deep/.el-table__body-wrapper {
  175. max-height: 450px;
  176. overflow-y: auto;
  177. }
  178. /deep/.cell {
  179. padding-left: 20px !important;
  180. }
  181. /deep/.el-table__row .el-table__cell {
  182. padding: 0 !important;
  183. }
  184. /deep/.el-pager li {
  185. background: transparent !important;
  186. }
  187. /deep/.btn-prev {
  188. background: transparent !important;
  189. }
  190. /deep/.btn-next {
  191. background: transparent !important;
  192. }
  193. padding: 0px 30px;
  194. .top {
  195. display: flex;
  196. align-items: center;
  197. height: 58px;
  198. width: 100%;
  199. .location {
  200. font-size: 22px;
  201. color: #999;
  202. & > span {
  203. color: black;
  204. }
  205. }
  206. }
  207. .conten {
  208. position: relative;
  209. width: 100%;
  210. height: 780px;
  211. .txt {
  212. font-weight: 700;
  213. height: 40px;
  214. border-bottom: 2px solid #A3A2A9 ;
  215. }
  216. .search {
  217. position: relative;
  218. padding: 15px 20px 0;
  219. border-radius: 5px;
  220. box-shadow: 0px 0px 5px 0px;
  221. height: 130px;
  222. background-color: #d8dadc;
  223. .row {
  224. width: 100%;
  225. margin-top: 20px;
  226. display: flex;
  227. align-items: center;
  228. & > div {
  229. margin-right: 50px;
  230. width: 20%;
  231. display: flex;
  232. align-items: center;
  233. }
  234. }
  235. .btn {
  236. border-radius: 5px;
  237. display: flex;
  238. justify-content: center;
  239. align-items: center;
  240. color: #fff;
  241. cursor: pointer;
  242. width: 170px;
  243. height: 40px;
  244. background-color: #dc3545;
  245. position: absolute;
  246. right: 50px;
  247. top: 75px;
  248. }
  249. }
  250. .table {
  251. margin-top: 25px;
  252. .title {
  253. position: relative;
  254. padding: 15px 20px 0;
  255. background-color: #e3e6e9;
  256. .addBtn {
  257. cursor: pointer;
  258. display: flex;
  259. justify-content: center;
  260. align-items: center;
  261. color: #fff;
  262. width: 80px;
  263. height: 30px;
  264. background-color: #dc3545;
  265. border-radius: 12px;
  266. z-index: 999;
  267. position: absolute;
  268. right: 56px;
  269. top: 62px;
  270. }
  271. }
  272. }
  273. .paging {
  274. position: absolute;
  275. bottom: 15px;
  276. right: 50px;
  277. }
  278. }
  279. }
  280. </style>