x-select的运用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>window</title>
    <script src="../../../js/tool/jquery-3.3.1.min.js"></script>
    <script src="../../../js/tool/layui/layui.js"></script>
    <script src="../../../js/common.js"></script>
    <script src="../../../js/tool/vue.js"></script>
    <script src="../../../js/tool/xm-select.js"></script>
    <link rel="stylesheet" href="../../../js/tool/layui/css/layui.css">
</head>
<style>
    .layui-btn-sm {
        position: relative;
        top: 2px;
    }
</style>
<body style="padding: 20px">

<h4 style="margin-left: 20px"><span style="color: black"><b>检测名称</b></span></h4>

<div id="app" class="layui-form-select" style="margin-left: 20px"></div>
<div>
    <button type="button" class="layui-btn " id="app-reload" style="margin-left: 20px">数据加载</button>

</div>

<div id="item">
    <div class="tableBar layui-form" style="width:auto;margin-left: 20px;" v-if="iqcCheckContentList!=null">
        <div>
            <table class="layui-table">
                <thead>
                <tr>
                    <th>检测名称</th>
                    <th>是否必检(0是必检,1是选检)</th>
                </tr>
                </thead>

                <tr v-for="(item, index) in iqcCheckContentList">

                    <td>
                        <input class="layui-input" type="text" v-model="item.name"
                               disabled="disabled">
                    </td>

                    <td>
                        <input type="number" class="layui-input" v-model="item.checkStatus">
                    </td>
                </tr>
            </table>
        </div>
        <button type="button" class="layui-btn" @click="doCheck()">确定</button>

    </div>

</div>

</body>
</html>

<script>
    var app = xmSelect.render({
        el: '#app',
        autoRow: true,
        toolbar: {show: true},
        filterable: true,
        remoteSearch: true,
        remoteMethod: function (val, cb, show) {
            //这里如果val为空, 则不触发搜索
            $.ajax({
                url: server + "/iqcBaseData/getAllIqcBaseData",
                method: 'post',
                contentType: 'application/json',
                success: function (res) {
                    if (res.type == 0) {
                        var iqcBaseDataList = res.data
                        var obj = [];
                        iqcBaseDataList.forEach(function (v, i) {
                            obj.push({
                                name: v.checkName,
                                value: v.id
                            });
                        })
                        cb(obj);
                    }
                }
            })
        },
    });
    document.getElementById('app-reload').onclick = function () {
        //获取当前多选选中的值
        var selectArr = app.getValue();
        var data = selectArr
        localStorage.removeItem("iqcBaseData")
        localStorage.setItem("iqcBaseData", JSON.stringify(data))
    };
</script>

<script>
    var item = new Vue({
        el: "#item",
        data: {
            iqcCheckContentList: [],
        },
        methods: {
            setTimer: function () {
                this.timer = setInterval(() => {
                    var parentValue = JSON.parse(localStorage.getItem("iqcBaseData"))

                    if(null==parentValue){
                        return
                    }
                    if (null == this.iqcCheckContentList) {
                        this.iqcCheckContentList = parentValue;
                        return;
                    }
                    var count = 1
                    for (var i = 1; i < parentValue.length; i++) {
                        for (var j = 0; j < this.iqcCheckContentList.length; j++) {
                            if (parentValue[i].name == (this.iqcCheckContentList[j].name)) {
                                count++;
                            }
                        }
                    }
                    if (count != parentValue.length) {
                        this.iqcCheckContentList = parentValue;
                    }
                }, 50);
            },
            doCheck: function () {
                var layer
                layui.use('layer', function () {
                    layer = layui.layer;
                })
                var data = this.iqcCheckContentList;
                var cInvcId = localStorage.getItem("tempData")
                $.ajax({
                    url: server + "/itemCheck/addItemCheckDetailsVersionTwo",
                    method: 'post',
                    data: JSON.stringify({
                        itemDetailsList: data,
                        cInvcId: cInvcId
                    }),
                    contentType: 'application/json',
                    success: function (res) {
                        if (res.type == 0) {
                            item.currentPageClose();
                        }
                        layer.msg(res.msg)
                    }
                })
            },
            //关闭当前页面
            currentPageClose: function () {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);//关闭当前页
            },

        },
        //页面关闭前关闭定时器 (这个才有用) 并且清空缓存
        destroyed: function () {
            console.log("============清空缓存");

            clearInterval(this.timer)
        },
        //页面加载完成后执行方法(启动定时器)
        mounted: function () {
            clearInterval(this.timer)
            this.setTimer()
        },


    });
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我理解了你的问题。我们可以使用Python和遗传算法来寻找函数f(x,y)= x^3 + y^3在[-5,5]区间内的最大值。 首先,我们需要定义一个适应度函数来评估每个个体的表现。在这种情况下,适应度函数应该根据f(x,y)的值来定义。我们可以将适应度函数定义为f(x,y)的值,因为我们想要最大化f(x,y)。 接下来,我们需要生成一个初始种群。我们可以使用随机数生成器在[-5,5]区间内生成一组x和y值来创建不同的个体。 然后,我们可以使用遗传算法的各个组成部分(选择、交叉和变异)对这些个体进行优化,以找到适应度最高的个体。 最后,我们可以输出适应度最高的个体的x和y值,并计算f(x,y)的值。这将是f(x,y)在给定区间[-5,5]内的最大值。 以下是代码示例,你可以参考一下: ```python import random # Define the fitness function def fitness(x, y): return x ** 3 + y ** 3 # Generate an initial population def generate_population(size): population = [] for i in range(size): x = random.uniform(-5, 5) y = random.uniform(-5, 5) population.append((x,y)) return population # Select the fittest individuals def selection(population): return sorted(population, key=lambda x: -fitness(*x))[:len(population)//2] # Crossover the fittest individuals def crossover(parents): children = [] for i in range(len(parents)): parent1 = parents[i] parent2 = parents[(i+1)%len(parents)] child = (parent1[0], parent2[1]) children.append(child) return children # Mutate the offspring def mutate(children, mutation_rate): for i in range(len(children)): if random.random() < mutation_rate: child = children[i] x = child[0] + random.uniform(-1, 1) y = child[1] + random.uniform(-1, 1) children[i] = (x, y) return children # Run the genetic algorithm def genetic_algorithm(population_size, num_generations, mutation_rate): population = generate_population(population_size) for i in range(num_generations): parents = selection(population) children = crossover(parents) children = mutate(children, mutation_rate) population = parents + children fittest = max(population, key=lambda x: fitness(*x)) return fittest # Run the genetic algorithm with a population size of 100, 100 generations, and a mutation rate of 0.1 fittest = genetic_algorithm(100, 100, 0.1) # Print the fittest individual and its fitness score print("Fittest individual:", fittest) print("Fitness score:", fitness(*fittest)) ``` 这段代码将生成一个初始种群,然后使用选择、交叉和变异来优化种群,以找到适应度最高的个体。最后,它将输出适应度最高的个体及其适应度得分,这将是f(x,y)在给定区间[-5,5]内的最大值。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值