Uncaugh(in promise)TypeError

来源:1-2 【讨论题】对于不断推出的前端新框架,我们应该如何学习?

dofospider

2023-08-16

在一个基于vue3.0的开源框架vue-next-admin里使用cascader组件实现更改节点触发change时间弹出messagebox进一步的对操作进行确认。但是在这里就出现了问题。
浏览器报错
我的后端cascader页面代码是这样的
图片描述
数据结构描述
图片描述
响应函数
图片描述

我在这个问题上困了两天了,翻阅资料大概判断应该问题出在异步操作的时候除了问题,但是没有办准确的描述及解决问题。
我的诉求是,1,请老师指出该代码的具体问题,及错误机理。
2,该问题的详细解决方案。
3,这样的问题如果需要自己解决需要什么知识,学习路线怎样。在咱们慕课需要学那几门课能够达到。

附,整体vue文件。

<template>
  <div class="eqpt-eqptInfo-container">
    <el-card shadow="hover">
        <div class="eqpt-eqptInfo-search mb15">
            <el-form :model="tableData.param" ref="queryRef" :inline="true" label-width="100px">
            <el-row>                
                <el-col :span="8" class="colBlock">
                  <el-form-item label="排序id" prop="listOrder">
                    <el-input
                        v-model="tableData.param.listOrder"
                        placeholder="请输入排序id"
                        clearable                        
                        @keyup.enter.native="eqptInfoList"
                    />                    
                  </el-form-item>
                </el-col>                
                <el-col :span="8" class="colBlock">
                  <el-form-item label="设备名称" prop="eqptName">
                    <el-input
                        v-model="tableData.param.eqptName"
                        placeholder="请输入设备名称"
                        clearable                        
                        @keyup.enter.native="eqptInfoList"
                    />                    
                  </el-form-item>
                </el-col>                
                <el-col :span="8" :class="!showAll ? 'colBlock' : 'colNone'">
                  <el-form-item>
                    <el-button type="primary"  @click="eqptInfoList"><el-icon><ele-Search /></el-icon>搜索</el-button>
                    <el-button  @click="resetQuery(queryRef)"><el-icon><ele-Refresh /></el-icon>重置</el-button>
                    <el-button type="primary" link  @click="toggleSearch">
                      {{ word }}
                      <el-icon v-show="showAll"><ele-ArrowUp/></el-icon>
                      <el-icon v-show="!showAll"><ele-ArrowDown /></el-icon>
                    </el-button>
                  </el-form-item>
                </el-col>                
                <el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
                  <el-form-item label="设备序列号" prop="eqptSerial">
                    <el-input
                        v-model="tableData.param.eqptSerial"
                        placeholder="请输入设备序列号"
                        clearable                        
                        @keyup.enter.native="eqptInfoList"
                    />                    
                  </el-form-item>
                </el-col>                
                <el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
                  <el-form-item label="设备资产标签" prop="eqptAssetTag">
                    <el-input
                        v-model="tableData.param.eqptAssetTag"
                        placeholder="请输入设备资产标签"
                        clearable                        
                        @keyup.enter.native="eqptInfoList"
                    />                    
                  </el-form-item>
                </el-col>                
                <el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
                  <el-form-item label="设备类型" prop="eqptType">
                    <el-select v-model="tableData.param.eqptType" placeholder="请选择设备类型" clearable >
                        <el-option
                            v-for="dict in eqpt_type"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                        />
                    </el-select>
                  </el-form-item>
                </el-col>                
                <el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
                  <el-form-item label="设备所属组织" prop="eqptOrgBelog">
                    <el-select v-model="tableData.param.eqptOrgBelog" placeholder="请选择设备所属组织" clearable  >
                      <el-option                      
                          v-for="item in eqptOrgBelogOptions"                      
                          :key="item.key"
                          :label="item.value"
                          :value="item.key"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>                
                <el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
                  <el-form-item label="设备状态" prop="eqptStatus">
                    <el-select v-model="tableData.param.eqptStatus" placeholder="请选择设备状态" clearable >
                        <el-option
                            v-for="dict in sys_normal_disable"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                        />
                    </el-select>
                  </el-form-item>
                </el-col>                
                <el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
                  <el-form-item label="设备采购时间" prop="eqptPurchaseData">
                    <el-date-picker
                        clearable  style="width: 200px"
                        v-model="tableData.param.eqptPurchaseData"
                        value-format="YYYY-MM-DD"                    
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"                    
                     ></el-date-picker>
                  </el-form-item>
                </el-col>                
                <el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
                  <el-form-item label="设备启用时间" prop="eqptStatData">
                    <el-date-picker
                        clearable  style="width: 200px"
                        v-model="tableData.param.eqptStatData"
                        value-format="YYYY-MM-DD"                    
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"                    
                     ></el-date-picker>
                  </el-form-item>
                </el-col>                
                <el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
                  <el-form-item label="设备报废时间" prop="eqptDisploseData">
                    <el-date-picker
                        clearable  style="width: 200px"
                        v-model="tableData.param.eqptDisploseData"
                        value-format="YYYY-MM-DD"                    
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"                    
                     ></el-date-picker>
                  </el-form-item>
                </el-col>                
                <el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
                  <el-form-item label="设备备注" prop="eqptRemark">
                    <el-input
                        v-model="tableData.param.eqptRemark"
                        placeholder="请输入设备备注"
                        clearable                        
                        @keyup.enter.native="eqptInfoList"
                    />                    
                  </el-form-item>
                </el-col>                
                <el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
                  <el-form-item label="设备创建时间" prop="createdAt">
                    <el-date-picker
                        clearable  style="width: 200px"
                        v-model="tableData.param.createdAt"
                        format="YYYY-MM-DD HH:mm:ss"
                        value-format="YYYY-MM-DD HH:mm:ss"                    
                        type="datetimerange"
                        range-separator="至"
                        start-placeholder="开始时间"
                        end-placeholder="结束时间"                    
                    ></el-date-picker>
                  </el-form-item>
                </el-col>            
                <el-col :span="8" :class="showAll ? 'colBlock' : 'colNone'">
                  <el-form-item>
                    <el-button type="primary"  @click="eqptInfoList"><el-icon><ele-Search /></el-icon>搜索</el-button>
                    <el-button  @click="resetQuery(queryRef)"><el-icon><ele-Refresh /></el-icon>重置</el-button>
                    <el-button type="primary" link  @click="toggleSearch">
                        {{ word }}
                        <el-icon v-show="showAll"><ele-ArrowUp/></el-icon>
                        <el-icon v-show="!showAll"><ele-ArrowDown /></el-icon>
                    </el-button>
                  </el-form-item>
                </el-col>            
              </el-row>
            </el-form>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button
                  type="primary"
                  @click="handleAdd"
                  v-auth="'api/v1/eqpt/eqptInfo/add'"
                ><el-icon><ele-Plus /></el-icon>新增</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button
                  type="success"
                  :disabled="single"
                  @click="handleUpdate(null)"
                  v-auth="'api/v1/eqpt/eqptInfo/edit'"
                ><el-icon><ele-Edit /></el-icon>修改</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button
                  type="danger"
                  :disabled="multiple"
                  @click="handleDelete(null)"
                  v-auth="'api/v1/eqpt/eqptInfo/delete'"
                ><el-icon><ele-Delete /></el-icon>删除</el-button>
              </el-col>
            </el-row>
        </div>
        <el-table v-loading="loading" :data="tableData.data" style="width: 100%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />          
          <el-table-column label="序号" align="center" prop="listOrder"
            min-width="35px"
             />          
          <el-table-column label="设备名称" align="center" prop="eqptName"
            min-width="100px"            
             />
          <el-table-column label="设备资产标签" align="center" prop="eqptAssetTag"
                           min-width="100px"
          />
          <el-table-column align="center" label="设备缩略图"
                           min-width="100px"
          >
            <template #default="scope">
              <el-image
                  style="width: 100px; height: 50px"
                  v-if="!proxy.isEmpty(scope.row.eqptThumb)"
                  :src="proxy.getUpFileUrl(scope.row.eqptThumb)"
                  fit="contain"></el-image>
            </template>
          </el-table-column>
          <el-table-column label="设备类型" align="center" prop="eqptType" :formatter="eqptTypeFormat"
            min-width="100px"            
             />          


          <el-table-column label="设备所属组织2" align="center" prop="eqptOrgBelog.deptId"
                           min-width="100px">
            <template #default="scope">


              <el-cascader
                  :options="deptData"
                  :props="{checkStrictly: true, emitPath: false, value: 'deptId', label: 'deptName', }"
                  :show-all-levels="false"
                  placeholder="请选择设备所属组织"
                  clearable
                  v-model="scope.row.linkedEqptOrgBelog.deptId"
                  @change="handleDeptChange(scope.row)"
                  >

                <template #default="{ node, data }">
                  <span>{{data.deptName}}</span>
                  <span v-if="!node.isLeaf"> ({{data.children.length}})</span>
                ></template>

              </el-cascader>
            </template>
          </el-table-column>







          <el-table-column label="操作人员" align="center" prop="eqptStatus" :formatter="eqptStatusFormat"
            min-width="100px"
             />
         <el-table-column   prop="eqptStatus" label="设备状态" align="center">
          <template #default="scope">
            <el-switch
              v-model="scope.row.eqptStatus"
              inline-prompt
              :active-value="1"
              :inactive-value="0"
              active-text="启"
              inactive-text="禁"
              @change="handleSwitch(scope.row)">

            </el-switch>
          </template>
        </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding" min-width="200px" fixed="right">
            <template #default="scope">            
              <el-button
                type="primary"
                link
                @click="handleView(scope.row)"
                v-auth="'api/v1/eqpt/eqptInfo/get'"
              ><el-icon><ele-View /></el-icon>详情</el-button>              

                <el-button
                  type="primary"
                  link

                  v-auth=""
                ><el-icon><ele-EditPen /></el-icon>IOT</el-button>
              <el-button
                type="primary"
                link
                @click="handleUpdate(scope.row)"
                v-auth=""
              ><el-icon><ele-View /></el-icon>备件</el-button>
              <el-button
                type="primary"
                link
                @click="handleUpdate(scope.row)"
                v-auth=""
              ><el-icon><ele-View /></el-icon>维修知识库</el-button>
              <el-button
                type="primary"
                link
                @click="handleDelete(scope.row)"
                v-auth="'api/v1/eqpt/eqptInfo/delete'"
              ><el-icon><ele-DeleteFilled /></el-icon>删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
            v-show="tableData.total>0"
            :total="tableData.total"
            v-model:page="tableData.param.pageNum"
            v-model:limit="tableData.param.pageSize"
            @pagination="eqptInfoList"
        />
    </el-card>
    <apiV1EqptEqptInfoEdit
       ref="editRef"       
       :eqptTypeOptions="eqpt_type"       
       :eqptOrgBelogOptions="eqptOrgBelogOptions"       
       :eqptStatusOptions="sys_normal_disable"       
       @eqptInfoList="eqptInfoList"
    ></apiV1EqptEqptInfoEdit>
    <apiV1EqptEqptInfoDetail
      ref="detailRef"      
      :eqptTypeOptions="eqpt_type"      
      :eqptOrgBelogOptions="eqptOrgBelogOptions"      
      :eqptStatusOptions="sys_normal_disable"      
      @eqptInfoList="eqptInfoList"
    ></apiV1EqptEqptInfoDetail>
  </div>
</template>
<script lang="ts">
import {ItemOptions} from "/@/api/items";
import {toRefs, reactive, onMounted, ref, defineComponent, computed,getCurrentInstance,toRaw} from 'vue';
import {ElMessageBox, ElMessage, FormInstance} from 'element-plus';
import {
    listEqptInfo,
    getEqptInfo,
    delEqptInfo,
    addEqptInfo,
    updateEqptInfo,    
    linkedDataSearch,
    changeEqptStatus,
    changeEqptDept
} from "/@/api/eqpt/eqptInfo";
import {getDeptTree} from '/@/api/system/user';

import {
    EqptInfoTableColumns,
    EqptInfoInfoData,
    EqptInfoTableDataState,    
    LinkedEqptInfoSysDept,    
} from "/@/views/eqpt/eqptInfo/list/component/model"
import apiV1EqptEqptInfoEdit from "/@/views/eqpt/eqptInfo/list/component/edit.vue"
import apiV1EqptEqptInfoDetail from "/@/views/eqpt/eqptInfo/list/component/detail.vue"
import {pullAllBy} from "lodash";
export default defineComponent({
    name: "apiV1EqptEqptInfoList",
    components:{
        apiV1EqptEqptInfoEdit,
        apiV1EqptEqptInfoDetail
    },
    setup() {
        const {proxy} = <any>getCurrentInstance()
        const loading = ref(false)
        const queryRef = ref()
        const editRef = ref();
        const detailRef = ref();
        // 是否显示所有搜索选项
        const showAll =  ref(false)
        // 非单个禁用
        const single = ref(true)
        // 非多个禁用
        const multiple =ref(true)
        const word = computed(()=>{
            if(showAll.value === false) {
                //对文字进行处理
                return "展开搜索";
            } else {
                return "收起搜索";
            }
        })
        // 字典选项数据        
        const {            
            eqpt_type,            
            sys_normal_disable,            
        } = proxy.useDict(            
            'eqpt_type',            
            'sys_normal_disable',            
        )        
        // eqptOrgBelogOptions关联表数据
        const eqptOrgBelogOptions = ref<Array<ItemOptions>>([])        
        const state = reactive<EqptInfoTableDataState>({
            ids:[],
            tableData: {
                data: [],
                total: 0,
                loading: false,
                param: {
                    pageNum: 1,
                    pageSize: 10,                    
                    listOrder: undefined,                    
                    eqptName: undefined,                    
                    eqptSerial: undefined,                    
                    eqptAssetTag: undefined,                    
                    eqptType: undefined,                    
                    eqptOrgBelog: undefined,                    
                    eqptStatus: undefined,                    
                    eqptPurchaseData: [],                    
                    eqptStatData: [],                    
                    eqptDisploseData: [],                    
                    eqptRemark: undefined,                    
                    createdAt: [],                    
                    createdBy: undefined,                    
                    dateRange: [],

                },

            },
            deptData:[],
        });
        // 页面加载时
        onMounted(() => {
            initTableData();
        });
        // 初始化表格数据
        const initTableData = () => {            
            linkedData();
            eqptInfoList();
        };        
        const linkedData = ()=>{
            linkedDataSearch().then((res:any)=>{                
                //关联sys_dept表选项                
                eqptOrgBelogOptions.value = proxy.setItems(res, 'deptId', 'deptName','linkedEqptInfoSysDept')                
            })
        }


        /** 重置按钮操作 */
        const resetQuery = (formEl: FormInstance | undefined) => {
            if (!formEl) return
            formEl.resetFields()
            eqptInfoList()
        };
        // 获取列表数据
        const eqptInfoList = ()=>{
          loading.value = true
          listEqptInfo(state.tableData.param).then((res:any)=>{
            let list = res.data.list??[];            
            list.map((item:any)=>{                
                item.createdBy = item.createdUser?.userNickname                
            })            
            state.tableData.data = list;
            state.tableData.total = res.data.total;
          });
          getDeptTree().then((res:any)=>{
           state.deptData= res.data.deps;
          });


          loading.value=false;
        };
        const toggleSearch = () => {
            showAll.value = !showAll.value;
        }        
        // 设备类型字典翻译
        const eqptTypeFormat = (row:EqptInfoTableColumns) => {
            return proxy.selectDictLabel(eqpt_type.value, row.eqptType);
        }        
        // 设备状态字典翻译
        const eqptStatusFormat = (row:EqptInfoTableColumns) => {
            return proxy.selectDictLabel(sys_normal_disable.value, row.eqptStatus);
        }        
        // 多选框选中数据
        const handleSelectionChange = (selection:Array<EqptInfoInfoData>) => {
            state.ids = selection.map(item => item.id)
            single.value = selection.length!=1
            multiple.value = !selection.length
        }
        const handleAdd =  ()=>{
            editRef.value.openDialog()
        }
        const handleUpdate = (row: EqptInfoTableColumns) => {
            if(!row){
                row = state.tableData.data.find((item:EqptInfoTableColumns)=>{
                    return item.id ===state.ids[0]
                }) as EqptInfoTableColumns
            }
            editRef.value.openDialog(toRaw(row));
        };
        const handleDelete = (row: EqptInfoTableColumns) => {
            let msg = '你确定要删除所选数据?';
            let id:number[] = [] ;
            if(row){
            msg = `此操作将永久删除数据,是否继续?`
            id = [row.id]
            }else{
            id = state.ids
            }
            if(id.length===0){
                ElMessage.error('请选择要删除的数据。');
                return
            }
            ElMessageBox.confirm(msg, '提示', {
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    delEqptInfo(id).then(()=>{
                        ElMessage.success('删除成功');
                        eqptInfoList();
                    })
                })
                .catch(() => {});
        }
        const handleView = (row:EqptInfoTableColumns)=>{
            detailRef.value.openDialog(toRaw(row));
        }
        const handleSwitch=(row:any)=>{

          let text=row.eqptStatus===1? "启用":"停用";
          ElMessageBox.confirm('确认要'+ text +': ' + row.eqptName + ' 设备吗?', "警告", {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
          }).then(function () {
            return changeEqptStatus(row.id,row.eqptStatus);
          }).then(()=> {
            ElMessage.success(text + '成功');
          }).catch(function () {
            row.eqptStatus = row.eqptStatus === 0 ? 1 : 0;
          });
        };


        const handleDeptChange=(row:any)=> {


          ElMessageBox.confirm('确认要更改'+': ' + row.eqptName + ' 设备吗的归属组织吗?', '警告', {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
          }).then(function () {
            return changeEqptDept(row.id,row.linkedEqptOrgBelog.deptId);
          }).then(()=> {
            ElMessage.success( '成功');
          }).catch(function () {
              ElMessage.success('设备组织更新成功');
          });


        };




        return {
            proxy,
            editRef,
            detailRef,
            showAll,
            loading,
            single,
            multiple,
            word,
            queryRef,
            resetQuery,
            eqptInfoList,
            toggleSearch,            
            eqptTypeFormat,
            eqpt_type,            
            //关联表数据选项
            eqptOrgBelogOptions,            
            eqptStatusFormat,
            sys_normal_disable,            
            handleSelectionChange,
            handleAdd,
            handleUpdate,
            handleDelete,            
            handleView,
            handleSwitch,
            handleDeptChange,
            ...toRefs(state),
        };
    }
});
</script>
<style lang="scss" scoped>
    .colBlock {
        display: block;
    }
    .colNone {
        display: none;
    }
    .ml-2{margin: 3px;}
</style>
写回答

1回答

Dell

2023-08-16

同学你好,非课程内的问题,需要自己解决下。

0
2
Dell
回复
dofospider
你的代码提示已经和明确了,.length 不存在,你看哪里调用 .length,就是那个变量数据不存在造成的报错,所以加一个 ?.length
2023-08-20
共2条回复

Vue3入门与项目实战 掌握完整知识体系

明星讲师DELL亲授,全方位知识点+高匹配度项目,入门到深度掌握

3382 学习 · 1454 问题

查看课程