//组件
	var Uhcomponent = {
		template:`
		<div>
			<div id="" style="display: inline-block;width: 100%;">
			
				<div  style="float: left; width: 20%;background-color: #ECF5FF;">
				<el-input v-model="input" placeholder="请输入用户名" clearable></el-input>
				</div>
				<div style="float: left;background-color: #ECF5FF;">
				 <el-date-picker
				      v-model="date_value"
				      type="datetimerange"
				      range-separator="至"
				      start-placeholder="开始日期"
				      end-placeholder="结束日期"
					  value-format="yyyy-MM-dd HH:mm:ss">
				    </el-date-picker>
				</div>
				<div style="float: left;margin-left: 10px;">
				<el-button id ="bt_search" plain type="primary" icon="el-icon-search" @click="getuh(input)">搜索</el-button>
				</div>
				
				<div style="float: left; margin-left: 10px;">
					<el-button id ="bt_export1" size="medium" plain type="primary" icon="el-icon-document" @click="exportUserLoginCnt()">导出用户登录次数</el-button>
				</div>
			</div>
			<div class="span">
				<el-table
				    :data="tableData"
				    style="width: 100%"
				    :height="tHeight"
							  :cell-style="{background:'#304156'}"
							  border
					>
				    <el-table-column
				      prop="username"
				      label="用户名"
				      width="100">
				    </el-table-column>
							  
							  <el-table-column
							    prop="time"
							    label="时间"
							    width="170">
							  </el-table-column>
							  
							  <el-table-column
							    prop="op_text"
							    label="操作"
							    :width="flexColumnWidth('op_text',tableData)">
							  </el-table-column>
				  </el-table>
			</div>
		  
			<div class="block">
			    <span class="demonstration" style="background-color: #ECF5FF;"></span>
			    <el-pagination
			      @size-change="handleSizeChange"
			      @current-change="handleCurrentChange"
			      :current-page="currentPage"
			      :page-sizes="[50,100, 200, 300]"
			      :page-size="pagesize"
			      layout="total, sizes, prev, pager, next, jumper"
			      :total="recordTotal" style="background-color: #ECF5FF;">
			    </el-pagination>
			  </div>
		</div>
		`,
	  data(){
		  // 获取当前屏幕的分辨率
		  let screenW = window.screen.width;
		  let screenH = window.innerHeight;
		  console.log("screen width:",screenW);
		  console.log("screen height:",screenH);
		  
		  return {
			tHeight:screenH-238,
			tableData: [],
			input:'',
			currentPage: 1,
			pagesize:50,
			recordTotal:0,
			date_value:[],
		  }
		},
		mounted() {
			
			var _this = this;
			
			var objs;
			axios.post('/deescloud/getuh', {
				opuser:localStorage.getItem("online_user"),
				opuser_uuid:localStorage.getItem("uuid"),
			    index: this.$data.currentPage,
			    count: this.$data.pagesize
			  })
			  .then(function (response) {
				  
			    console.log(response.data);
				objs = response.data.data;
				rcnt = response.data.total;
				_this.$data.tableData = objs;
				_this.$data.recordTotal = rcnt;
			  })
			  .catch(function (error) {
			    console.log(error);
			  });
		},
	  methods: {

		exportUserLoginCnt(){
			document.getElementById("bt_export1").blur();

			var beginTime= '';
			var endTime = '';

			console.log("date_value:",this.$data.date_value);
			if (this.$data.date_value != null && this.$data.date_value.length > 1) {
				console.log("len:",this.$data.date_value.length)
				beginTime = this.$data.date_value[0];
				endTime = this.$data.date_value[1];
			}
			axios.post('deescloud/getUserLoginCntCsv',{
				opuser:localStorage.getItem("online_user"),
				opuser_uuid:localStorage.getItem("uuid"),
				user: this.$data.input,
				b_time:beginTime,
				e_time:endTime,
			})
			.then(function (response) {
				console.log(response.data);
				var fileid = response.data.fileId;
				
				var downUrl = 'file/'+fileid;
				downloadUrl("用户登录次数表.xlsx",downUrl);
			})
			.catch(function (error) {
				console.log(error);
			});
		},
		
		getuh(_search_name){
		document.getElementById("bt_search").blur();
		
		this.$data.currentPage=1;
		
		var beginTime= '';
		var endTime = '';
		
		console.log("date_value:",this.$data.date_value);
		if (this.$data.date_value != null && this.$data.date_value.length > 1) {
			console.log("len:",this.$data.date_value.length)
			beginTime = this.$data.date_value[0];
			endTime = this.$data.date_value[1];
		}

		var _this = this;

		var objs;
		axios.post('/deescloud/getuh', {
			opuser:localStorage.getItem("online_user"),
			opuser_uuid:localStorage.getItem("uuid"),
			user: _search_name,
			b_time:beginTime,
			e_time:endTime,
			index: this.$data.currentPage,
			count: this.$data.pagesize
		  })
		  .then(function (response) {
			console.log(response.data);
			objs = response.data.data;
			rcnt = response.data.total;
			_this.$data.tableData = objs;
			_this.$data.recordTotal = rcnt;
		  })
		  .catch(function (error) {
			console.log(error);
		  });

		},

		handleSizeChange(val) {
			  this.$data.pagesize = val;
			  this.$data.currentPage = 1;
			  var beginTime= '';
			  var endTime = '';
			  
			  if (this.$data.date_value != null && this.$data.date_value.length > 1) {
			  	console.log("len:",this.$data.date_value.length)
			  	console.log("date_value:",this.$data.date_value);
			  	beginTime = this.$data.date_value[0];
			  	endTime = this.$data.date_value[1];
			  }
			  
			  var _this = this;
			  
			  var objs;
			  axios.post('/deescloud/getuh', {
					opuser:localStorage.getItem("online_user"),
					opuser_uuid:localStorage.getItem("uuid"),
					user: this.$data.input,
					b_time:beginTime,
					e_time:endTime,
					index: this.$data.currentPage,
					count: this.$data.pagesize
				})
				.then(function (response) {
				  console.log(response.data);
				objs = response.data.data;
				rcnt = response.data.total;
				_this.$data.tableData = objs;
				_this.$data.recordTotal = rcnt;
				})
				.catch(function (error) {
				  console.log(error);
				});
		},
		handleCurrentChange(val) {
		  this.$data.currentPage = val;
		  
		  var beginTime= '';
		  var endTime = '';
		  
		  if (this.$data.date_value != null && this.$data.date_value.length > 1) {
		  	console.log("len:",this.$data.date_value.length)
		  	console.log("date_value:",this.$data.date_value);
		  	beginTime = this.$data.date_value[0];
		  	endTime = this.$data.date_value[1];
		  }
		  
		  var _this = this;
		  
		  var objs;
		  axios.post('/deescloud/getuh', {
					opuser:localStorage.getItem("online_user"),
					opuser_uuid:localStorage.getItem("uuid"),
					user: this.$data.input,
					b_time:beginTime,
					e_time:endTime,
					index: this.$data.currentPage,
					count: this.$data.pagesize
				})
				.then(function (response) {
				  console.log(response.data);
				objs = response.data.data;
				rcnt = response.data.total;
				_this.$data.tableData = objs;
				_this.$data.recordTotal = rcnt;
				})
				.catch(function (error) {
				  console.log(error);
				});
		},
		flexColumnWidth(str, tableData, flag = 'max') {
		  // str为该列的字段名(传字符串);tableData为该表格的数据源(传变量);
		  // flag为可选值，可不传该参数,传参时可选'max'或'equal',默认为'max'
		  // flag为'max'则设置列宽适配该列中最长的内容,flag为'equal'则设置列宽适配该列中第一行内容的长度。
		  let flexWidth = 0
		  
		  str = str + ''
		  let columnContent = ''
		  if (!tableData || !tableData.length || tableData.length === 0 || tableData === undefined) {
		    flexWidth = 120;
			return flexWidth + 'px';
		  }
		  if (!str || !str.length || str.length === 0 || str === undefined) {
			 flexWidth = 120;
			 return flexWidth + 'px';
		  }
		  if (flag === 'equal') {
		    // 获取该列中第一个不为空的数据(内容)
		    for (let i = 0; i < tableData.length; i++) {
		      if (tableData[i][str].length > 0) {
		        // console.log('该列数据[0]:', tableData[0][str])
		        columnContent = tableData[i][str]
		        break
		      }
		    }
		  } else {
		    // 获取该列中最长的数据(内容)
		    let index = 0
		    for (let i = 0; i < tableData.length; i++) {
		      if (tableData[i][str] === null) {
		        return
		      }
		      const now_temp = tableData[i][str] + ''
		      const max_temp = tableData[index][str] + ''
		      if (now_temp.length > max_temp.length) {
		        index = i
		      }
		    }
		    columnContent = tableData[index][str]
		  }
		  // console.log('该列数据[i]:', columnContent)
		  // 以下分配的单位长度可根据实际需求进行调整
		  
		  console.log(columnContent);
		  
		  for (const char of columnContent.toString()) {
		    if ((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z')) {
		      // 如果是英文字符，为字符分配8个单位宽度
		      flexWidth += 8
		    } else if (char >= '\u4e00' && char <= '\u9fa5') {
		      // 如果是中文字符，为字符分配15个单位宽度
		      flexWidth += 15
		    } else {
		      // 其他种类字符，为字符分配8个单位宽度
		      flexWidth += 8
		    }
		  }
		  if (flexWidth < 120) {
		    // 设置最小宽度
		    flexWidth = 120
			return flexWidth + 'px'
		  }
		  
		  if (flexWidth > 300) {
			  // 设置最大宽度
		  	flexWidth = 300;
		  }
		  
		  console.log("1-flexWidth:",flexWidth);
		  //flexWidth = flexWidth+20;//20-padding
		  console.log("2-flexWidth:",flexWidth);
		  return flexWidth + 'px'
		},
		
	  }
	}
			