vue给表格,弹窗以及整个页面加loading

给表格加loading

table表格有内置的loading,
:loading=“tableLoading”

<a-table
	 :columns="columns"
	 :data-source="expandform.treeList"
	 :pagination="false"
	 rowKey="appraisalTargetId"
	 :loading="tableLoading"
	>
	 <template #index="{ index }">{{ index + 1 }}</template>
	 <template #weight="{ record }">
	   <a-input
	     v-model:value="record.weight"
	     placeholder="请输入"
	     :disabled="currentType === '3'"
	   />
	 </template>
	
	 <!-- 顺序调整 -->
	 <template #sort="{ record, index }" v-if="currentType !== '3'">
	   <CaretDownOutlined @click="onSort(record, index, '1')" />
	   <CaretUpOutlined
	     @click="onSort(record, index, '2')"
	     style="margin-left: 10px"
	   />
	 </template>
</a-table>

js

//tableLoading 
const tableLoading = ref(false)

 const selectProjectAppraisalTargetSecondary = () => {
 	//tableLoading 
     tableLoading.value = true
     
     post(API.ability.selectProjectAppraisalTargetSecondary, {
             params: {
                 projectEvaluationId: props.stepId
             }
         })
         .then((res) => {
             //tableLoading 
             tableLoading.value = false
             
             expandform.treeList = treeData(
                 res.data,
                 "appraisalTargetId",
                 "parentId",
                 "children",
                 "parentId",
                 undefined
             )
             expandform.treeList.forEach((item, index) => {
                 let i = 100 % expandform.treeList.length
                 item.weight = parseInt(100 / expandform.treeList.length)
                 if (index === expandform.treeList.length - 1) {
                     item.weight = item.weight + i
                 }
                 item.children.forEach((itms, indx) => {
                     let n = item.weight % item.children.length
                     console.log(n)
                     itms.weight = parseInt(item.weight / item.children.length)
                     if (indx === item.children.length - 1) {
                         console.log(item.weight)
                         itms.weight = itms.weight + n
                     }
                 })

             })
         })
         .catch((res) => {
             //tableLoading 
             tableLoading.value = false
             
             message.error(res);
         });
 }

弹窗加loading

点击确定的时候不能多次点击用:

 <a-spin :spinning="confirmLoading"></a-spin>
<a-modal
    v-model:visible="addVisible"
    :title="submitDialogText === '1' ? '新增体系指标' : '编辑体系指标'"
    :footer="null"
    :afterClose="afterClose"
    :destroyOnClose="true"
    class="ruleFormDialoglist"
    width="80%"
  >
    <a-spin :spinning="confirmLoading">
      <a-form
        ref="ruleForms"
        :model="submitForm"
        :rules="rules"
        :label="{ span: 12, offset: 24 }"
        layout="horizontal"
        style="padding: 0 10px"
        class="ruleFormDialoglist"
      >
        <a-row :gutter="24">
          <a-col :span="24" v-if="searchForm.parentsId">
            <a-form-item label="父级指标名称:" v-if="searchForm.targetName">
              <div>{{ searchForm.targetName }}</div>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item ref="name" label="指标名称:" name="name">
              <a-input
                v-model:value="submitForm.name"
                placeholder="请输入指标名称"
              />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="依据内容:" name="explain" ref="explain">
              <a-textarea
                v-model:value="submitForm.explain"
                placeholder="请输入依据内容"
                allowClear
              />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item ref="enabled" label="状态" name="enabled">
              <a-radio-group
                v-model:value="submitForm.enabled"
                @change="statusChange"
              >
                <a-radio :value="'true'">启用</a-radio>
                <a-radio :value="'false'">停用</a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>
        </a-row>
        <div
          class="footButton"
          v-if="submitDialogText === '1' || submitDialogText === '2'"
        >
          <a-button type="primary" @click="onSubmit">提交</a-button>
          <a-button style="margin-left: 60px" @click="afterClose"
            >取消</a-button
          >
        </div>
      </a-form>
    </a-spin>
  </a-modal>

js:

const addVisible = ref(false);
let submitForm = reactive(submitForms)

//confirmLoading 
const confirmLoading = ref(false)

 // //校验
 const ruleForms = ref();
 let rules = reactive(rule)

 //关闭弹窗之后的回调
 const afterClose = () => {
     addVisible.value = false
     submitForm.name = "";
     submitForm.explain = "";
     submitForm.enabled = "true"
 }

 const statusChange = (e) => {
     console.log(e)
 }
 const addAppraisalTarget = () => {
 
     //confirmLoading 
     confirmLoading.value = true
     
     post(API.ability.addAppraisalTarget, {
             params: {
                 targetTemplateId: router.currentRoute.value.query.id,
                 parentId: searchForm.parentsId,
                 targetName: submitForm.name,
                 gistContent: submitForm.explain,
                 enabled: submitForm.enabled, //数据状态(启用:1或者true,停用:0或者false)
             },
         })
         .then((res) => {
         
         	 //confirmLoading 
             confirmLoading.value = false
             
             message.success('添加成功');
             addVisible.value = false;
             getAppraisalTargetListCreateProject()
         })
         .catch((res) => {
         
             //confirmLoading 
             confirmLoading.value = false
             
             message.error(res);
         });
 }

整个页面加loading

在提交的时候整个页面进行loading,防止多次点击

<a-spin :spinning="spinning"></a-spin>
<template>
  <div class="EvaluatPage">
  
    <a-spin :spinning="spinning">
      <a-tabs v-model:activeKey="activeKey" @change="callback">
        <a-tab-pane
          v-for="item in searchForm.tabList"
          :key="item.appraisalTargetId"
        >
          <template #tab>
            <span>
              {{ item.appraisalTargetName }}
              <CheckOutlined />
            </span>
          </template>

          <a-table
            :columns="columns"
            :data-source="item.tableData"
            :pagination="false"
            rowKey="appraisalTargetId"
          >
            <template #index="{ index }">{{ index + 1 }}</template>
            <template #standard="{ record }">
              <div v-for="(item, index) in record.userList" :key="index">
                {{ item.score + ":" + item.standard }}
              </div>
            </template>
            <template #score="{ record }">
              <a-radio-group
                name="radioGroup"
                v-model:value="record.isSelectId"
              >
                <a-radio
                  :style="radioStyle"
                  :value="item.projectCriteriaId"
                  v-for="(item, index) in record.userList"
                  :key="index"
                  >{{ item.score }}</a-radio
                >
              </a-radio-group>
            </template>
          </a-table>
        </a-tab-pane>
      </a-tabs>
      <div class="footButton" v-if="searchForm.tabList.length !== 0">
        <a-button
          type="primary"
          @click="onSubmitNext"
          v-if="
            searchForm.tabList.length > 0
              ? searchForm.tabList[searchForm.tabList.length - 1]
                  .appraisalTargetId !== activeKey
              : false
          "
          >下一步</a-button
        >
        <a-button type="primary" @click="onSubmit" v-else>提交</a-button>
      </div>
      <div class="footButton footImg" v-if="searchForm.tabList.length === 0">
        <div class="footBigBox">
          <div class="footImgBox"></div>
        </div>
        
        <a-button type="primary" @click="goBack">返回</a-button>
      </div>
    </a-spin>
    
  </div>
</template>

js:

let spinning = ref(false)

//获取上面头部列表
const getDetail = () => {

    spinning.value = true
    
    post(API.ability.selectProjectEvaluationDetailDesc, {
            params: {
                projectEvaluationId: listId.value,
            }
        })
        .then((res) => {
        
            spinning.value = false
            
            console.log(res.data)
            searchForm.tabList = res.data.projectAppraisalTargetDtoList ? res.data.projectAppraisalTargetDtoList.filter(item => {
                return item.isCheck
            }) : []
            searchForm.tabList.forEach(item => {
                item.tableData = []
            })
            if (searchForm.tabList.length > 0) {
                activeKey.value = searchForm.tabList[0].appraisalTargetId
                selectProjectEvaluationDetailCommon()
            }
        })
        .catch((res) => {
        
            spinning.value = false
            
            message.error(res);
        });
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 3中,可以通过在全局注册一个组件来实现全局弹窗的调用。 首先,在main.js或者类似的入口文件中,使用Vue的createApp方法创建一个Vue实例,并将全局组件注册到该实例中。 ```javascript import { createApp } from 'vue' import App from './App.vue' import GlobalDialog from './components/GlobalDialog.vue' const app = createApp(App) // 将全局弹窗组件注册为全局组件 app.component('global-dialog', GlobalDialog) app.mount('#app') ``` 接下来,在需要使用全局弹窗页面组件中,可以直接在模板中使用`<global-dialog>`标签调用全局弹窗组件。 ```html <template> <div> <button @click="openDialog">打开弹窗</button> <global-dialog v-if="showDialog" @close="closeDialog" /> </div> </template> <script> export default { data() { return { showDialog: false } }, methods: { openDialog() { this.showDialog = true }, closeDialog() { this.showDialog = false } } } </script> ``` 在以上示例中,我们首先在页面组件的data选项中定义了一个布尔型的showDialog变量来控制弹窗的显示与隐藏。然后,在openDialog方法中,将showDialog变量设为true,使得弹窗组件显示出来。在closeDialog方法中,将showDialog变量设为false,让弹窗组件隐藏起来。 通过以上的步骤,我们成功实现了在页面中调用全局弹窗组件。每当点击“打开弹窗”按钮时,弹窗组件就会显示出来,点击关闭按钮或其他操作,弹窗组件又会隐藏起来。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值