

(1.1)使用el-popover,你需要修改的是this.colOptions,colSelect:

"popover" popper-class="planProver" placement="bottom" width="300" trigger="click" content="{this.colOptions}" class="elPopover"> - <el-checkbox-group v-model="colSelect" @change="refreshPic">
- <el-checkbox v-for="item in colOptions" :label="item" :key="item" style="display: block; padding-top: 10px">el-checkbox>
- el-checkbox-group>
- <el-button type="primary" slot="reference">表格设置el-button>
-
(1.2)js代码中的data

- data(){
- return{
- colOptions: ['飞行计划编号', '通航用户', '任务性质', '机型', '飞行员', '开始时间', '结束时间', '联系人', '24位地址码', '机载设备', '飞行规则'],
- // 已选中的表头:默认显示内容
- colSelect: [],
- // 默认选择的
- colSelectToday: ['飞行计划编号', '通航用户', '任务性质', '机型', '飞行员', '开始时间'],
- // 主要是为了获取table的prop
- columnLabels: {
- flightPlanNumber: '飞行计划编号',
- airNavigationUser: '通航用户',
- missionType: '任务性质',
- aircraftType: '机型',
- pilot: '飞行员',
- startTime: '开始时间',
- endTime: '结束时间',
- contact: '联系人',
- addressCode: '24位地址码',
- onboardEquipment: '机载设备',
- flightRules: '飞行规则',
- },
-
- }
- }
(1.3)js中的methods

- //重新选择表格表头时
- refreshPic(val) {
- localStorage.setItem('planColSelect', JSON.stringify(val));
- this.colSelect = JSON.parse(localStorage.getItem('planColSelect'));
- },
(2.1)html代码

- <el-table :data="tableData" style="width: 100%; height: 100%" border :cell-style="customCellStyle" :header-cell-style="customHeaderCellStyle">
- <el-table-column label="序号" type="index" align="center" width="50">
- el-table-column>
- <el-table-column :label="item" :key="'key' + item + index" v-for="(item, index) in colSelect" :prop="getProp(item)">el-table-column>
- el-table>
(2)js中的method写:

- getProp(item) {
- // 遍历 columnLabels 对象,查找匹配的属性名
- for (const prop in this.columnLabels) {
- if (this.columnLabels[prop] === item) {
- return prop; // 返回匹配的属性名
- }
- }
- // 如果未找到匹配项,返回 null 或其他适当的值
- return null;
- },
-
-
-
-
-
-
-
取消 -
保存 -
- >
-
-
-
待审批 -
审批 -
- >
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- v-model="dateForm.dateTimes"
- type="datetimerange"
- range-separator="至"
- start-placeholder="开始日期"
- end-placeholder="结束日期"
- :picker-options="pickerOptions"
- format="yyyy-MM-dd HH:mm"
- value-format="yyyy-MM-dd HH:mm"
- >
-
-
-
-
查询 -
-
-
导出 -
-
-
重置 -
-
-
-
-
-
表格设置 -
-
-
-
-
-
-
-
-
-
-
-
- export default {
- name: 'navigationFlightPlan',
- data() {
- return {
- dateForm: {
- dateTimes: [this.$common.getMonthFirstAndLastDay().firstDay, this.$common.getMonthFirstAndLastDay().lastDay],
- radio1: 0,
- radio2: 0,
- planNumberInput: '',
- callInput: '',
- machineInput: '',
- },
- pickerOptions: {
- shortcuts: [
- {
- text: '最近一天',
- onClick(picker) {
- const end = new Date();
- const start = new Date();
- start.setTime(start.getTime() - 3600 * 1000 * 24);
- picker.$emit('pick', [start, end]);
- },
- },
- {
- text: '最近一个周',
- onClick(picker) {
- const end = new Date();
- const start = new Date();
- start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
- picker.$emit('pick', [start, end]);
- },
- },
- {
- text: '最近一个月',
- onClick(picker) {
- const end = new Date();
- const start = new Date();
- start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
- picker.$emit('pick', [start, end]);
- },
- },
- ],
- onPick: ({ maxDate, minDate }) => {
- this.selectDate = minDate.getTime();
- if (maxDate) {
- this.selectDate = '';
- }
- },
- disabledDate: (time) => {
- if (this.selectDate !== '') {
- const one = 31 * 24 * 3600 * 1000;
- const minTime = this.selectDate - one;
- const maxTime = this.selectDate + one;
- return time.getTime() < minTime || time.getTime() > maxTime;
- }
- },
- },
- tableData: [
- {
- flightPlanNumber: 'FP001',
- airNavigationUser: 'User A',
- missionType: 'Mission 1',
- aircraftType: 'Type X',
- pilot: 'Pilot 1',
- startTime: '2023-10-01 08:00',
- endTime: '2023-10-01 10:00',
- contact: 'John Doe',
- addressCode: 'ABCDEF1234567890',
- onboardEquipment: 'Equipment 1',
- flightRules: 'Rule A',
- },
- {
- flightPlanNumber: 'FP002',
- airNavigationUser: 'User B',
- missionType: 'Mission 2',
- aircraftType: 'Type Y',
- pilot: 'Pilot 2',
- startTime: '2023-10-05 14:00',
- endTime: '2023-10-05 16:00',
- contact: 'Jane Smith',
- addressCode: 'XYZ1234567890ABC',
- onboardEquipment: 'Equipment 2',
- flightRules: 'Rule B',
- },
- {
- flightPlanNumber: 'FP003',
- airNavigationUser: 'User C',
- missionType: 'Mission 1',
- aircraftType: 'Type X',
- pilot: 'Pilot 3',
- startTime: '2023-10-10 10:00',
- endTime: '2023-10-10 12:00',
- contact: 'Mary Johnson',
- addressCode: '1234567890XYZABC',
- onboardEquipment: 'Equipment 3',
- flightRules: 'Rule A',
- },
- {
- flightPlanNumber: 'FP004',
- airNavigationUser: 'User D',
- missionType: 'Mission 3',
- aircraftType: 'Type Z',
- pilot: 'Pilot 4',
- startTime: '2023-10-15 09:00',
- endTime: '2023-10-15 11:00',
- contact: 'Robert Brown',
- addressCode: '7890ABCXYZ123456',
- onboardEquipment: 'Equipment 4',
- flightRules: 'Rule C',
- },
- // Add more data objects as needed
- ],
-
- // 表格设置
- // 所有的选项
- colOptions: ['飞行计划编号', '通航用户', '任务性质', '机型', '飞行员', '开始时间', '结束时间', '联系人', '24位地址码', '机载设备', '飞行规则'],
- // 已选中的表头:默认显示内容
- colSelect: [],
- // 默认选择的
- colSelectToday: ['飞行计划编号', '通航用户', '任务性质', '机型', '飞行员', '开始时间'],
- // 主要是为了获取table的prop
- columnLabels: {
- flightPlanNumber: '飞行计划编号',
- airNavigationUser: '通航用户',
- missionType: '任务性质',
- aircraftType: '机型',
- pilot: '飞行员',
- startTime: '开始时间',
- endTime: '结束时间',
- contact: '联系人',
- addressCode: '24位地址码',
- onboardEquipment: '机载设备',
- flightRules: '飞行规则',
- },
- };
- },
- mounted() {
- this.colSelect = this.colSelectToday;
- },
- methods: {
- onSearch() {
- console.log(this.dateForm.dateTimes);
- },
- customCellStyle({ row, column }) {
- return {
- color: 'white',
- backgroundColor: '#333333',
- border: '1px solid #616265',
- };
- },
- customHeaderCellStyle({ column }) {
- return {
- color: 'white',
- backgroundColor: '#616265',
- border: '1px solid #616265',
- fontWeight: 'bold', // 文本加粗
- 'text-align': 'center',
- };
- },
- resetForm() {
- this.$refs.myForm.resetFields(); // 通过 ref 调用 resetFields 方法重置表单
- },
-
- //重新选择表格表头时
- refreshPic(val) {
- localStorage.setItem('planColSelect', JSON.stringify(val));
- this.colSelect = JSON.parse(localStorage.getItem('planColSelect'));
- },
- getProp(item) {
- // 遍历 columnLabels 对象,查找匹配的属性名
- for (const prop in this.columnLabels) {
- if (this.columnLabels[prop] === item) {
- return prop; // 返回匹配的属性名
- }
- }
- // 如果未找到匹配项,返回 null 或其他适当的值
- return null;
- },
- },
- };
-
- .homeContainer {
- width: 100%;
- height: 100%;
- padding: 3rem 1rem;
- color: white;
- display: flex; /* 使用Flexbox布局 */
- flex-direction: column; /* 垂直布局 */
- }
- .el-form-item__label {
- color: white !important;
- }
- .el-date-editor,
- .el-range-input {
- background-color: #aaaaaa;
- color: black !important;
- }
- .el-icon-date,
- .el-range-input::placeholder,
- .el-picker-panel,
- .el-date-table th,
- .el-picker-panel__sidebar button {
- color: black !important;
- }
- .el-picker-panel__sidebar,
- .el-picker-panel__body,
- .el-input__inner,
- .el-picker-panel__footer {
- background-color: #aaaaaa;
- }
- .el-input.is-disabled .el-input__inner {
- background-color: #aaaaaa;
- }
- .homeMain {
- flex: 1;
- }
- .el-table {
- background-color: #333333 !important;
- }
- /* .itemInput >>> .el-form-item__content {
- width: 100px !important;
- } */
- .el-radio__label {
- font-size: 1rem !important;
- font-family: Microsoft YaHei, Microsoft YaHei-Regular !important;
- }
- .el-popover--plain,
- .el-checkbox__inner {
- background: #aaaaaa !important;
- }
-
相关阅读:
【Python】类和对象的深入解析
Redis之Redis基础、环境搭建、主从切换
程序员保密协议书(与合作单位签署)
leetcode:2441. 与对应负数同时存在的最大正整数(python3解法)
Android studio 一次编译生成32位和64位bin和lib
【Vue基础一】
我,土木人,时隔7年转行计算机,差点放弃了
相机相关:相机模型与畸变模型
智能社区奶柜带来便利与实惠
项目管理之实施关键步骤
-
原文地址:https://blog.csdn.net/qq_42192641/article/details/134190364