Traditional task allocation methods are threatened by the complexity and adversarial nature of modern battlefields. This work focuses on the modeling, optimization, and simulation verification of UAV swarm multi-domain fighting under the constraint of task resilience in order to address the issues created by various ways of deliberate enemy attack. Initially, a novel idea of equivalent load is proposed, considering it as the fundamental unit of reconnaissance, assault, communication, and other activities, in order to construct the capability load matrix of our single UAV and the needed load matrix of attacking each fighting unit in each battle region. Then, by integrating the strike probability and task completion degree, the task resilience capability index was developed, which improved the current UAV swarm task resilience measurement process. Due to the difficulty of traditional task allocation optimization methods in dealing with dynamic changes of optimization indexes before and after attacks, a resilience compensation load relaxation variable was added to the traditional Integral Linear Programming (ILP) problem description model of a UAV swarm. On the basis of a bilevel nested structure, a task allocation optimization method is created. Before an assault, the lower layer's ILP optimizer uses the swarm load cost as the target. The uppermost layer is comprised of Particle Swarm Optimization (PSO), which targets the comprehensive indices of UAV swarm load cost and task resilience after attack. It effectively resolves the multi-objective optimization problem of UAV swarms taking task difficulty into account. Ultimately, the test scenarios of three conflict domains, five basic battle units, and five load kinds were constructed, and the Ranchester battle model was used to simulate and validate the rationale and efficacy of the bilevel nested optimization method based on PSO-ILP.