vue2使用小记

el-form表单嵌套Select 选择器

  • el-select 属性

filterable:用于搜索下拉框中的选项

clearable:清空选择项

multiple:可以多选,传递的值为数组格式,不写默认单选传递的值为字符串

:collapse-tags="true":将选中值按文字的形式展示,看下图

                <el-form-item label="场景:">
                    <el-select v-model="listQuery.ChannelCategory" class="input-width" placeholder="全部" filterable clearable
                        @keyup.enter.native="handleSearchList" :collapse-tags="true">
                        <el-option v-for="item in ChannelCategory" :key="item.id" :label="item.name" :value="item.name">
                        </el-option>
                    </el-select>
                </el-form-item>

去除el-table内边距

首先使用:header-cell-style="tableHeaderCellStyle":cell-style="tableCellStyle"用来定义表头单元格和普通单元格的样式。

        <el-table class="custom-table" highlight-current-row :data="TargetData" style="width: 100%"
            element-loading-spinner="el-icon-loading" v-loading="loading" element-loading-text="拼命加载中" max-height="500"
            :header-cell-style="tableHeaderCellStyle" :cell-style="tableCellStyle">

然后使用 computed 属性来定义计算属性。在这里,tableHeaderCellStyle 和 tableCellStyle 都是计算属性,它们会根据特定的逻辑返回一个样式对象。

 computed: {

        tableHeaderCellStyle() {
            return {
                color: '#000', // 字体颜色
                fontSize: '12px', // 字体大小
                fontFamily: '微软雅黑', // 字体样式
                // textAlign: 'center', // 文本居中对齐

            };
        },
        // table文本居中
        tableCellStyle() {
            return {
                fontSize: '0.17rem', // 字体大小
                // textAlign: 'center', // 文本居中对齐
                padding: 0,
                margin: 0,
            };
        },
    },

对于 tableHeaderCellStyle,它返回一个对象,其中包含了一些用于定义表头样式的属性,比如字体颜色、字体大小、字体样式等。

对于 tableCellStyle,它返回一个对象,其中包含了一些用于定义表格内容样式的属性,比如字体大小、内边距、外边距等。

这样做的好处是,如果这些样式需要根据特定逻辑或数据动态变化,可以将其定义为计算属性,从而使得样式可以根据数据的变化而动态更新,而不需要手动编写复杂的逻辑来实现样式的动态变化。

查询loading效果

        <el-button icon="el-icon-search" type="primary" @click="handleSearchList()" style="margin-top: 37px;"
          v-loading.fullscreen.lock="fullscreenLoading">查询</el-button>


 return {
      fullscreenLoading: false,//全屏遮罩
}


    //搜索
    handleSearchList() {
      this.fullscreenLoading = true;
      setTimeout(() => {
       //调用接口
        this.fullscreenLoading = false;
      }, 2000);

    },

导出功能添加全屏loading 页面禁止其它操作

    // 导出 
    async ProfitMarginExcel() {
      this.$message({
        message: '正在为您导出全量明细',
        type: 'warning',
      });

//loading效果
      const loading = this.$loading({
        lock: true,
        text: '导出完成后自动打开excel',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      const startDate = this.listQuery.ownUpdatedTime ? this.listQuery.ownUpdatedTime[0] : null;
      const endDate = this.listQuery.ownUpdatedTime ? this.listQuery.ownUpdatedTime[1] : null;
      const data = {
        
      }
      try {
        // 发送 POST 请求获取 Excel 数据
        const response = await ExcelomnichannelMarginalProfitApi(data)

        // 创建 Blob 对象并下载文件
        const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
        const link = document.createElement('a');
        link.href = window.URL.createObjectURL(blob);
        link.download = '全量明细报表.xlsx';
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);

        // 导出完成后关闭加载状态
        loading.close();
      } catch (error) {
        console.error('导出 Excel 出错:', error);
      }
    },

将 `ProjectMaterialStatistics.vue` 和 `ProjectMaterialDetails.vue` 使用 Composition API 进行重构,并且保证在 Vue 2 中运行,可以按照以下步骤进行: ### 1. 安装 `@vue/composition-api` 首先,需要安装 `@vue/composition-api` 插件,以便在 Vue 2使用 Composition API。 ```bash npm install @vue/composition-api ``` ### 2. 修改主文件引入插件 在 `main.js` 或者 `main.ts` 文件中引入并注册 `@vue/composition-api`。 ```javascript import Vue from 'vue'; import App from './App.vue'; import '@vue/composition-api'; Vue.config.productionTip = false; new Vue({ render: h => h(App), }).$mount('#app'); ``` ### 3. 重构 `ProjectMaterialStatistics.vue` #### 原始代码结构 原始代码使用了 Options API,我们需要将其转换为 Composition API。 #### 重构后的代码 ```vue <template> <a-spin :spinning="spinning" tip="报表同步中,请稍等"> <a-card :bordered="false"> <!-- 查询区域 --> <div class="table-page-search-wrapper"> <a-form layout="inline" @keyup.enter.native="searchQuery"> <a-row :gutter="24"> <a-col> <my-fast-date-picker :radioList="[{ value: 2, text: '月' }, { value: 3, text: '年' }]" :radioVal="2" :currName="'近半年'" :showRadioGroup="true" :fastTime="fastTime" @change="change" > <template v-slot:text>时间:</template> </my-fast-date-picker> </a-col> <template v-if="toggleSearchStatus"> <a-col :xl="6" :lg="7" :md="8" :sm="24"> <a-form-item label="目编号:"> <a-input placeholder="请输入目编号" allow-clear v-model="queryParam.projectCode"></a-input> </a-form-item> </a-col> <a-col :xl="6" :lg="7" :md="8" :sm="24"> <a-form-item label="目名称"> <a-select allow-clear show-search v-model="queryParam.projectName_Code" placeholder="请输入目名称" style="width: 100%" :show-arrow="false" :filter-option="false" :not-found-content="null" @search="projectCodeSearch" @change="projectCodeChange" > <a-select-option v-for="d in projectNameList" :key="d.id">{{ d.text }}</a-select-option> </a-select> </a-form-item> </a-col> <a-col :xl="6" :lg="7" :md="8" :sm="24"> <a-form-item label="物资"> <a-input placeholder="请输入物资编号/名称" allow-clear v-model="queryParam.keyWord"></a-input> </a-form-item> </a-col> <a-col :xl="6" :lg="7" :md="8" :sm="24"> <a-form-item label="厂商"> <j-search-select-tag placeholder="请选择厂商" v-model="queryParam.producerId" dict="biz_product_vendor,abbreviation,id,del_flag = 0 and status = 1" /> </a-form-item> </a-col> <a-col :xl="6" :lg="7" :md="8" :sm="24"> <a-form-item label="规格型号"> <a-input placeholder="请输入规格型号" allow-clear v-model="queryParam.specification"></a-input> </a-form-item> </a-col> </template> <a-col :xl="6" :lg="7" :md="8" :sm="24"> <span style="float: left; overflow: hidden;" class="table-page-search-submitButtons"> <a-button type="primary" @click="searchQuery" icon="search">查询</a-button> <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button> <a @click="handleToggleSearch" style="margin-left: 8px">{{ toggleSearchStatus ? '收起' : '展开' }} <a-icon :type="toggleSearchStatus ? 'up' : 'down'" /> </a> </span> </a-col> </a-row> </a-form> </div> <!-- 查询区域-END --> <!-- 操作按钮区域 --> <div class="table-operator"> <div> <a-button type="primary" icon="download" @click="handleExportXlsx()">导出</a-button> </div> </div> <!-- table区域-begin --> <div> <a-table ref="table" size="middle" :scroll="{ x: true }" bordered row-key="uniqueId" :columns="columns" :data-source="dataSource" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap" @change="handleTableChange" > <span slot="receivingFreezeAmount"> 领用冻结 <a-tooltip> <template slot="title"> 目领用申请审核通过后,待出库的数量。 </template> <a-icon type="info-circle" /> </a-tooltip> </span> <span slot="receivingFreezeAmount_title"> 预算余量 <a-tooltip> <template slot="title"> 预算余量=预算总数-领用冻结-领用总数+领用归还 </template> <a-icon type="info-circle" /> </a-tooltip> </span> <span slot="requisitionAmount_title"> 领用总数 <a-tooltip> <template slot="title"> 目盘盈更新领用余料时,会自动产生领用增补单(不受预算限制),可能导致领用总数超过预算总数。 </template> <a-icon type="info-circle" /> </a-tooltip> </span> <span slot="budgetTotalAmount" slot-scope="text, record"> <a-tooltip> <template slot="title"> <div class="tipItem"> <div>预算编号</div> <div>预算数</div> </div> <div v-for="(value, key) in record.budgetDetail" class="tipItem" v-show="key !== '小计'"> <div>{{ key }}</div> <div>{{ value }}</div> </div> <div class="tipItem"> <div>小记</div> <div>{{ text }}</div> </div> </template> <span style="color: blue">{{ text }}</span> </a-tooltip> </span> <span slot="budgetSurplusAmount" slot-scope="text, record"> <span :style="{ color: record.budgetSurplusAmount <= projectBudgetMarginWarning ? 'red' : 'black' }"> {{ text }} </span> </span> <span slot="inventoryAmount" slot-scope="text, record"> <span :style="{ color: record.inventoryAmount <= record.budgetSurplusAmount ? 'red' : 'black' }"> {{ text }} </span> </span> </a-table> </div> </a-card> </a-spin> </template> <script> import { reactive, computed, onMounted, watch } from '@vue/composition-api'; import { getAction, postAction } from '@/api/manage'; import MyFastDatePicker from '@/components/date/MyFastDatePicker'; import '@/assets/less/TableExpand.less'; import { mixinDevice } from '@/utils/mixin'; import { JeecgListMixin } from '@/mixins/JeecgListMixin'; export default { name: 'ProjectMaterialStatistics', components: { MyFastDatePicker, }, setup(props, { root }) { const state = reactive({ projectNameList: [], projectName_Code: '', projectBudgetMarginWarning: 0, expandedRowKeys: [], workorderProjectList: [], description: '营业报表管理页面', fastTime: ['本月', '上月', '近半年'], noCreate: true, hasUpdateTime: true, configOrderSubTypeList: [], configOrderSubTypeTemp: undefined, allDepartList: [], hallCodeDataList: [], spinning: false, checkFlag: true, updateTime: '', url: { list: '/web/projectUseMaterial/list', exportXlsxUrl: '/web/projectUseMaterial/export', exportPdfUrl: '/web/bizBusinessRecord/exportpdf', exportDetailUrl: '/web/bizBusinessRecord/exportDetailExcel', }, keyList: ['saleNum', 'saleName', 'terminalTypeName', 'userTypeName', 'configOrderMainTypeName', 'configOrderSubTypeName'], ipagination: { current: 1, pageSize: 20, pageSizeOptions: ['20', '50', '80'], showTotal(total, range) { return `${range[0]}-${range[1]} 共${total}条`; }, showQuickJumper: true, showSizeChanger: true, total: 0, }, columns: [ { title: '目编号', align: 'center', dataIndex: 'projectCode', customRender: (text, row, index) => renderMergedCells(text, row, index) }, { title: '目名称', align: 'center', dataIndex: 'projectName', customRender: (text, row, index) => renderMergedCells(text, row, index) }, { title: '物资编号', align: 'center', dataIndex: 'materialCode' }, { title: '物资名称', align: 'center', dataIndex: 'materialName' }, { title: '厂商', align: 'center', dataIndex: 'producerId_dictText' }, { title: '规格型号', align: 'center', dataIndex: 'specification' }, { title: '单位', align: 'center', dataIndex: 'unit' }, { title: '预算总数', align: 'center', dataIndex: 'budgetTotalAmount', scopedSlots: { customRender: 'budgetTotalAmount' } }, { align: 'center', slots: { title: 'receivingFreezeAmount' }, dataIndex: 'receivingFreezeAmount' }, { align: 'center', slots: { title: 'requisitionAmount_title' }, dataIndex: 'receivingTotalAmount' }, { title: '领用余料', align: 'center', dataIndex: 'receivingSurplusAmount' }, { title: '领料使用', align: 'center', dataIndex: 'receivingUseAmount' }, { align: 'center', dataIndex: 'budgetSurplusAmount', slots: { title: 'receivingFreezeAmount_title' }, scopedSlots: { customRender: 'budgetSurplusAmount' } }, { title: '库存可用数', align: 'center', dataIndex: 'inventoryAmount', scopedSlots: { customRender: 'inventoryAmount' } }, ], queryParam: { projectCode: '', keyWord: '', producerId: '', specification: '', projectName_Code: '', projectName: '', }, toggleSearchStatus: false, dataSource: [], loading: false, }); const renderMergedCells = (value, row, index) => { const obj = { children: value, attrs: {} }; if (index === 0 || row.projectName !== state.dataSource[index - 1].projectName) { let rowSpan = 1; for (let i = index + 1; i < state.dataSource.length; i++) { if (state.dataSource[i].projectName === row.projectName) { rowSpan++; } else { break; } } obj.attrs.rowSpan = rowSpan; } else { obj.attrs.rowSpan = 0; } return obj; }; const projectCodeSearch = async (value) => { const res = await getAction('/web/projectRecord/searchMainProject', { order: 'desc', pageNo: 1, pageSize: 100, keyword: value }); state.projectNameList = res.result.map(item => ({ id: item.id, value: item.projectCode, text: item.projectName })); }; const projectCodeChange = (value) => { const obj = state.projectNameList.filter(item => item.id === value); if (obj.length > 0) { state.exportParams.projectName = obj[0].text; state.queryParam.projectName = obj[0].text; } else { state.exportParams.projectName = ''; state.queryParam.projectName = ''; } }; const change = (val1, val2, val3) => { state.exportParams.dateTpye = val3 === 2 ? 1 : 2; state.queryParam.beginDate = val1; state.queryParam.endDate = val2; state.queryParam.hiddenZeroTotalAmountFlag = state.checkFlag ? 1 : 0; }; const searchQuery = () => { state.loadData(1); }; const searchReset = () => { state.queryParam.projectCode = ''; state.queryParam.keyWord = ''; state.queryParam.producerId = ''; state.queryParam.specification = ''; state.queryParam.projectName_Code = ''; state.queryParam.projectName = ''; state.loadData(1); }; const handleToggleSearch = () => { state.toggleSearchStatus = !state.toggleSearchStatus; }; const handleExportXlsx = () => { // 导出逻辑 }; const handleTableChange = (pagination, filters, sorter) => { // 表格变化逻辑 }; const loadData = async (page) => { state.loading = true; try { const res = await getAction(state.url.list, { ...state.queryParam, page }); state.dataSource = res.result.records; state.ipagination.total = res.result.total; } finally { state.loading = false; } }; onMounted(() => { loadData(1); postAction('/web/sysCompany/queryLoginCompany').then(res => { state.projectBudgetMarginWarning = res.result.projectBudgetMarginWarning || 0; }); });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值