大图预览不循环 --(自定义大图预览组件)

需求是大图预览禁止循环,开始是用的elementui里面的el-image组件  但是这个组件源码里面的infinite为true是写死的 意味着必定会循环   我也没有找到其他配置方法可以禁止循环。

自定义大图预览组件:

<template>
  <div style="position: relative; overflow: hidden">
    <!--    遮罩层-->
    <div class="mark" style=""></div>
    <!--    主体部分-->
    <div
      class="img_box animated"
      :class="out ? 'zoomIn' : 'zoomOut'"
      @mousewheel="debounce(handleScroll($event), 200)"
    >
      <!-- 右上角关闭按钮 -->
      <div class="close" @click="closeMark">
        <i class="el-icon-close close_btn"></i>
      </div>
      <!--  图片  -->
      <div style="margin: auto; position: relative">
        <img
          width="400px"
          height="680px"
          class="img"
          :style="imgStyle"
          @mousedown.prevent="dropImage"
          :src="img"
          @keyup.left="handleActions('left')"
          @keyup.right="handleActions('right')"
        />
      </div>
      <!--    上一张  -->
      <div class="prev" @mouseover="isShow = true" @mouseleave="isShow = false">
        <i v-if="isShow" class="el-icon-arrow-left prev_img" @click="prevImg(2)"></i>
      </div>
      <!--   下一张-->
      <div class="next" @mouseover="isShow = true" @mouseleave="isShow = false">
        <i v-if="isShow" class="el-icon-arrow-right next_img" @click="nextImg(2)"></i>
      </div>
    </div>
    <!--    图片名字及页数-->
    <div class="pages animated" :class="out ? 'flipInX' : 'zoomOutLeft'">
      <div>{{ nextIndex + 1 }} / {{ images.length }}</div>
    </div>
    <!--    底部操作区-->
    <div class="img_footer animated" :class="out ? 'flipInX' : 'zoomOutLeft'">
      <div class="img_options">
        <!-- <el-tooltip content="图片比例1:1" :open-delay="500" placement="bottom" effect="light">
          <i @click="handleActions('restore')" class="el-icon-c-scale-to-original"></i>
        </el-tooltip> -->
        <el-tooltip content="放大图片" :open-delay="500" placement="bottom" effect="light">
          <i @click="handleActions('zoomIn')" class="el-icon-zoom-in"></i>
        </el-tooltip>
        <el-tooltip content="缩小图片" :open-delay="500" placement="bottom" effect="light">
          <i @click="handleActions('zoomOut')" class="el-icon-zoom-out"></i>
        </el-tooltip>

        <el-tooltip content="逆时针90度" :open-delay="500" placement="bottom" effect="light">
          <i @click="handleActions('refresh-left')" class="el-icon-refresh-left"></i>
        </el-tooltip>
        <el-tooltip content="顺时针90度" :open-delay="500" placement="bottom" effect="light">
          <i @click="handleActions('refresh-right')" class="el-icon-refresh-right"></i>
        </el-tooltip>
        <el-tooltip content="第一张" :open-delay="500" placement="bottom" effect="light">
          <i class="el-icon-d-arrow-left" @click="prevImg(1)"></i>
        </el-tooltip>
        <el-tooltip content="上一张" :open-delay="500" placement="bottom" effect="light">
          <i class="el-icon-arrow-left" @click="prevImg(2)"></i>
        </el-tooltip>
        <el-tooltip content="下一张" :open-delay="500" placement="bottom" effect="light">
          <i class="el-icon-arrow-right" @click="nextImg(2)"></i>
        </el-tooltip>
        <el-tooltip content="最后一张" :open-delay="500" placement="bottom" effect="light">
          <i class="el-icon-d-arrow-right" @click="nextImg(1)"></i>
        </el-tooltip>
        <!-- <el-tooltip content="下载图片" :open-delay="500" placement="bottom" effect="light">
          <i class="el-icon-download" @click="down"></i>
        </el-tooltip> -->
        <el-tooltip content="关闭预览" :open-delay="500" placement="bottom" effect="light">
          <i class="el-icon-circle-close" @click="closeMark"></i>
        </el-tooltip>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    // 接收图片列表 一维数组
    images: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      out: true,
      img: "", // 图片路径
      odiv: null,
      transform: {
        scale: 1,
        degree: 0
      },
      nextIndex: 0, //预览的当前下标
      isShow: true
    };
  },
  created() {
    // console.log(this.images, this.currentIndex, this.nextIndex, "66666666666666");
    if (this.images && this.images.length > 0) {
      this.img = this.images[this.nextIndex];
    }
  },
  watch: {
    images(newVal) {
      this.img = newVal;
    }
  },
  computed: {
    // 是否是第一张
    isFirst() {
      return this.nextIndex === 0;
    },
    // 是否是最后一张
    isLast() {
      return this.nextIndex === this.images.length - 1;
    },
    // 用于计算图片缩小放大样式
    imgStyle() {
      const { scale, degree } = this.transform;
      const style = {
        transform: `scale(${scale}) rotate(${degree}deg)`
      };
      return style;
    }
  },
  methods: {
    nextImg(type) {
      // 点击切换下一张
      if (this.images.length && this.images.length > 1) {
        if (this.isLast) {
          this.$message("这是最后一张啦");
        } else {
          if (type === 2) {
            this.nextIndex += 1;
            this.img = this.images[this.nextIndex];
          } else {
            this.nextIndex = this.images.length - 1;
            this.img = this.images[this.nextIndex];
          }
          this.reset();
        }
      } else {
        this.$message({
          type: "error",
          message: "错误预览!"
        });
      }
    },
    prevImg(type) {
      // 点击切换上一张
      if (this.images.length && this.images.length > 1) {
        if (this.isFirst) {
          this.$message("这就是第一张啦");
        } else {
          if (type === 2) {
            this.nextIndex -= 1;
            this.img = this.images[this.nextIndex];
          } else {
            this.nextIndex = 0;
            this.img = this.images[this.nextIndex];
          }
          this.reset();
        }
      } else {
        this.$message({
          type: "error",
          message: "错误预览!"
        });
      }
    },
    // 防抖,需要的自己调用以下 fn是要执行的函数,delay是延迟时间默认500ms
    debounce(fn, delay = 500) {
      // 是闭包中的
      let timer;
      // 事件调用的函数,相当于obj调用函数
      return function () {
        // 这个if 判断不做也没关系,可直接清空,只有第一次timer非空
        if (timer) {
          clearTimeout(timer);
        }
        timer = setTimeout(() => {
          fn.apply(this, arguments);
          timer = null;
        }, delay);
      };
    },
    reset() {
      // 初始化图片样式
      this.transform = {
        scale: 1,
        degree: 0
      };
    },
    // 拖拽图片
    dropImage(e) {
      if (e === null) {
        return;
      }
      this.odiv = e.target; //获取目标元素
      //算出鼠标相对元素的位置
      let disX = e.clientX - this.odiv.offsetLeft;
      let disY = e.clientY - this.odiv.offsetTop;
      document.onmousemove = s => {
        //鼠标按下并移动的事件
        //用鼠标的位置减去鼠标相对元素的位置,得到元素的位置
        let left = s.clientX - disX;
        let top = s.clientY - disY;
        //移动当前元素
        this.odiv.style.left = left + "px";
        this.odiv.style.top = top + "px";
      };
      document.onmouseup = () => {
        document.onmousemove = null;
        document.onmouseup = null;
      };
    },
    // 关闭预览
    closeMark() {
      this.out = false;
      setTimeout(() => this.$emit("listenChild", false), 500); // 这里延迟是为了执行动画
    },
    // 点击下载
    // down() {
    //   let url = this.images[this.nextIndex];
    //   this.download(url, name);
    // },
    // // 下载  这里是做了非同源跨域处理
    // download(imageSrc, imgName) {
    //   let image = new Image();
    //   // 解决跨域 Canvas 污染问题
    //   image.setAttribute("crossOrigin", "anonymous");
    //   image.onload = function () {
    //     let canvas = document.createElement("canvas");
    //     canvas.width = image.width;
    //     canvas.height = image.height;
    //     let context = canvas.getContext("2d");
    //     context.drawImage(image, 0, 0, image.width, image.height);
    //     let url = canvas.toDataURL("image/png"); //得到图片的base64编码数据
    //     let a = document.createElement("a"); // 生成一个a元素
    //     let event = new MouseEvent("click"); // 创建一个单击事件
    //     a.download = imgName || "photo"; // 设置图片名称
    //     a.href = url; // 将生成的URL设置为a.href属性
    //     a.dispatchEvent(event); // 触发a的单击事件
    //   };
    //   image.src = imageSrc;
    // },
    //判断滚动缩放
    handleScroll(e) {
      let direction = e.deltaY > 0 ? "down" : "up"; //deltaY为正则滚轮向下,为负滚轮向上
      if (direction === "down" && e.deltaY >= 100) {
        //125为用户一次滚动鼠标的wheelDelta的值
        this.handleActions("zoomOut");
      }
      if (direction === "up" && e.deltaY <= -100) {
        this.handleActions("zoomIn");
      }
    },
    // 旋转放大缩小
    handleActions(action) {
      // 放大旋转等操作
      const { zoomRate, rotateDeg, enableTransition } = {
        zoomRate: 0.2,
        rotateDeg: 90,
        enableTransition: true
      };
      const { transform } = this;
      switch (action) {
        case "zoomOut":
          if (transform.scale > 0.2) {
            transform.scale = parseFloat((transform.scale - zoomRate).toFixed(3));
          }
          break;
        case "zoomIn":
          if (transform.scale < 7) {
            transform.scale = parseFloat((transform.scale + zoomRate).toFixed(3));
          }
          break;
        case "refresh-left":
          transform.degree -= rotateDeg;
          break;
        case "refresh-right":
          transform.degree += rotateDeg;
          break;
        case "restore":
          // 恢复1:1
          transform.scale = 1;
          break;
      }
      transform.enableTransition = enableTransition;
    }
  }
};
</script>

<style lang="scss" scoped>
.mark {
  z-index: 1000;
  position: fixed;
  background-color: rgba(3, 3, 3, 1);
  opacity: 0.5;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}
.img_box {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  z-index: 1050;
  display: flex;
}
.img {
  position: relative;
}
.close {
  position: fixed;
  width: 60px;
  height: 60px;
  z-index: 1060;
  top: 0;
  right: 0;
  font-size: 0.3rem;
  color: rgba(255, 255, 255, 0.8);
  background-color: rgba(38, 35, 35, 0.8);
  border-radius: 0 0 0 100%;
  cursor: pointer;
  transition: all 0.5s;
}
.close:hover {
  width: 80px;
  height: 80px;
  font-size: 26px;
}
.close_btn {
  position: fixed;
  top: 15px;
  right: 15px;
}
.img_footer {
  z-index: 1051;
  position: fixed;
  // height: 30px;
  width: 100%;
  background-color: #0a0a0a;
  bottom: 0;
  left: 0;
}
.img_options {
  width: 100%;
  height: 28px;
  background-color: rgba(241, 241, 241, 0.25);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
}
.img_options i {
  width: 20px;
  height: 20px;
  margin: 0 10px;
  transition: all 0.5s;
}
.img_options i:hover {
  color: #ffffff;
  font-size: 28px;
  cursor: pointer;
}
.pages {
  z-index: 1050;
  position: fixed;
  bottom: 1.1rem;
  left: 0;
  height: 60px;
  width: 100px;
  font-size: 26px;
  color: #ffffff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.image_name {
  font-size: 0.18rem;
  color: #ffffff;
}
.next,
.prev {
  position: fixed;
  width: 40px;
  height: 100%;
  font-size: 26px;
  color: #ffffff;
  z-index: 1051;
  display: flex;
  justify-content: center;
  align-items: center;
}
.next {
  right: 0;
}
.prev {
  left: 0;
}
.prev_img,
.next_img {
  color: #ffffff;
  border: 0.0375rem solid #ffffff;
  border-radius: 100%;
  transition: all 0.5s;
  // opacity: 0.3;
}
.prev_img {
  left: 12%;
}
.next_img {
  right: 12%;
}
.prev_img:hover,
.next_img:hover {
  cursor: pointer;
  opacity: 1;
}
</style>

父组件中引入:

<template>
  <div class="subjective container">
    <div class="answer_content">
      <span
        class="answer_item"
        v-for="(item, index) in List"
        :key="index"
        v-if="index < List.length - 1"
      >
        <span class="name">
          <span>{{ item.classNo }}班</span>
          <span>{{ item.name }}</span>
          <span>得分:{{ item.score }}</span>
        </span>
        <img :src="item.pic[0]" alt="" class="images" @click="openShowImage(index, item)" />
      </span>
    </div>
    <!-- 自定义图片预览组件 -->
    <showImg v-if="isShow" @listenChild="listenChild" :images="images[currentIndex]"></showImg>
  </div>
</template>
<script>
import showImg from "./showImage.vue";
import { getSubjectiveDetail } from "@/api/precisionTeaching/examPaper.js";
export default {
  components: { showImg },
  name: "",

  data() {
    return {
      examList: [],
      List: [],
      currentIndex: "",
      images: [],
      isShow: false
    };
  },
  created() {},
  computed: {
    classSeq() {
      return this.$store.state.user.current_class.classSeq;
    },
    grade() {
      return this.$store.state.user.current_class.grade;
    },
    subjectName() {
      return this.$store.state.user.currentSubject.subjectName;
    },
    schoolUid() {
      return this.$store.state.user.teacherInfo.schoolVo.schoolUid;
    },
    watchData() {
      const { classSeq, grade, subjectName, schoolUid } = this;
      return { classSeq, grade, subjectName, schoolUid };
    }
  },
  watch: {
    watchData: {
      handler() {
        this.getExcellentEssay();
      },
      deep: true
    }
  },
  mounted() {
    this.getExcellentEssay();
  },
  methods: {
    // 优秀作答
    getExcellentEssay() {
      getSubjectiveDetail({
        schoolUid: this.schoolUid,
        grade: this.grade,
        classNo: this.classSeq,
        lesson: this.subjectName
      }).then(res => {
        this.examList = res.data.content;
        this.List = this.examList.map(v => {
          return {
            classNo: v.stuclass,
            name: v.stuname,
            score: v.score,
            pic: v.pic.split(";").filter(e => e !== "")
          };
        });
        this.images = this.List.map(item => {
          return item.pic;
        });
        console.log(this.images, " this.images");
      });
    },
    // 监听子组件事件
    listenChild(e) {
      // console.log(e, "e");
      this.isShow = e;
    },
    // 点击学生作答  打开预览
    openShowImage(index, item) {
      this.currentIndex = index;
      this.isShow = true;
    }
  }
};
</script>
<style lang="scss" scoped>
.subjective {
  padding: 0 30px 30px 30px;
  // height: 800px;
  background-color: #fff;
  .answer_content {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    margin-top: 16px;
    width: 100%;
    .answer_item {
      display: flex;
      margin-right: 60px;
      margin-bottom: 28px;
      flex-direction: column;
      justify-content: center;
      &:nth-child(3n) {
        margin-right: 0;
      }

      .name {
        margin-bottom: 5px;
        color: #333333;
        font-weight: 700;
        font-size: 18px;
        span {
          margin-right: 4px;
        }
      }
    }
    .images {
      width: 300px;
      height: 400px;
    }
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
FYCMS是一款具有强大的功能的基于ASP语言的开源内容管理软件,有UTF-8和GB2312两个编码版本,支持ACCESS和MSSQL两种数据库。FYCMS是一款完全开源的程序,都毫无保留的完全开放源代码,用户不需额外安装其他DLL组件,其最大的特点是易用。   系统自带三大模型,系统模型,注册模型,表单模型,让你无顾虑制作属于自己的特色网站。 国内目前为止ASPCMS中唯一支持注册模型的CMS。 FYCMS网站管理系统加入函数接口,如果对ASP熟悉一点的,您还可以自己编写函数来和系统融合,直接调用系统函数,4.0新增自定义表单将提交结果发送到邮箱,专题功能,在线主题,可以轻松下载在线模版,在线插件,心情指数,特别针对SEO优化的内部链接功能,支持伪静态功能,在线主题功能,让新手站长不会标签就可以制作网站。   一、系统特色: 1、独特模型管理。通过模型管理,您可以基于文章系统克隆出不同的模型,使用标签 模板可扩展图片、新闻、文章、下载、Flash...等多个频道。每个模型可以自定义显示添加选项,更为强大的是,您还可以自定义字段管理,可以随时根据需要自己自定义添加、设立、调整需要添加的选项,这些选项可以是文本框、下拉框等,也可以是图片、文件、随机数等。每个模型都具有易用的信息添加系统,简短和完整标题设置、分页设置、TOP设置、热点设置、是否允许评论、关键字、导读、阅读权限等等&hellip;&hellip;不需要您再去二次开发插件。 2、强大标签管理。您只要将这些标签插入到页面需要的位置即可实现相应功能,而这一切不需要您去学ASP语言,因为这一切FYCMS已经为您完成。系统拥有强大的标签自动生成系统,任何您想要实现的功能,例如输出格式(table和div可选)、排序方法、文章属性、文章行距、文章数量、标题字数、日期格式、分隔图片、标题样式等等只需要在后台进行相关设置即可;任何网站所有的输出功能,如栏目文章、图片文章、幻灯片、循环栏目、分页文章、相关文章、网站导航、友情链接等,也只需要在后台进行相关设置即可。同时可以通过自定义标签的使用,创立自己独特标签,来让整个网站更为完善。 3、可选生成格式。整个网站可以快速地、全部生成静态页面,支持动态、纯静态等多种格式发布,易于搜索引擎的快速收录,有效提升网站搜索提名,充分满足您的多样化需要,让您的网站立于不败之地。发布静态站点时可以选择不同的后缀生成名,可分别生成各频道、栏目、网站首页的静态文件,也可以自主设置添加文章时是否同时生成内容页、栏目页和首页。 4、特色会员系统。会员注册采用模型管理方式,您可以根据情况自定义添加不同的注册模型,如普通用户、企业用户等等,每个模型还可以自定义添加不同字段,如籍贯、头像、选项等。各个添加的用户组可以配置不同的权限和计费方式,如扣点数、有效期、无限期等。后台还配有充值卡添加管理功能和用户短信管理功能等。在会员操作前台,会员可以进行续费、交友、投稿等操作。会员管理系统还与流行论坛高度整合,让整个网站与网站论坛完美融合,让您的网站更具竞争力。 5、齐全文章管理。在信息添加管理系统那里,具备齐全的文章管理功能。文章管理、审核、评论管理、tags管理、回收站、栏目添加管理、生成操作等功能一应俱全。集成系统内置了世界著名的开源编辑器FckEditor的HTML在线编辑系统,可在后台选择默认、简洁、超简洁等模式,使编辑文章能所见所得,添加新闻时还可根据分页标签自动分页。   二、其他功能 1、在线系统设置。在系统设置里面可以方便设置站点基本信息、进行管理员管理、日志管理、插件管理、维护数据库等。 2、无限级栏目分类。系统支持无限级分类,添加、修改、删除,操作十分简单方便。 3、多样化的模板管理。页面模板可以在线预览、添加、修改、删除,每个模型、栏目可以绑定不同的模板,让您的网站不再陷入单一化的页面状态,只要您愿意,您的站点绝不可能和其他人的站点有雷同。 4、友情链接系统。可以新增友情链接类别,审核申请的链接,在后台可以统计链接点击次数等。 5、留言系统。对留言进行回复、删除管理。 6、管理员权限分配。管理员分栏目管理员、模型管理员、超级管理员三级,可以给予某个管理员某个栏目的管理、增加、修改、删除、审核中的任一或多个操作权限,将责任细化到每个管理员,再也不用为管理责任不清而烦劳。 7、强大的图片新闻幻灯显示系统,采用FLASH或者纯图片方式,将您的图片文章以融合、百叶窗等多种交替方面幻灯显示,让您的网站与大网站相媲美 8、强大的文章显示功能,文章除了分页、页数统计这些,还拥有上一篇、下一篇提示、点击数、评论留言、查看权限(收费文章)、投稿系统等强大的功能 9、独创的Tags标签,该功能随着系统使用时间的增加,一个真正属于您自己的词库也在慢慢建立。可根据您的需要调用热门Tags,同论坛精华贴一样,让用户快速找到最有用的信息 合肥网络公司发布 10、配套采集功能。系统与ET采集系统无缝整合,提供接口,您可以通过强大的ET采集器将文章采集到FYCMS系统中。 11、超小的程序,仅有1M多点。虽然FYCMS拥有这么多的强大的功能,可是它的体积很小,这显然十分有益于大幅度提高网站的访问速度,非常适宜新站长和空间较小的站长使用,更多功能还有待您去挖掘. 12、免费而强大的后续支持。首先,FYCMS教程丰富。FYCMS虽然易用,但考虑到新人站长们很多并没有接触过网站制作等,所以FYCMS专门组建了视频教程制作小组,将整个FYCMS网站构建流程制作出视频教程,只要会用鼠标、键盘就可以通过视频教程构建出属于自己的网站。其次,FYCMS专属QQ群:41460643无障碍免费为您提供程序使用咨询。 13、Google Sitemaps地图生成操作,生成符合GOOGLE规范的XML格式地图页面。 14、更多的惊喜请在使用中慢慢发掘。   fycms演示站点: 后台:http://demo.fycms.com/admin/ 账号信息:用户名(admin) 密码(admin)   更新说明: 修正会员中心发布文章,批量上传错误 修正内部链接返回链接错误和列表描述错误 修正编辑器在子目录下出现路径错误 修正投稿页面调用错误 修正验证码在高版本谷歌浏览器下不显示错误 修正幻灯片在子目录不显示错误 修正自定义表单提交错误 修正上传图片没有水印的问题 修正搜索关键字无法获取值的错误 修正采集插件,文件内容存储无法获取内容的错误 增加栏目自定义字段可指定显示 更新最新版编辑器 更新普通管理员右侧显示列表

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值