handleDefaultUseDoc(index) { let {id, documents} = this.travelerForm.travelers[index]; const { transnational } = this.checkList; let flightFlag = true, landFlag = true; if (id) { this.optionalDocument[index].length && this.optionalDocument[index].forEach(item => { if (documents.hasOwnProperty(item)) { this.handleDocClick(item, index); flightFlag = false; } }) this.landOptionalDoc[index].length && this.landOptionalDoc[index].forEach(item => { if (documents.hasOwnProperty(item)) { this.handleLandDoc(item, index); landFlag = false; } }) } if (flightFlag && this.optionalDocument.length && this.optionalDocument[index].length) { transnational ? this.handleDocClick('A', index) : this.handleDocClick(this.optionalDocument[index][0], index); } if (landFlag && this.landOptionalDoc.length && this.landOptionalDoc[index].length) { transnational ? this.handleLandDoc('A', index) : this.handleLandDoc(this.landOptionalDoc[index][0], index); } },
时间: 2024-02-10 14:34:28 浏览: 107
这是一个 JS 函数,函数名为 handleDefaultUseDoc,可能是在 Vue 组件的 methods 选项中定义的。该函数接收一个参数 index,用于表示当前旅客的索引。函数内部主要做以下几件事情:
1. 根据传入的 index,获取该旅客的 id 和 documents。
2. 判断该旅客是否有 id,如果有则遍历 optionalDocument 和 landOptionalDoc 数组,如果 documents 中包含了 optionalDocument 或者 landOptionalDoc 中的某个元素,则调用 handleDocClick 或 handleLandDoc 方法来处理对应文档,并将 flightFlag 或 landFlag 标记为 false。
3. 如果 flightFlag 为 true,且 optionalDocument 数组和该旅客的 optionalDocument 数组都存在且长度大于 0,则根据 transnational 值来调用 handleDocClick 方法处理相应的文档。
4. 如果 landFlag 为 true,且 landOptionalDoc 数组和该旅客的 landOptionalDoc 数组都存在且长度大于 0,则根据 transnational 值来调用 handleLandDoc 方法处理相应的文档。
该函数主要是根据一些条件来给旅客设置默认的文档,具体实现可能需要结合组件中的其他代码进行分析。
相关问题
用c加加写一个基类:过境人员,派生类:游客、卡车司机、商务旅客的长代码,具体要求1.从一个抽象基类和几个非抽象派生类创建一个层次结构。 2.在类描述中包含一个在创建对象后不会改变的唯一数字标识符: 3. 实现所有构造函数、必要的设置和获取方法、析构函数。 4.重载赋值运算符,比较运算符 == 根据你的准则,流输出运算符<<。5.创建一个指向基类的指针数组,填充并对该数组进行一定的操作,以及统计每个类的对象个数。6.基类和派生类的字段的其余组成,以及可执行的对数组的操作要自己想
出来。
以下是一个可能的实现:
```c++
#include <iostream>
#include <string>
class TransitPerson {
public:
TransitPerson(int id) : id_(id) {}
virtual ~TransitPerson() {}
int get_id() const { return id_; }
virtual std::string get_type() const = 0;
virtual void print_info() const {
std::cout << "ID: " << id_ << ", Type: " << get_type() << std::endl;
}
private:
int id_;
};
class Tourist : public TransitPerson {
public:
Tourist(int id, std::string country) : TransitPerson(id), country_(country) {}
std::string get_type() const override { return "Tourist"; }
std::string get_country() const { return country_; }
void print_info() const override {
std::cout << "ID: " << get_id() << ", Type: " << get_type()
<< ", Country: " << country_ << std::endl;
}
private:
std::string country_;
};
class TruckDriver : public TransitPerson {
public:
TruckDriver(int id, std::string license) : TransitPerson(id), license_(license) {}
std::string get_type() const override { return "TruckDriver"; }
std::string get_license() const { return license_; }
void print_info() const override {
std::cout << "ID: " << get_id() << ", Type: " << get_type()
<< ", License: " << license_ << std::endl;
}
private:
std::string license_;
};
class BusinessTraveler : public TransitPerson {
public:
BusinessTraveler(int id, std::string company) : TransitPerson(id), company_(company) {}
std::string get_type() const override { return "BusinessTraveler"; }
std::string get_company() const { return company_; }
void print_info() const override {
std::cout << "ID: " << get_id() << ", Type: " << get_type()
<< ", Company: " << company_ << std::endl;
}
private:
std::string company_;
};
int main() {
const int kNumPersons = 6;
TransitPerson* persons[kNumPersons] = {
new Tourist(1, "USA"),
new Tourist(2, "Japan"),
new TruckDriver(3, "ABC123"),
new TruckDriver(4, "XYZ789"),
new BusinessTraveler(5, "Google"),
new BusinessTraveler(6, "Microsoft")
};
int num_tourists = 0;
int num_truck_drivers = 0;
int num_business_travelers = 0;
for (int i = 0; i < kNumPersons; ++i) {
persons[i]->print_info();
if (Tourist* tourist = dynamic_cast<Tourist*>(persons[i])) {
++num_tourists;
std::cout << "Country: " << tourist->get_country() << std::endl;
} else if (TruckDriver* truck_driver = dynamic_cast<TruckDriver*>(persons[i])) {
++num_truck_drivers;
std::cout << "License: " << truck_driver->get_license() << std::endl;
} else if (BusinessTraveler* business_traveler = dynamic_cast<BusinessTraveler*>(persons[i])) {
++num_business_travelers;
std::cout << "Company: " << business_traveler->get_company() << std::endl;
}
}
std::cout << "Num tourists: " << num_tourists << std::endl;
std::cout << "Num truck drivers: " << num_truck_drivers << std::endl;
std::cout << "Num business travelers: " << num_business_travelers << std::endl;
for (int i = 0; i < kNumPersons; ++i) {
delete persons[i];
}
return 0;
}
```
这个程序定义了一个抽象基类 `TransitPerson`,包含一个唯一的数字标识符 `id_` 和一个纯虚函数 `get_type()`,表示该对象的类型。它还定义了三个派生类 `Tourist`、`TruckDriver` 和 `BusinessTraveler`,它们分别表示游客、卡车司机和商务旅客,每个类都重载了 `get_type()` 函数,返回相应的字符串,并添加了一些特定的字段和方法。
在 `main()` 函数中,我们创建了一个指向 `TransitPerson` 的指针数组 `persons`,并用几个不同的对象填充它。然后我们遍历该数组,对每个对象调用 `print_info()` 函数,打印出该对象的信息,并根据对象的类型统计对象的个数。最后,我们释放了所有的对象。
这个程序演示了如何使用抽象基类和派生类创建一个层次结构,以及如何使用动态类型转换和虚函数来处理不同类型的对象。
阅读全文
相关推荐
















