schangxiang@126.com
2024-08-16 65bd2dc1d4c1fb136af853c7ede93a338431be29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<template>
  <div>
    <x-card v-if="hasPerm('sysOnlineUser:page')">
      <div slot="content" class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="搜索">
                <a-input v-model="queryParam.searchValue" allow-clear placeholder="请输入账号或姓名" />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </x-card>
    <a-card :bordered="false">
      <!-- <a-table size="middle" :columns="columns" :dataSource="loadData" :pagination="false" :loading="loading">
           <span slot="lastLoginAddress" slot-scope="text">
             <ellipsis :length="20" tooltip>{{ text }}</ellipsis>
           </span>
           <span slot="lastLoginBrowser" slot-scope="text">
             <ellipsis :length="20" tooltip>{{ text }}</ellipsis>
           </span>
           <span slot="action" slot-scope="text, record">
             <a-popconfirm
               v-if="hasPerm('sysOnlineUser:forceExist')"
               placement="topRight"
               title="是否强制下线该用户?"
               @confirm="() => forceExist(record)">
               <a>强制下线</a>
             </a-popconfirm>
           </span>
         </a-table> -->
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :alert="true"
        :rowKey="record => record.id"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      >
        <span slot="lastLoginAddress" slot-scope="text">
          <ellipsis :length="20" tooltip>{{ text }}</ellipsis>
        </span>
        <span slot="lastLoginBrowser" slot-scope="text">
          <ellipsis :length="20" tooltip>{{ text }}</ellipsis>
        </span>
        <span slot="action" slot-scope="text, record">
          <a-popconfirm
            v-if="hasPerm('sysOnlineUser:forceExist')"
            placement="topRight"
            title="是否强制下线该用户?"
            @confirm="() => forceExist(record)"
          >
            <a>强制下线</a>
          </a-popconfirm>
        </span>
      </s-table>
    </a-card>
  </div>
</template>
<script>
import store from '@/store'
import { STable, Ellipsis, XCard } from '@/components'
import { sysOnlineUserForceExist, sysOnlineUserPage } from '@/api/modular/system/onlineUserManage'
export default {
  components: {
    XCard,
    STable,
    Ellipsis
  },
  data() {
    return {
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        // {
        //   title: '用户Id',
        //   dataIndex: 'userId'
        // },
        {
          title: '账号',
          dataIndex: 'account'
        },
        {
          title: '姓名',
          dataIndex: 'name'
        },
        {
          title: '登录IP',
          dataIndex: 'lastLoginIp'
        },
        {
          title: '登录时间',
          dataIndex: 'lastTime'
        },
        {
          title: '浏览器',
          dataIndex: 'lastLoginBrowser',
          scopedSlots: {
            customRender: 'lastLoginBrowser'
          }
        },
        {
          title: '操作系统',
          dataIndex: 'lastLoginOs'
        }
      ],
      // loading: true,
      loadData: parameter => {
        return sysOnlineUserPage(Object.assign(parameter, this.queryParam)).then(res => {
          return res.data
        })
      },
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  // 进页面加载
  created() {
    // 如果是超级管理员
    // eslint-disable-next-line eqeqeq
    if (store.getters.admintype == '1') {
      this.columns.push({
        title: '租户',
        dataIndex: 'tenantName'
      })
    }
 
    if (this.hasPerm('sysOnlineUser:forceExist')) {
      this.columns.push({
        title: '操作',
        width: '150px',
        dataIndex: 'action',
        scopedSlots: {
          customRender: 'action'
        }
      })
    }
  },
  mounted() {
    const that = this
    setTimeout(() => {
      that.$refs.table.refresh(true)
    }, 1000)
  },
  methods: {
    forceExist(record) {
      const that = this
      sysOnlineUserForceExist(record)
        .then(res => {
          if (res.success) {
            this.$message.success('强制下线成功')
            if (this.$store.getters.userInfo.id !== record.userId) {
              // 重新加载表格
              setTimeout(() => {
                that.$refs.table.refresh(false)
              }, 1000)
            }
          } else {
            this.$message.error('强制下线失败:' + res.message)
          }
        })
        .catch(err => {
          this.$message.error('强制下线错误:' + err.message)
        })
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    }
  }
}
</script>
<style lang="less">
.table-operator {
  margin-bottom: 18px;
}
 
button {
  margin-right: 8px;
}
</style>