index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <div>
  3. <Card :bordered="false" dis-hover class="ivu-mt">
  4. <Form
  5. ref="formValidate"
  6. :model="formValidate"
  7. :label-width="labelWidth"
  8. :label-position="labelPosition"
  9. @submit.native.prevent
  10. >
  11. <Row type="flex" :gutter="24">
  12. <Col v-bind="grid">
  13. <FormItem label="状态:" label-for="status1">
  14. <Select v-model="status" placeholder="请选择" @on-change="userSearchs" clearable>
  15. <Option value="all">全部</Option>
  16. <Option value="1">开启</Option>
  17. <Option value="0">关闭</Option>
  18. </Select>
  19. </FormItem>
  20. </Col>
  21. <Col v-bind="grid">
  22. <FormItem label="搜索:" label-for="status2">
  23. <Input
  24. search
  25. enter-button
  26. placeholder="请输入姓名或者账号"
  27. v-model="formValidate.name"
  28. @on-search="userSearchs"
  29. />
  30. </FormItem>
  31. </Col>
  32. </Row>
  33. <Row type="flex">
  34. <Col v-bind="grid">
  35. <Button v-auth="['setting-system_admin-add']" type="primary" @click="add" icon="md-add">添加管理员</Button>
  36. </Col>
  37. </Row>
  38. </Form>
  39. <Table
  40. :columns="columns1"
  41. :data="list"
  42. class="mt25"
  43. no-userFrom-text="暂无数据"
  44. no-filtered-userFrom-text="暂无筛选结果"
  45. :loading="loading"
  46. highlight-row
  47. >
  48. <template slot-scope="{ row, index }" slot="roles">
  49. <div v-if="row.roles.length !== 0">
  50. <Tag color="blue" v-for="(item, index) in row.roles.split(',')" :key="index" v-text="item"></Tag>
  51. </div>
  52. </template>
  53. <template slot-scope="{ row, index }" slot="status">
  54. <i-switch
  55. v-model="row.status"
  56. :value="row.status"
  57. :true-value="1"
  58. :false-value="0"
  59. @on-change="onchangeIsShow(row)"
  60. size="large"
  61. >
  62. <span slot="open">开启</span>
  63. <span slot="close">关闭</span>
  64. </i-switch>
  65. </template>
  66. <template slot-scope="{ row, index }" slot="action">
  67. <a @click="edit(row)">编辑</a>
  68. <Divider type="vertical" />
  69. <a @click="del(row, '删除管理员', index)">删除</a>
  70. </template>
  71. </Table>
  72. <div class="acea-row row-right page">
  73. <Page
  74. :total="total"
  75. :current="formValidate.page"
  76. show-elevator
  77. show-total
  78. @on-change="pageChange"
  79. :page-size="formValidate.limit"
  80. />
  81. </div>
  82. </Card>
  83. <!-- 添加 编辑 -->
  84. <admin-from :FromData="FromData" ref="adminfrom" @submitFail="submitFail"></admin-from>
  85. </div>
  86. </template>
  87. <script>
  88. import { mapState } from 'vuex';
  89. import { adminListApi, adminFromApi, adminEditFromApi, setShowApi } from '@/api/systemAdmin';
  90. import adminFrom from '../../../components/from/from';
  91. export default {
  92. name: 'systemAdmin',
  93. components: { adminFrom },
  94. data() {
  95. return {
  96. grid: {
  97. xl: 7,
  98. lg: 7,
  99. md: 12,
  100. sm: 24,
  101. xs: 24,
  102. },
  103. total: 0,
  104. loading: false,
  105. roleData: {
  106. status1: '',
  107. },
  108. formValidate: {
  109. roles: '',
  110. status: '',
  111. name: '',
  112. page: 1, // 当前页
  113. limit: 20, // 每页显示条数
  114. },
  115. status: '',
  116. list: [],
  117. columns1: [
  118. {
  119. title: '姓名',
  120. key: 'real_name',
  121. minWidth: 120,
  122. },
  123. {
  124. title: '账号',
  125. key: 'account',
  126. minWidth: 150,
  127. },
  128. {
  129. title: '身份',
  130. slot: 'roles',
  131. minWidth: 250,
  132. },
  133. {
  134. title: '最后一次登录时间',
  135. key: '_last_time',
  136. minWidth: 180,
  137. },
  138. {
  139. title: '最后一次登录ip',
  140. key: 'last_ip',
  141. minWidth: 180,
  142. },
  143. {
  144. title: '开启',
  145. slot: 'status',
  146. minWidth: 90,
  147. },
  148. {
  149. title: '操作',
  150. key: 'action',
  151. slot: 'action',
  152. fixed: 'right',
  153. minWidth: 120,
  154. },
  155. ],
  156. FromData: null,
  157. modalTitleSs: '',
  158. ids: Number,
  159. };
  160. },
  161. computed: {
  162. ...mapState('media', ['isMobile']),
  163. labelWidth() {
  164. return this.isMobile ? undefined : 50;
  165. },
  166. labelPosition() {
  167. return this.isMobile ? 'top' : 'left';
  168. },
  169. },
  170. created() {
  171. this.getList();
  172. },
  173. methods: {
  174. // 修改是否开启
  175. onchangeIsShow(row) {
  176. let data = {
  177. id: row.id,
  178. status: row.status,
  179. };
  180. setShowApi(data)
  181. .then(async (res) => {
  182. this.$Message.success(res.msg);
  183. })
  184. .catch((res) => {
  185. this.$Message.error(res.msg);
  186. });
  187. },
  188. // 请求列表
  189. submitFail() {
  190. this.getList();
  191. },
  192. // 列表
  193. getList() {
  194. this.loading = true;
  195. this.formValidate.roles = this.formValidate.roles || '';
  196. adminListApi(this.formValidate)
  197. .then(async (res) => {
  198. this.total = res.data.count;
  199. this.list = res.data.list;
  200. this.loading = false;
  201. })
  202. .catch((res) => {
  203. this.loading = false;
  204. this.$Message.error(res.msg);
  205. });
  206. },
  207. pageChange(index) {
  208. this.formValidate.page = index;
  209. this.getList();
  210. },
  211. // 添加表单
  212. add() {
  213. adminFromApi()
  214. .then(async (res) => {
  215. this.FromData = res.data;
  216. this.$refs.adminfrom.modals = true;
  217. })
  218. .catch((res) => {
  219. this.$Message.error(res.msg);
  220. });
  221. },
  222. // 编辑
  223. edit(row) {
  224. adminEditFromApi(row.id)
  225. .then(async (res) => {
  226. if (res.data.status === false) {
  227. return this.$authLapse(res.data);
  228. }
  229. this.FromData = res.data;
  230. this.$refs.adminfrom.modals = true;
  231. })
  232. .catch((res) => {
  233. this.$Message.error(res.msg);
  234. });
  235. },
  236. // 删除
  237. del(row, tit, num) {
  238. let delfromData = {
  239. title: tit,
  240. num: num,
  241. url: `setting/admin/${row.id}`,
  242. method: 'DELETE',
  243. ids: '',
  244. };
  245. this.$modalSure(delfromData)
  246. .then((res) => {
  247. this.$Message.success(res.msg);
  248. this.list.splice(num, 1);
  249. })
  250. .catch((res) => {
  251. this.$Message.error(res.msg);
  252. });
  253. },
  254. // 表格搜索
  255. userSearchs() {
  256. this.formValidate.status = this.status === 'all' ? '' : this.status;
  257. this.formValidate.page = 1;
  258. this.list = [];
  259. this.getList();
  260. },
  261. },
  262. };
  263. </script>
  264. <style scoped></style>