微信小程序单双周选择排序有效果图

效果图

请添加图片描述

.wxml

<view class="group-box">
  <label class="radio" wx:for="{{['单周','双周','全选']}}" wx:key="index" bind:tap="radioChange"
  data-index="{{index}}">
      <radio checked="{{index === zcTem.index}}"/>{{item}}
  </label>
</view>
<view class="week-box">
  <view wx:for="{{zcArray}}" wx:key="index" class="week-item {{zcTem.arr[index]?'active':''}}"
  bind:tap="zcSelect" data-index="{{index}}">
    {{item}}
  </view>
</view>
<view class="label">{{zcTem.label}}</view>

.wxss

view{box-sizing: border-box;}
.group-box{
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30rpx 0;
}
.group-box>label{
  display: flex;
  align-items: center;
}
.group-box>label:nth-child(2){
  margin: 0 50rpx;
}
.week-box{
  padding: 0 50rpx;
}
.week-item{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: calc((100% - 64rpx) / 5);
  height: 68rpx;
  margin: 10rpx 0 0 16rpx;
  background-color: #F3F5F7;
  border-radius: 10rpx;
  transition: background-color 0.3s;
}
.week-item:nth-child(5n + 1){
  margin-left: 0;
}
.active{
  background-color:#07C160;
  color: white;
}
.label{
  text-align: center;
  padding: 30rpx;
}

.js

Page({
  data: {
    zcCount:25,
    zcTem:{
      label: '',
      index: -1,
      arr: []
    },
    zcArray:[],
    zcSingle:[],
    zcDouble:[],
  },
  onLoad(){
    const arr = []
    const single = []
    const double = []
    const zcCount = this.data.zcCount
    const zcTem = this.data.zcTem
    for (let i = 1; i <= zcCount; i++) {
      arr.push(`${i}`)
      zcTem.arr.push('')
      if (i % 2 !== 0) {
        single.push(`${i}`)
        double.push('')
        continue
      }
      single.push('')
      double.push(`${i}`)
    }
    this.setData({
      zcTem,
      zcArray:arr,
      zcSingle:single,
      zcDouble:double,
    })
  },
  radioChange(e){
    const index = e.currentTarget.dataset.index
    const o = this.data.zcTem
    if (index === o.index) {
      o.index = -1
      o.label = ''
      o.arr = []
      this.setData({
        zcTem:o,
      })
      return
    }
    o.index = index
    let tem
    if (index === 0) {
      const d = this.data.zcSingle
      o.label = `第${d[0]}-${d[d.length - 1]}周(单周)`
      tem = JSON.stringify(d)
    } else if (index === 1) {
      const d = this.data.zcDouble
      o.label = `第${d[1]}-${d[d.length - 2]}周(双周)`
      tem = JSON.stringify(d)
    } else {
      const d = this.data.zcArray
      o.label = `第1-${d[d.length - 1]}周`
      tem = JSON.stringify(d)
    }
    o.arr = JSON.parse(tem)
    this.setData({
      zcTem:o,
    })
  },
  zcSelect(e){
    const index = e.currentTarget.dataset.index
    const o = this.data.zcTem
    o.arr[index] = o.arr[index] ? '' : `${index + 1}`
    if (JSON.stringify(o.arr) === JSON.stringify(this.data.zcArray)) {
      o.index = 2
      const d = this.data.zcArray
      o.label = `第1-${d[d.length - 1]}周`
      this.setData({
        zcTem:o
      })
      return
    }
    if (JSON.stringify(o.arr) === JSON.stringify(this.data.zcSingle)) {
      o.index = 0
      const d = this.data.zcSingle
      o.label = `第${d[0]}-${d[d.length - 1]}周(单周)`
      this.setData({
        zcTem:o
      })
      return
    }
    if (JSON.stringify(o.arr) === JSON.stringify(this.data.zcDouble)) {
      o.index = 1
      const d = this.data.zcDouble
      o.label = `第${d[1]}-${d[d.length - 2]}周(双周)`
      this.setData({
        zcTem:o
      })
      return
    }
    const len = o.arr.length
    let arr = ''; let start = ''; let end = '周'; let or = 0; let name = ''
    for (let i = 0; i < len; i++) {
      if (o.arr[i]) {
        if (end === '周') {
          name = parseInt(o.arr[i]) % 2 !== 0 ? '单周' : '双周'
          start = arr ? `,第${o.arr[i]}` : `第${o.arr[i]}`
        }
        if (o.arr[i + 1]) {
          if (or === 2) {
            or = 0
            arr += start + end
            start = ''
            end = '周'
            continue
          }
          or = 1
          end = `-${o.arr[i + 1]}周`
          continue
        }
        if (or !== 1 && o.arr[i + 2]) {
          i += 1
          or = 2
          end = `-${o.arr[i + 1]}${name}`
          continue
        }
        i += or === 1 ? 1 : 2
        or = 0
        if (start) {
          arr += start + end
          start = ''
          end = '周'
        }
      }
    }
    o.index = -1
    o.label = arr
    this.setData({
      zcTem:o
    })
  }
})

遇到问题可以看我主页加我Q,很少看博客,对你有帮助别忘记点赞收藏。

<think>嗯,用户想了解如何配置和使用yum源。首先,我需要回忆一下关于yum源的基本知识。记得yum源是软件仓库,用来管理RPM包的安装和依赖关系。配置yum源通常涉及编辑.repo文件,这些文件位于/etc/yum.repos.d/目录下。还有可能涉及到本地源和网络源的配置。 根据用户提供的引用内容,引用[2]提到yum的配置文件分为main和repository部分,main在/etc/yum.conf,而repository在/etc/yum.repos.d/里的各个文件。所以配置的时候需要关注这两个部分。用户可能遇到的问题包括如何创建新的源文件,如何指向本地或网络路径,以及如何处理GPG检查。 用户的问题可能包括步骤不清晰,比如如何挂载ISO镜像来配置本地源。引用[3]中提到了创建local.repo文件,并指定baseurl为file:///路径。这时候需要确保挂载点正确,并且权限设置没问题。另外,可能需要禁用默认的网络源,避免冲突。 用户还可能关心如何测试配置后的yum源是否生效,比如运行yum clean all和yum makecache。此外,常见问题如无法找到包,可能和baseurl的配置错误有关,或者网络源不可达。需要检查URL是否正确,网络连接是否正常。 可能还需要解释不同的源类型,比如本地、网络(如阿里云、清华源),以及如何备份原有的配置文件,避免出错后恢复。引用[1]提到可以将默认文件移到/opt下或重命名,这样可以禁用默认源,避免干扰。 总结下来,回答的结构应该分步骤,包括备份、创建repo文件、配置内容、清理缓存,然后验证。同时,常见问题部分需要列出可能的问题和解决方法,如GPG检查、路径错误等。还要注意使用正确的格式,行内变量用$符号,独立公式用$$,不过这里可能数学公式不多,但需要确保LaTeX正确。</think>### 如何配置和使用yum源? #### 一、yum源的核心配置方法 1. **备份默认源** 操作前建议备份系统原有源配置: ```bash mv /etc/yum.repos.d/*.repo /opt/backup/ # 将默认源文件移动到备份目录 ``` 这是为了防止原有配置与新配置产生冲突[^1]。 2. **本地yum源配置** - **挂载镜像文件** 将CentOS镜像文件挂载到指定目录: ```bash mount -o loop /path/to/CentOS-ISO /mnt/cdrom ``` - **创建配置文件** 新建`/etc/yum.repos.d/local.repo`并写入: ```ini [local-base] name=Local-CentOS-Base baseurl=file:///mnt/cdrom gpgcheck=0 enabled=1 ``` 关键参数说明: - `baseurl`:本地路径使用`file://`协议头[^3] - `gpgcheck=0`表示跳过数字签名验证 3. **网络yum源配置** 以阿里云源为例,创建`/etc/yum.repos.d/aliyun.repo`: ```ini [aliyun-base] name=Aliyun-CentOS-Base baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 enabled=1 ``` 注意:`$releasever`和`$basearch`会自动解析为系统版本和架构[^2] #### 二、关键操作命令 1. **清理缓存并更新** ```bash yum clean all # 清除旧缓存 yum makecache # 生成新缓存 yum repolist all # 验证源状态 ``` 2. **典型使用场景** ```bash yum install httpd -y # 安装软件包 yum update # 更新所有软件 yum search python3 # 搜索软件包 ``` #### 三、常见问题排查 | 问题现象 | 解决方案 | |---------|----------| | `Could not resolve host` | 检查网络连接和`baseurl`地址 | | `Package not found` | 确认仓库是否包含该软件包版本 | | GPG签名校验失败 | 设置`gpgcheck=0`或导入正确密钥 | #### 四、进阶配置技巧 1. **多源优先级控制** 安装`yum-plugin-priorities`插件,在`.repo`文件中添加: ```ini priority=1 # 数字越小优先级越高 ``` 2. **仓库分组管理** 通过`[epel]`、`[docker]`等独立仓库配置实现分类管理
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值