<!--
 * @Descripttion: 
 * @version: 
 * @Author: fzq
 * @Date: 2022-11-25 09:51:46
 * @LastEditors: fzq
 * @LastEditTime: 2023-02-08 16:18:20
-->
<template>
	<el-card shadow="never" class="aui-card--fill">
		<div class="mod-sys__log-login">
			<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()"  class="blueTip" size="small">
				<el-form-item>
					{{ $t('logLogin.creatorName') }}
				</el-form-item>
				<el-form-item>
					<el-input v-model="dataForm.creatorName" :placeholder="$t('logLogin.creatorName')" clearable></el-input>
				</el-form-item>
				<el-form-item>
		        	{{ $t('logLogin.status') }}
				</el-form-item>
				<el-form-item>
					<el-select v-model="dataForm.status" :placeholder="$t('logLogin.status')" clearable>
						<el-option :label="$t('logLogin.status0')" :value="0"></el-option>
						<el-option :label="$t('logLogin.status1')" :value="1"></el-option>
						<el-option :label="$t('logLogin.status2')" :value="2"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button class="buttonColor" @click="getDataList()">{{ $t('query') }}</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
				</el-form-item>
			</el-form>
			<el-table v-loading="dataListLoading" :data="dataList" border @sort-change="dataListSortChangeHandle" style="width: 100%;">
				<el-table-column prop="creatorName" :label="$t('logLogin.creatorName')" header-align="center" align="center"></el-table-column>
				<el-table-column prop="operation" :label="$t('logLogin.operation')" header-align="center" align="center">
					<template slot-scope="scope">
						{{ scope.row.operation === 0 ? $t('logLogin.operation0') : $t('logLogin.operation1') }}
					</template>
				</el-table-column>
				<el-table-column prop="status" :label="$t('logLogin.status')" sortable="custom" header-align="center" align="center">
					<template slot-scope="scope">
						<el-tag v-if="scope.row.status === 0" size="small" type="danger">{{ $t('logLogin.status0') }}</el-tag>
						<el-tag v-else-if="scope.row.status === 1" size="small" type="success">{{ $t('logLogin.status1') }}</el-tag>
						<el-tag v-else size="small" type="warning">{{ $t('logLogin.status2') }}</el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="ip" :label="$t('logLogin.ip')" header-align="center" align="center"></el-table-column>
				<el-table-column prop="userAgent" :label="$t('logLogin.userAgent')" header-align="center" align="center" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column prop="createDate" :label="$t('logLogin.createDate')" sortable="custom" header-align="center" align="center" width="180"></el-table-column>
			</el-table>
			<el-pagination
				:current-page="page"
				:page-sizes="[10, 20, 50, 100]"
				:page-size="limit"
				:total="total"
				layout="total, sizes, prev, pager, next, jumper"
				@size-change="pageSizeChangeHandle"
				@current-change="pageCurrentChangeHandle"
			>
			</el-pagination>
		</div>
	</el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
	mixins: [mixinViewModule],
	data() {
		return {
			mixinViewModuleOptions: {
				getDataListURL: '/sys/log/login/page',
				getDataListIsPage: true,
				exportURL: '/sys/log/login/export'
			},
			dataForm: {
				creatorName: '',
				status: ''
			}
		}
	},
	methods: {
		exportHandle() {
			// 导出登录日志
			this.$http({
				url: this.$http.adornUrl(`/sys/log/login/export${this.dataForm.creatorName,this.dataForm.status}`),
				method: 'get',
				responseType: "blob"
			}).then((response) => {
				let fileName = ''
				const contentDisposition = response.headers['content-disposition']
				if (contentDisposition) {
					// fileName = contentDisposition.slice(contentDisposition.indexOf('filename=') + 9).replace('.xls',this.$t('LoginRecords')) +'.xls'
					fileName = contentDisposition.slice(contentDisposition.indexOf('filename=') + 9)
				}
				fileName = decodeURIComponent(fileName)
				const blob = new Blob([response.data])
				const reader = new FileReader()
				reader.readAsDataURL(blob)
				reader.onload = (e) => {
					const a = document.createElement('a')
					a.download = fileName
					a.href = e.target.result
					document.body.appendChild(a)
					a.click()
					document.body.removeChild(a)
				}
			})
		}
	}
}
</script>

<style>
.blueTip::before {
	display: inline-block;
	content: '';
	width: 4px;
	height: 24px;
	background: #0b58ff;
	border-radius: 1px;
	margin-right: 8px;
	margin-top: 4px;
}
.buttonColor {
	color: #fff;
	background: #0b58ff;
}
</style>