vue实现H5拖拽可视化编辑器

[开源]MIT开源协议,基于Vue3.x可视化拖拽编辑,页面生成工具 基于Vue可视化拖拽编辑,页面生成工具。src / components / sliderassembly / index.vue // 左侧组件大全文件。src / layout / home / index.vue // 编辑页面文件。src / components / componentscom // 左侧组件目录。src / components / rightslider // 右侧组件目录。 阅读详情
AI摘要

介绍一款HTML5可视化编辑器,它是专注于可视化平台的工具,功能强大且高可扩展。该编辑器采用Vue和TypeScript开发,旨在提供简单易用、高效创新的解决方案,专注于研发创新工具。

一款专注可视化平台工具,功能强大,高可扩展的HTML5可视化编辑器,致力于提供一套简单易用、高效创新、无限可能的解决方案。技术栈采用vue和typescript开发, 专注研发创新工具。 

<template>
  <div
    :style="style"
    :class="[{
      [classNameActive]: enabled,
      [classNameDragging]: dragging,
      [classNameResizing]: resizing,
      [classNameDraggable]: draggable,
      [classNameResizable]: resizable
    }, className]"
    @click="$emit('click')"
    @mousedown="elementMouseDown"
    @touchstart="elementTouchDown"
    @contextmenu="onContextMenu">
    <div
      v-for="handle in actualHandles"
      :key="handle"
      :class="[classNameHandle, classNameHandle + '-' + handle]"
      :style="handleStyle(handle)"
      @mousedown.stop.prevent="handleDown(handle, $event)"
      @touchstart.stop.prevent="handleTouchDown(handle, $event)">
      <slot :name="handle"></slot>
    </div>
    <slot></slot>
  </div>
</template>

<script>
import { matchesSelectorToParentElements, getComputedSize, addEvent, removeEvent } from './utils/dom'
import { computeWidth, computeHeight, restrictToBounds, snapToGrid } from './utils/fns'

const events = {
  mouse: {
    start: 'mousedown',
    move: 'mousemove',
    stop: 'mouseup'
  },
  touch: {
    start: 'touchstart',
    move: 'touchmove',
    stop: 'touchend'
  }
}

// 禁止用户选取
const userSelectNone = {
  userSelect: 'none',
  MozUserSelect: 'none',
  WebkitUserSelect: 'none',
  MsUserSelect: 'none'
}
// 用户选中自动
const userSelectAuto = {
  userSelect: 'auto',
  MozUserSelect: 'auto',
  WebkitUserSelect: 'auto',
  MsUserSelect: 'auto'
}

let eventsFor = events.mouse

export default {
  replace: true,
  name: 'draggable-resizable',
  props: {
    rotateZ: {
      type: Number,
      default: 0
    },
    className: {
      type: String,
      default: 'vdr'
    },
    classNameDraggable: {
      type: String,
      default: 'draggable'
    },
    classNameResizable: {
      type: String,
      default: 'resizable'
    },
    classNameDragging: {
      type: String,
      default: 'dragging'
    },
    classNameResizing: {
      type: String,
      default: 'resizing'
    },
    classNameActive: {
      type: String,
      default: 'active'
    },
    classNameHandle: {
      type: String,
      default: 'handle'
    },
    disableUserSelect: {
      type: Boolean,
      default: true
    },
    enableNativeDrag: {
      type: Boolean,
      default: false
    },
    preventDeactivation: {
      type: Boolean,
      default: false
    },
    active: {
      type: Boolean,
      default: false
    },
    draggable: {
      type: Boolean,
      default: true
    },
    resizable: {
      type: Boolean,
      default: true
    },
    // 锁定宽高比
    lockAspectRatio: {
      type: Boolean,
      default: false
    },
    w: {
      type: [Number, String],
      default: 200,
      validator: (val) => {
        if (typeof val === 'number') {
          return val > 0
        }
        return val === 'auto'
      }
    },
    h: {
      type: [Number, String],
      default: 200,
      validator: (val) => {
        if (typeof val === 'number') {
          return val > 0
        }
        return val === 'auto'
      }
    },
    minWidth: {
      type: Number,
      default: 0,
      validator: (val) => val >= 0
    },
    minHeight: {
      type: Number,
      default: 0,
      validator: (val) => val >= 0
    },
    maxWidth: {
      type: Number,
      default: null,
      validator: (val) => val >= 0
    },
    maxHeight: {
      type: Number,
      default: null,
      validator: (val) => val >= 0
    },
    x: {
      type: Number,
      default: 0
    },
    y: {
      type: Number,
      default: 0
    },
    z: {
      type: [String, Number],
      default: 'auto',
      validator: (val) => (typeof val === 'string' ? val === 'auto' : val >= 0)
    },
    handles: {
      type: Array,
      default: () => ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml'],
      validator: (val) => {
        const s = new Set(['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml'])

        return new Set(val.filter(h => s.has(h))).size === val.length
      }
    },
    dragHandle: {
      type: String,
      default: null
    },
    dragCancel: {
      type: String,
      default: null
    },
    axis: {
      type: String,
      default: 'both',
      validator: (val) => ['x', 'y', 'both'].includes(val)
    },
    grid: {
      type: Array,
      default: () => [1, 1]
    },
    parent: {
      type: [Boolean, String],
      default: false
    },
    onDragStart: {
      type: Function,
      default: () => true
    },
    onDrag: {
      type: Function,
      default: () => true
    },
    onResizeStart: {
      type: Function,
      default: () => true
    },
    onResize: {
      type: Function,
      default: () => true
    },
    // 冲突检测
    isConflictCheck: {
      type: Boolean,
      default: false
    },
    // 元素对齐
    snap: {
      type: Boolean,
      default: false
    },
    // 当调用对齐时,用来设置组件与组件之间的对齐距离,以像素为单位
    snapTolerance: {
      type: Number,
      default: 5,
      validator: function (val) {
        return typeof val === 'number'
      }
    },

    // 缩放比例
    scaleRatio: {
      type: Number,
      default: 1,
      validator: (val) => typeof val === 'number'
    },

    // handle是否缩放
    handleInfo: {
      type: Object,
      default: () => {
        return {
          size: 8,
          offset: -5,
          switch: true
        }
      }
    }
  },

  data: function () {
    return {
      left: this.x,
      top: this.y,
      right: null,
      bottom: null,

      width: null,
      height: null,
      widthTouched: false,
      heightTouched: false,
      aspectFactor: null,

      parentWidth: null,
      parentHeight: null,

      minW: this.minWidth,
      minH: this.minHeight,

      maxW: this.maxWidth,
      maxH: this.maxHeight,

      handle: null,
      enabled: this.active,
      resizing: false,
      dragging: false,
      zIndex: this.z
    }
  },

  created: function () {
    // eslint-disable-next-line 无效的prop:minWidth不能大于maxWidth
    if (this.maxWidth && this.minWidth > this.maxWidth) console.warn('[Vdr warn]: Invalid prop: minWidth cannot be greater than maxWidth')
    // eslint-disable-next-line 无效prop:minHeight不能大于maxHeight'
    if (this.maxWidth && this.minHeight > this.maxHeight) console.warn('[Vdr warn]: Invalid prop: minHeight cannot be greater than maxHeight')

    this.resetBoundsAndMouseState()
  },
  mounted: function () {
    if (!this.enableNativeDrag) {
      this.$el.ondragstart = () => false
    }

    const [parentWidth, parentHeight] = this.getParentSize()

    this.parentWidth = parentWidth
    this.parentHeight = parentHeight
    const [width, height] = getComputedSize(this.$el)
    this.aspectFactor = (this.w !== 'auto' ? this.w : width) / (this.h !== 'auto' ? this.h : height)
    this.width = this.w !== 'auto' ? this.w : width
    this.height = this.h !== 'auto' ? this.h : height
    this.right = this.parentWidth - this.width - this.left
    this.bottom = this.parentHeight - this.height - this.top

    this.settingAttribute()

    // 优化:取消选中的行为优先绑定在父节点上
    const parentElement = this.$el.parentNode
    addEvent(parentElement || document.documentElement, 'mousedown', this.deselect)
    addEvent(parentElement || document.documentElement, 'touchend touchcancel', this.deselect)

    addEvent(window, 'resize', this.checkParentSize)
  },
  beforeDestroy: function () {
    removeEvent(document.documentElement, 'mousedown', this.deselect)
    removeEvent(document.documentElement, 'touchstart', this.handleUp)
    removeEvent(document.documentElement, 'mousemove', this.move)
    removeEvent(document.documentElement, 'touchmove', this.move)
    removeEvent(document.documentElement, 'mouseup', this.handleUp)
    removeEvent(document.documentElement, 'touchend touchcancel', this.deselect)

    removeEvent(window, 'resize', this.checkParentSize)
  },

  methods: {
    // 右键菜单
    onContextMenu (e) {
      this.$emit('contextmenu', e)
    },
    // 重置边界和鼠标状态
    resetBoundsAndMouseState () {
      this.mouseClickPosition = { mouseX: 0, mouseY: 0, x: 0, y: 0, w: 0, h: 0 }

      this.bounds = {
        minLeft: null,
        maxLeft: null,
        minRight: null,
        maxRight: null,
        minTop: null,
        maxTop: null,
        minBottom: null,
        maxBottom: null
      }
    },
    // 检查父元素大小
    checkParentSize () {
      if (this.parent) {
        const [newParentWidth, newParentHeight] = this.getParentSize()
        // 修复父元素改变大小后,组件resizing时活动异常
        this.right = newParentWidth - this.width - this.left
        this.bottom = newParentHeight - this.height - this.top

        this.parentWidth = newParentWidth
        this.parentHeight = newParentHeight
      }
    },
    // 获取父元素大小
    getParentSize () {
      if (this.parent === true) {
        const style = window.getComputedStyle(this.$el.parentNode, null)
        return [
          parseInt(style.getPropertyValue('width'), 10),
          parseInt(style.getPropertyValue('height'), 10)
        ]
      }
      if (typeof this.parent === 'string') {
        const parentNode = document.querySelector(this.parent)
        if (!(parentNode instanceof HTMLElement)) {
          throw new Error(`The selector ${this.parent} does not match any element`)
        }
        return [parentNode.offsetWidth, parentNode.offsetHeight]
      }

      return [null, null]
    },
    // 元素触摸按下
    elementTouchDown (e) {
      eventsFor = events.touch
      this.elementDown(e)
    },
    elementMouseDown (e) {
      eventsFor = events.mouse
      this.elementDown(e)
    },
    // 元素按下
    elementDown (e) {
      if (e instanceof MouseEvent && e.which !== 1) {
        return
      }
      const target = e.target || e.srcElement
      if (this.$el.contains(target)) {
        if (this.onDragStart(e) === false) {
          return
        }
        if (
          (this.dragHandle && !matchesSelectorToParentElements(target, this.dragHandle, this.$el)) ||
          (this.dragCancel && matchesSelectorToParentElements(target, this.dragCancel, this.$el))
        ) {
          this.dragging = false
          return
        }
        if (!this.enabled) {
          this.enabled = true
          this.$emit('activated')
          this.$emit('update:active', true)
        }
        if (this.draggable) {
          this.dragging = true
        }
        this.mouseClickPosition.mouseX = e.touches ? e.touches[0].pageX : e.pageX
        this.mouseClickPosition.mouseY = e.touches ? e.touches[0].pageY : e.pageY
        this.mouseClickPosition.left = this.left
        this.mouseClickPosition.right = this.right
        this.mouseClickPosition.top = this.top
        this.mouseClickPosition.bottom = this.bottom
        this.mouseClickPosition.w = this.width
        this.mouseClickPosition.h = this.height
        if (this.parent) {
          this.bounds = this.calcDragLimits()
        }
        addEvent(document.documentElement, eventsFor.move, this.move)
        addEvent(document.documentElement, eventsFor.stop, this.handleUp)
      }
    },
    // 计算移动范围
    calcDragLimits () {
      return {
        minLeft: this.left % this.grid[0],
        maxLeft: Math.floor((this.parentWidth - this.width - this.left) / this.grid[0]) * this.grid[0] + this.left,
        minRight: this.right % this.grid[0],
        maxRight: Math.floor((this.parentWidth - this.width - this.right) / this.grid[0]) * this.grid[0] + this.right,
        minTop: this.top % this.grid[1],
        maxTop: Math.floor((this.parentHeight - this.height - this.top) / this.grid[1]) * this.grid[1] + this.top,
        minBottom: this.bottom % this.grid[1],
        maxBottom: Math.floor((this.parentHeight - this.height - this.bottom) / this.grid[1]) * this.grid[1] + this.bottom
      }
    },
    // 取消
    deselect (e) {
      const target = e.target || e.srcElement
      const regex = new RegExp(this.className + '-([trmbl]{2})', '')

      if (!this.$el.contains(target) && !regex.test(target.className)) {
        if (this.enabled && !this.preventDeactivation) {
          this.enabled = false

          this.$emit('deactivated')
          this.$emit('update:active', false)
        }

        removeEvent(document.documentElement, eventsFor.move, this.handleResize)
      }

      this.resetBoundsAndMouseState()
    },
    // 控制柄触摸按下
    handleTouchDown (handle, e) {
      eventsFor = events.touch

      this.handleDown(handle, e)
    },
    // 控制柄按下
    handleDown (handle, e) {
      if (e instanceof MouseEvent && e.which !== 1) {
        return
      }

      if (this.onResizeStart(handle, e) === false) {
        return
      }

      if (e.stopPropagation) e.stopPropagation()

      // Here we avoid a dangerous recursion by faking
      // corner handles as middle handles
      if (this.lockAspectRatio && !handle.includes('m')) {
        this.handle = 'm' + handle.substring(1)
      } else {
        this.handle = handle
      }

      this.resizing = true

      this.mouseClickPosition.mouseX = e.touches ? e.touches[0].pageX : e.pageX
      this.mouseClickPosition.mouseY = e.touches ? e.touches[0].pageY : e.pageY
      this.mouseClickPosition.left = this.left
      this.mouseClickPosition.right = this.right
      this.mouseClickPosition.top = this.top
      this.mouseClickPosition.bottom = this.bottom
      this.mouseClickPosition.w = this.width
      this.mouseClickPosition.h = this.height

      this.bounds = this.calcResizeLimits()

      addEvent(document.documentElement, eventsFor.move, this.handleResize)
      addEvent(document.documentElement, eventsFor.stop, this.handleUp)
    },
    // 计算调整大小范围
    calcResizeLimits () {
      let minW = this.minW
      let minH = this.minH
      let maxW = this.maxW
      let maxH = this.maxH

      const aspectFactor = this.aspectFactor
      const [gridX, gridY] = this.grid
      const width = this.width
      const height = this.height
      const left = this.left
      const top = this.top
      const right = this.right
      const bottom = this.bottom

      if (this.lockAspectRatio) {
        if (minW / minH > aspectFactor) {
          minH = minW / aspectFactor
        } else {
          minW = aspectFactor * minH
        }

        if (maxW && maxH) {
          maxW = Math.min(maxW, aspectFactor * maxH)
          maxH = Math.min(maxH, maxW / aspectFactor)
        } else if (maxW) {
          maxH = maxW / aspectFactor
        } else if (maxH) {
          maxW = aspectFactor * maxH
        }
      }

      maxW = maxW - (maxW % gridX)
      maxH = maxH - (maxH % gridY)

      const limits = {
        minLeft: null,
        maxLeft: null,
        minTop: null,
        maxTop: null,
        minRight: null,
        maxRight: null,
        minBottom: null,
        maxBottom: null
      }

      if (this.parent) {
        limits.minLeft = left % gridX
        limits.maxLeft = left + Math.floor((width - minW) / gridX) * gridX
        limits.minTop = top % gridY
        limits.maxTop = top + Math.floor((height - minH) / gridY) * gridY
        limits.minRight = right % gridX
        limits.maxRight = right + Math.floor((width - minW) / gridX) * gridX
        limits.minBottom = bottom % gridY
        limits.maxBottom = bottom + Math.floor((height - minH) / gridY) * gridY

        if (maxW) {
          limits.minLeft = Math.max(limits.minLeft, this.parentWidth - right - maxW)
          limits.minRight = Math.max(limits.minRight, this.parentWidth - left - maxW)
        }

        if (maxH) {
          limits.minTop = Math.max(limits.minTop, this.parentHeight - bottom - maxH)
          limits.minBottom = Math.max(limits.minBottom, this.parentHeight - top - maxH)
        }

        if (this.lockAspectRatio) {
          limits.minLeft = Math.max(limits.minLeft, left - top * aspectFactor)
          limits.minTop = Math.max(limits.minTop, top - left / aspectFactor)
          limits.minRight = Math.max(limits.minRight, right - bottom * aspectFactor)
          limits.minBottom = Math.max(limits.minBottom, bottom - right / aspectFactor)
        }
      } else {
        limits.minLeft = null
        limits.maxLeft = left + Math.floor((width - minW) / gridX) * gridX
        limits.minTop = null
        limits.maxTop = top + Math.floor((height - minH) / gridY) * gridY
        limits.minRight = null
        limits.maxRight = right + Math.floor((width - minW) / gridX) * gridX
        limits.minBottom = null
        limits.maxBottom = bottom + Math.floor((height - minH) / gridY) * gridY

        if (maxW) {
          limits.minLeft = -(right + maxW)
          limits.minRight = -(left + maxW)
        }

        if (maxH) {
          limits.minTop = -(bottom + maxH)
          limits.minBottom = -(top + maxH)
        }

        if (this.lockAspectRatio && (maxW && maxH)) {
          limits.minLeft = Math.min(limits.minLeft, -(right + maxW))
          limits.minTop = Math.min(limits.minTop, -(maxH + bottom))
          limits.minRight = Math.min(limits.minRight, -left - maxW)
          limits.minBottom = Math.min(limits.minBottom, -top - maxH)
        }
      }

      return limits
    },
    // 移动
    move (e) {
      if (this.resizing) {
        this.handleResize(e)
      } else if (this.dragging) {
        this.handleDrag(e)
      }
    },
    // 元素移动
    async handleDrag  (e) {
      const axis = this.axis
      const grid = this.grid
      const bounds = this.bounds
      const mouseClickPosition = this.mouseClickPosition

      const tmpDeltaX = axis && axis !== 'y' ? mouseClickPosition.mouseX - (e.touches ? e.touches[0].pageX : e.pageX) : 0
      const tmpDeltaY = axis && axis !== 'x' ? mouseClickPosition.mouseY - (e.touches ? e.touches[0].pageY : e.pageY) : 0

      const [deltaX, deltaY] = snapToGrid(grid, tmpDeltaX, tmpDeltaY, this.scaleRatio)

      const left = restrictToBounds(mouseClickPosition.left - deltaX, bounds.minLeft, bounds.maxLeft)
      const top = restrictToBounds(mouseClickPosition.top - deltaY, bounds.minTop, bounds.maxTop)
      if (this.onDrag(left, top) === false) {
        return
      }
      const right = restrictToBounds(mouseClickPosition.right + deltaX, bounds.minRight, bounds.maxRight)
      const bottom = restrictToBounds(mouseClickPosition.bottom + deltaY, bounds.minBottom, bounds.maxBottom)
      this.left = left
      this.top = top
      this.right = right
      this.bottom = bottom

      await this.snapCheck()
      this.$emit('dragging', {left: this.left, top: this.top})
    },
    moveHorizontally (val) {
      const [deltaX, _] = snapToGrid(this.grid, val, this.top, this.scale)
      const left = restrictToBounds(deltaX, this.bounds.minLeft, this.bounds.maxLeft)
      this.left = left
      this.right = this.parentWidth - this.width - left
    },
    moveVertically (val) {
      const [_, deltaY] = snapToGrid(this.grid, this.left, val, this.scale)
      const top = restrictToBounds(deltaY, this.bounds.minTop, this.bounds.maxTop)
      this.top = top
      this.bottom = this.parentHeight - this.height - top
    },
    // 控制柄移动
    handleResize (e) {
      let left = this.left
      let top = this.top
      let right = this.right
      let bottom = this.bottom

      const mouseClickPosition = this.mouseClickPosition
      const lockAspectRatio = this.lockAspectRatio
      const aspectFactor = this.aspectFactor

      const tmpDeltaX = mouseClickPosition.mouseX - (e.touches ? e.touches[0].pageX : e.pageX)
      const tmpDeltaY = mouseClickPosition.mouseY - (e.touches ? e.touches[0].pageY : e.pageY)

      if (!this.widthTouched && tmpDeltaX) {
        this.widthTouched = true
      }
      if (!this.heightTouched && tmpDeltaY) {
        this.heightTouched = true
      }
      const [deltaX, deltaY] = snapToGrid(this.grid, tmpDeltaX, tmpDeltaY, this.scaleRatio)

      if (this.handle.includes('b')) {
        bottom = restrictToBounds(
          mouseClickPosition.bottom + deltaY,
          this.bounds.minBottom,
          this.bounds.maxBottom
        )
        if (this.lockAspectRatio && this.resizingOnY) {
          right = this.right - (this.bottom - bottom) * aspectFactor
        }
      } else if (this.handle.includes('t')) {
        top = restrictToBounds(
          mouseClickPosition.top - deltaY,
          this.bounds.minTop,
          this.bounds.maxTop
        )
        if (this.lockAspectRatio && this.resizingOnY) {
          left = this.left - (this.top - top) * aspectFactor
        }
      }

      if (this.handle.includes('r')) {
        right = restrictToBounds(
          mouseClickPosition.right + deltaX,
          this.bounds.minRight,
          this.bounds.maxRight
        )
        if (this.lockAspectRatio && this.resizingOnX) {
          bottom = this.bottom - (this.right - right) / aspectFactor
        }
      } else if (this.handle.includes('l')) {
        left = restrictToBounds(
          mouseClickPosition.left - deltaX,
          this.bounds.minLeft,
          this.bounds.maxLeft
        )
        if (this.lockAspectRatio && this.resizingOnX) {
          top = this.top - (this.left - left) / aspectFactor
        }
      }

      const width = computeWidth(this.parentWidth, left, right)
      const height = computeHeight(this.parentHeight, top, bottom)
      if (this.onResize(this.handle, left, top, width, height) === false) {
        return
      }
      this.left = left
      this.top = top
      this.right = right
      this.bottom = bottom
      this.width = width
      this.height = height
      this.$emit('resizing', {left: this.left, top: this.top, width: this.width, height: this.height})
    },
    changeWidth (val) {
      const [newWidth, _] = snapToGrid(this.grid, val, 0, this.scale)
      let right = restrictToBounds(
        (this.parentWidth - newWidth - this.left),
        this.bounds.minRight,
        this.bounds.maxRight
      )
      let bottom = this.bottom
      if (this.lockAspectRatio) {
        bottom = this.bottom - (this.right - right) / this.aspectFactor
      }
      const width = computeWidth(this.parentWidth, this.left, right)
      const height = computeHeight(this.parentHeight, this.top, bottom)
      this.right = right
      this.bottom = bottom
      this.width = width
      this.height = height
    },
    changeHeight (val) {
      const [_, newHeight] = snapToGrid(this.grid, 0, val, this.scale)
      let bottom = restrictToBounds(
        (this.parentHeight - newHeight - this.top),
        this.bounds.minBottom,
        this.bounds.maxBottom
      )
      let right = this.right
      if (this.lockAspectRatio) {
        right = this.right - (this.bottom - bottom) * this.aspectFactor
      }
      const width = computeWidth(this.parentWidth, this.left, right)
      const height = computeHeight(this.parentHeight, this.top, bottom)
      this.right = right
      this.bottom = bottom
      this.width = width
      this.height = height
    },
    // 从控制柄松开
    async handleUp (e) {
      this.handle = null
      // 初始化辅助线数据
      const temArr = new Array(3).fill({ display: false, position: '', origin: '', lineLength: '' })
      const refLine = { vLine: [], hLine: [] }
      for (let i in refLine) { refLine[i] = JSON.parse(JSON.stringify(temArr)) }

      if (this.resizing) {
        this.resizing = false
        await this.conflictCheck()
        this.$emit('refLineParams', refLine)
        this.$emit('resizestop', this.left, this.top, this.width, this.height)
      }
      if (this.dragging) {
        this.dragging = false
        await this.conflictCheck()
        this.$emit('refLineParams', refLine)
        this.$emit('dragstop', this.left, this.top)
      }
      this.resetBoundsAndMouseState()
      removeEvent(document.documentElement, eventsFor.move, this.handleResize)
    },
    // 设置属性
    settingAttribute () {
      // 设置冲突检测
      this.$el.setAttribute('data-is-check', `${this.isConflictCheck}`)
      // 设置对齐元素
      this.$el.setAttribute('data-is-snap', `${this.snap}`)
    },
    // 冲突检测
    conflictCheck () {
      const top = this.top
      const left = this.left
      const width = this.width
      const height = this.height

      if (this.isConflictCheck) {
        const nodes = this.$el.parentNode.childNodes // 获取当前父节点下所有子节点
        for (let item of nodes) {
          if (item.className !== undefined && !item.className.includes(this.classNameActive) && item.getAttribute('data-is-check') !== null && item.getAttribute('data-is-check') !== 'false') {
            const tw = item.offsetWidth
            const th = item.offsetHeight
            // 正则获取left与right
            let [tl, tt] = this.formatTransformVal(item.style.transform)

            // 左上角与右下角重叠
            const tfAndBr = (top >= tt && left >= tl && tt + th > top && tl + tw > left) || (top <= tt && left < tl && top + height > tt && left + width > tl)
            // 右上角与左下角重叠
            const brAndTf = (left <= tl && top >= tt && left + width > tl && top < tt + th) || (top < tt && left > tl && top + height > tt && left < tl + tw)
            // 下边与上边重叠
            const bAndT = (top <= tt && left >= tl && top + height > tt && left < tl + tw) || (top >= tt && left <= tl && top < tt + th && left > tl + tw)
            // 上边与下边重叠(宽度不一样)
            const tAndB = (top <= tt && left >= tl && top + height > tt && left < tl + tw) || (top >= tt && left <= tl && top < tt + th && left > tl + tw)
            // 左边与右边重叠
            const lAndR = (left >= tl && top >= tt && left < tl + tw && top < tt + th) || (top > tt && left <= tl && left + width > tl && top < tt + th)
            // 左边与右边重叠(高度不一样)
            const rAndL = (top <= tt && left >= tl && top + height > tt && left < tl + tw) || (top >= tt && left <= tl && top < tt + th && left + width > tl)

            // 如果冲突,就将回退到移动前的位置
            if (tfAndBr || brAndTf || bAndT || tAndB || lAndR || rAndL) {
              this.top = this.mouseClickPosition.top
              this.left = this.mouseClickPosition.left
              this.right = this.mouseClickPosition.right
              this.bottom = this.mouseClickPosition.bottom
              this.width = this.mouseClickPosition.w
              this.height = this.mouseClickPosition.h
              this.$emit('resizing', this.left, this.top, this.width, this.height)
            }
          }
        }
      }
    },
    // 检测对齐元素
    async snapCheck () {
      let width = this.width
      let height = this.height
      if (this.snap) {
        let activeLeft = this.left
        let activeRight = this.left + width
        let activeTop = this.top
        let activeBottom = this.top + height

        // 初始化辅助线数据
        const temArr = new Array(3).fill({ display: false, position: '', origin: '', lineLength: '' })
        const refLine = { vLine: [], hLine: [] }
        for (let i in refLine) { refLine[i] = JSON.parse(JSON.stringify(temArr)) }

        // 获取当前父节点下所有子节点
        const nodes = this.$el.parentNode.childNodes

        let tem = {
          value: { x: [[], [], []], y: [[], [], []] },
          display: [],
          position: []
        }
        const { groupWidth, groupHeight, groupLeft, groupTop, bln } = await this.getActiveAll(nodes)
        if (!bln) {
          width = groupWidth
          height = groupHeight
          activeLeft = groupLeft
          activeRight = groupLeft + groupWidth
          activeTop = groupTop
          activeBottom = groupTop + groupHeight
        }
        for (let item of nodes) {
          if (item.className !== undefined && !item.className.includes(this.classNameActive) && item.getAttribute('data-is-snap') !== null && item.getAttribute('data-is-snap') !== 'false') {
            const w = item.offsetWidth
            const h = item.offsetHeight
            const [l, t] = this.formatTransformVal(item.style.transform)
            const r = l + w // 对齐目标right
            const b = t + h // 对齐目标的bottom

            const hc = Math.abs((activeTop + height / 2) - (t + h / 2)) <= this.snapTolerance // 水平中线
            const vc = Math.abs((activeLeft + width / 2) - (l + w / 2)) <= this.snapTolerance // 垂直中线

            const ts = Math.abs(t - activeBottom) <= this.snapTolerance // 从上到下
            const TS = Math.abs(b - activeBottom) <= this.snapTolerance // 从上到下
            const bs = Math.abs(t - activeTop) <= this.snapTolerance // 从下到上
            const BS = Math.abs(b - activeTop) <= this.snapTolerance // 从下到上

            const ls = Math.abs(l - activeRight) <= this.snapTolerance // 外左
            const LS = Math.abs(r - activeRight) <= this.snapTolerance // 外左
            const rs = Math.abs(l - activeLeft) <= this.snapTolerance // 外右
            const RS = Math.abs(r - activeLeft) <= this.snapTolerance // 外右

            tem['display'] = [ts, TS, bs, BS, hc, hc, ls, LS, rs, RS, vc, vc]
            tem['position'] = [t, b, t, b, t + h / 2, t + h / 2, l, r, l, r, l + w / 2, l + w / 2]

            // fix:中线自动对齐,元素可能超过父元素边界的问题
            if (ts) {
              if (bln) {
                this.top = Math.max(t - height, this.bounds.minTop)
                this.bottom = this.parentHeight - this.top - height
              }
              tem.value.y[0].push(l, r, activeLeft, activeRight)
            }
            if (bs) {
              if (bln) {
                this.top = t
                this.bottom = this.parentHeight - this.top - height
              }
              tem.value.y[0].push(l, r, activeLeft, activeRight)
            }
            if (TS) {
              if (bln) {
                this.top = Math.max(b - height, this.bounds.minTop)
                this.bottom = this.parentHeight - this.top - height
              }
              tem.value.y[1].push(l, r, activeLeft, activeRight)
            }
            if (BS) {
              if (bln) {
                this.top = b
                this.bottom = this.parentHeight - this.top - height
              }
              tem.value.y[1].push(l, r, activeLeft, activeRight)
            }

            if (ls) {
              if (bln) {
                this.left = Math.max(l - width, this.bounds.minLeft)
                this.right = this.parentWidth - this.left - width
              }
              tem.value.x[0].push(t, b, activeTop, activeBottom)
            }
            if (rs) {
              if (bln) {
                this.left = l
                this.right = this.parentWidth - this.left - width
              }
              tem.value.x[0].push(t, b, activeTop, activeBottom)
            }
            if (LS) {
              if (bln) {
                this.left = Math.max(r - width, this.bounds.minLeft)
                this.right = this.parentWidth - this.left - width
              }
              tem.value.x[1].push(t, b, activeTop, activeBottom)
            }
            if (RS) {
              if (bln) {
                this.left = r
                this.right = this.parentWidth - this.left - width
              }
              tem.value.x[1].push(t, b, activeTop, activeBottom)
            }

            if (hc) {
              if (bln) {
                this.top = Math.max(t + h / 2 - height / 2, this.bounds.minTop)
                this.bottom = this.parentHeight - this.top - height
              }
              tem.value.y[2].push(l, r, activeLeft, activeRight)
            }
            if (vc) {
              if (bln) {
                this.left = Math.max(l + w / 2 - width / 2, this.bounds.minLeft)
                this.right = this.parentWidth - this.left - width
              }
              tem.value.x[2].push(t, b, activeTop, activeBottom)
            }
            // 辅助线坐标与是否显示(display)对应的数组,易于循环遍历
            const arrTem = [0, 1, 0, 1, 2, 2, 0, 1, 0, 1, 2, 2]
            for (let i = 0; i <= arrTem.length; i++) {
              // 前6为Y辅助线,后6为X辅助线
              const xory = i < 6 ? 'y' : 'x'
              const horv = i < 6 ? 'hLine' : 'vLine'
              if (tem.display[i]) {
                const { origin, length } = this.calcLineValues(tem.value[xory][arrTem[i]])
                refLine[horv][arrTem[i]].display = tem.display[i]
                refLine[horv][arrTem[i]].position = tem.position[i] + 'px'
                refLine[horv][arrTem[i]].origin = origin
                refLine[horv][arrTem[i]].lineLength = length
              }
            }
          }
        }
        this.$emit('refLineParams', refLine)
      }
    },
    calcLineValues (arr) {
      const length = Math.max(...arr) - Math.min(...arr) + 'px'
      const origin = Math.min(...arr) + 'px'
      return { length, origin }
    },
    async getActiveAll (nodes) {
      const activeAll = []
      const XArray = []
      const YArray = []
      let groupWidth = 0
      let groupHeight = 0
      let groupLeft = 0
      let groupTop = 0
      for (let item of nodes) {
        if (item.className !== undefined && item.className.includes(this.classNameActive)) {
          activeAll.push(item)
        }
      }
      const AllLength = activeAll.length
      if (AllLength > 1) {
        for (let i of activeAll) {
          const l = i.offsetLeft
          const r = l + i.offsetWidth
          const t = i.offsetTop
          const b = t + i.offsetHeight
          XArray.push(t, b)
          YArray.push(l, r)
        }
        groupWidth = Math.max(...YArray) - Math.min(...YArray)
        groupHeight = Math.max(...XArray) - Math.min(...XArray)
        groupLeft = Math.min(...YArray)
        groupTop = Math.min(...XArray)
      }
      const bln = AllLength === 1
      return { groupWidth, groupHeight, groupLeft, groupTop, bln }
    },
    // 正则获取left与top
    formatTransformVal (string) {
      let [left, top] = string.replace(/[^0-9\-,]/g, '').split(',')
      if (top === undefined) top = 0
      return [+left, +top]
    }
  },
  computed: {
    handleStyle () {
      return (stick) => {
        if (!this.handleInfo.switch) return { display: this.enabled ? 'block' : 'none' }

        const size = (this.handleInfo.size / this.scaleRatio).toFixed(2)
        const offset = (this.handleInfo.offset / this.scaleRatio).toFixed(2)
        const center = (size / 2).toFixed(2)

        const styleMap = {
          tl: {
            top: `${offset}px`,
            left: `${offset}px`
          },
          tm: {
            top: `${offset}px`,
            left: `calc(50% - ${center}px)`
          },
          tr: {
            top: `${offset}px`,
            right: `${offset}px`
          },
          mr: {
            top: `calc(50% - ${center}px)`,
            right: `${offset}px`
          },
          br: {
            bottom: `${offset}px`,
            right: `${offset}px`
          },
          bm: {
            bottom: `${offset}px`,
            right: `calc(50% - ${center}px)`
          },
          bl: {
            bottom: `${offset}px`,
            left: `${offset}px`
          },
          ml: {
            top: `calc(50% - ${center}px)`,
            left: `${offset}px`
          }
        }
        const stickStyle = {
          width: `${size}px`,
          height: `${size}px`,
          top: styleMap[stick].top,
          left: styleMap[stick].left,
          right: styleMap[stick].right,
          bottom: styleMap[stick].bottom
        }
        stickStyle.display = this.enabled ? 'block' : 'none'
        return stickStyle
      }
    },
    style () {
      return {
        transform: `translate(${this.left}px, ${this.top}px) rotateZ(${this.rotateZ}deg)`,
        width: this.computedWidth,
        height: this.computedHeight,
        zIndex: this.zIndex,
        ...(this.dragging && this.disableUserSelect ? userSelectNone : userSelectAuto)
      }
    },
    // 控制柄显示与否
    actualHandles () {
      if (!this.resizable) return []

      return this.handles
    },
    computedWidth () {
      if (this.w === 'auto') {
        if (!this.widthTouched) {
          return 'auto'
        }
      }
      return this.width + 'px'
    },
    computedHeight () {
      if (this.h === 'auto') {
        if (!this.heightTouched) {
          return 'auto'
        }
      }
      return this.height + 'px'
    },
    resizingOnX () {
      return (Boolean(this.handle) && (this.handle.includes('l') || this.handle.includes('r')))
    },
    resizingOnY () {
      return (Boolean(this.handle) && (this.handle.includes('t') || this.handle.includes('b')))
    },
    isCornerHandle () {
      return (Boolean(this.handle) && ['tl', 'tr', 'br', 'bl'].includes(this.handle))
    }
  },

  watch: {
    active (val) {
      this.enabled = val

      if (val) {
        this.$emit('activated')
      } else {
        this.$emit('deactivated')
      }
    },
    z (val) {
      if (val >= 0 || val === 'auto') {
        this.zIndex = val
      }
    },
    x (val) {
      if (this.resizing || this.dragging) {
        return
      }

      if (this.parent) {
        this.bounds = this.calcDragLimits()
      }

      this.moveHorizontally(val)
    },
    y (val) {
      if (this.resizing || this.dragging) {
        return
      }

      if (this.parent) {
        this.bounds = this.calcDragLimits()
      }

      this.moveVertically(val)
    },
    lockAspectRatio (val) {
      if (val) {
        this.aspectFactor = this.width / this.height
      } else {
        this.aspectFactor = undefined
      }
    },
    minWidth (val) {
      if (val > 0 && val <= this.width) {
        this.minW = val
      }
    },
    minHeight (val) {
      if (val > 0 && val <= this.height) {
        this.minH = val
      }
    },
    maxWidth (val) {
      this.maxW = val
    },
    maxHeight (val) {
      this.maxH = val
    },
    w (val) {
      if (this.resizing || this.dragging) {
        return
      }

      if (this.parent) {
        this.bounds = this.calcResizeLimits()
      }

      this.changeWidth(val)
    },
    h (val) {
      if (this.resizing || this.dragging) {
        return
      }

      if (this.parent) {
        this.bounds = this.calcResizeLimits()
      }

      this.changeHeight(val)
    }
  }
}
</script>
<template>
  <!--选择素材-->
  <el-dialog
    @close="$emit('cancel')"
    :title="$t('plugin.selectFootage')"
    append-to-body
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form inline ref="queryForm" :model="material" size="small">
      <el-form-item label="分组" prop="groupId">
        <tree-select
          placeholder="请选择素材分组"
          :data="groupOptions"
          :props="defaultProps"
          :clearable="true"
          :accordion="true"
          @getValue="getValue"/>
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input circle v-model="material.name" placeholder="请输入素材名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getListMaterial" type="primary">{{ $t('plugin.search') }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t('plugin.rest') }}</el-button>
      </el-form-item>
    </el-form>
    <el-radio-group
      @change="changeType"
      v-if="typeList.length > 1"
      style="margin-bottom: 8px;"
      v-model="material.type" size="small">
      <el-radio
        border
        :label="item"
        style="margin-right: 5px;"
        v-for="item in typeList">
        <span>{{ item | filterType }}</span>
      </el-radio>
    </el-radio-group>
    <el-row :gutter="20" v-loading="material.loading">
      <el-col :span="6" v-for="(item, index) in material.list">
        <label>
          <div style="background-color: #fff; width: 167px; font-weight: 400; border: 2px solid transparent;"
               :class="{'active-material': currentIndex.some(s => s.id == item.id)}" class="choose-file"
               @click="rowClick(item)">
            <span v-show="Number(item.duration)" class="duration">{{ item.duration }} {{ $t('plugin.second') }}</span>
            <span class="resolution">{{ item.resolution }}</span>
            <img v-if="item.type === 'image'"
                 style="width: 100%; height: 120px;"
                 :src="filterUrl(item)"/>
            <img v-if="item.type === 'file'"
                 style="width: 100%; height: 120px;"
                 :src="filterUrl(item)"/>
            <div v-if="item.type === 'audio'" style="height: 120px; width: 100%; background-color: #ecf4ff;">
              <svg-icon style="color: #86baff; font-size: 36px; margin: 10px;" icon-class="audio"/>
            </div>
            <video v-if="item.type === 'media'"
                   style="height: 120px; width: 100%; object-fit: fill; vertical-align: bottom;"
                   :disabled="true"
                   :autoplay="false"
                   :controls="false"
                   :src="filterUrl(item)">
              {{ $t('tips.canvas') }}
            </video>
            <div class="bottom line-clamp1">
              <span style="margin: 0 5px;">{{ item.name }}</span>
            </div>
          </div>
        </label>
      </el-col>
    </el-row>
    <el-pagination
      style="margin-top: 16px;"
      @size-change="getListMaterial"
      @current-change="getListMaterial"
      :current-page.sync="material.current"
      :page-size="material.size"
      layout="total, prev, pager, next"
      :total="material.total">
    </el-pagination>
    <div style="text-align: right; margin-top: 16px;">
      <el-button size="small" @click="$emit('cancel')">{{ $t('tips.cancel') }}</el-button>
      <el-button size="small" :disabled="!currentIndex.length" type="primary" @click="confirm"> {{
          $t('tips.confirm')
        }}
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import treeSelect from "./TreeSelect/index"
import {request} from "@/config";
import Cookies from "js-cookie";

const {getMaterialList, groupTree} = request;
export default {
  name: "material",
  inject: ['equipment'],
  components: {
    treeSelect
  },
  watch: {
    visible: {
      handler() {
        this.currentIndex = [];
      },
      deep: true,
      immediate: true
    }
  },
  props: {
    mode: {
      type: String,
      default: "single"
    }, // single、multiple
    ids: {
      type: Array,
      default() {
        return []
      }
    },
    title: {
      type: String,
      default: "选择素材"
    },
    visible: {
      type: Boolean,
      default: false
    },
    typeList: {
      type: Array,
      default() {
        return ["image"]
      }
    }
  },
  filters: {
    filterType(data) {
      const typeList = [
        {label: "图片", name: "image"},
        {label: "视频", name: "media"},
        {label: "音频", name: "audio"}];
      const vo = typeList.find(item => data === item.name);
      const {label, name} = vo;
      const language = Cookies.get('language') || "zh"
      return language === 'zh' ? label : name;
    }
  },
  computed: {
    currentType() {
      return this.typeList.length ? this.typeList[0] : ""
    }
  },
  data() {
    const type = this.typeList[0]
    return {
      defaultProps: {
        value: 'id',
        label: 'name',
        children: 'children'
      },
      groupOptions: [],
      empty: require("@/assets/images/empty-img.png"),
      currentIndex: [],
      material: {
        name: "",
        groupId: "",
        type: type,
        list: [],
        current: 1,
        total: 0,
        size: 20,
        loading: false,
        data: []
      },
      baseUrl: sessionStorage.getItem('baseUrl')
    }
  },
  methods: {
    getValue(value) {
      this.material.groupId = value;
      this.getListMaterial();
    },
    getTree() {
      groupTree({type: '0'}).then(response => {
        this.groupOptions = response.data
      })
    },
    changeType() {
      this.material.current = 1;
      this.getListMaterial();
    },
    filterUrl(data) {
      const {decodedUrl, originalUrl} = data;
      return data ? `${this.baseUrl}${decodedUrl || originalUrl}` : this.empty;
    },
    rowClick(data) {
      if (this.mode === "multiple") {
        if (this.currentIndex.some(item => item.id == data.id)) {
          this.currentIndex = this.currentIndex.filter(item => item.id !== data.id);
        } else {
          this.currentIndex.push(data)
        }
      } else {
        this.currentIndex = [data]
      }
    },
    confirm() {
      let array = JSON.parse(JSON.stringify(this.currentIndex));
      this.material.data = [];
      let flag = false;
      array.forEach(data => {
        const {decodedUrl, originalUrl} = data;
        data.url = `${this.baseUrl}${decodedUrl || originalUrl}`
        if (data.addition) {
          data.addition = data.addition.split(",").map(item => this.baseUrl + item);
        } else {
          flag = true;
        }
        this.material.data.push(data);
      })
      if (flag && this.currentType === 'file') {
        return this.$notify.warning("当前文档未转换成功")
      }
      if (this.mode === "multiple") {
        this.$emit("confirm", this.material.data);
      } else {
        const data = this.material.data;
        this.$emit("confirm", data.length ? data[0] : {});
      }
    },
    getListMaterial() {
      this.material.loading = true;
      if (!Number(this.material.groupId)) {
        this.material.groupId = "";
      }
      getMaterialList({
        name: this.material.name,
        groupId: this.material.groupId,
        type: this.material.type,
        current: this.material.current,
        size: this.material.size
      }).then(response => {
        const {total, data} = response;
        if (data) {
          data.forEach((item, index) => {
            if (item.type === 'file') {
              const list = item.addition ? item.addition.split(",") : [""]
              data[index].decodedUrl = list[0];
            }
          })
          this.material.list = data;
          this.material.total = total;
        }
        this.material.loading = false;
      })
    },
    resetQuery() {
      this.$refs.queryForm.resetFields();
      this.material.current = 1;
      this.material.groupId = "";
      this.getListMaterial();
    }
  },
  created() {
    if (!this.equipment) {
      this.getListMaterial();
      this.getTree();
    }
  }
}
</script>

<style>
.active-material {
  transition: .3s;
  background-color: #ecf4ff !important;
  border: 3px solid #409eff !important;
}
</style>

 

Vue如何实现可视化拖拽表单(一) 在我们平时做需求中,往往会遇到拖拽模块的需求。刚开始没有接触过拖拽的时候,会对拖拽有陌生感,会比较担心实现起来会比较的复杂,可能自己很难搞定,低代码平台基本都会涵盖拖拽功能,今天来看一下到底是怎么实现的。因此,我们必须阻止浏览器这种默认行为。组在使用的时候,可以通过v-model来双向绑定本地data,如果需要更新或者是触发父组件监听的事件,可以在updated()中去emit。Vuedraggable 是标准的组件式封装,并且将可拖动元素放进了transition-group上面,过渡动画都比较好。 阅读详情

相关推荐

vue中is属性搭配vuedraggable插件实现可拖动可视化大屏展示组件的自定义配置功能

最近有这样一个需求,将大屏上展示的东西都封装这独立的组件让用户自己可以自定义配置自己的组件位置及想要展示的组件,第一个我就想到通过is来实现,分享下我的思路及部分代码供大家参考。

梦雨的博客 6561

手把手带你写 Vue 可视化拖拽页面编辑器

可视化页面编辑器,听起来可望不可即是吧,先来张动图观摩观摩一番! 实现这功能之前,在网上参考了很多资料,最终一无所获,五花八门的文章,都在述说着曾经的自己! 那么,这时候就需要自己去琢磨了,如何实现? 需要考虑到: 拖拽的实现 数据结构的定义 组件的划分 可维护性、扩展性 对象的引用:在这里是我感觉最酷的技巧了,来一一讲解其中的细节吧!! 拖拽实现 拖拽事件 这里使用 H5的拖拽事件 ,主要用到: dragstart // 开始拖拽一个元素时触发 draggable

weixin_53777231的博客 1万+

LCHub:腾讯魔方tmagic-editor低代码可视化生成器,正式开源

据 LCHub获悉:腾讯tmagic-editor是一个所见即所得的页面可视化编辑器,实现零代码/低代码生成页面,可以快速搭建可视化页面生产平台,让非技术人员可以通过拖拽和配置,自助生成H5页面、PC页面、TV页面,大大降低页面生产成本。 以下是腾讯视频会员业务基于tmagic-editor搭建的可视化页面搭建平台示意图。tmagic-editor已经用于腾讯视频会员、爱玩游戏、云视听极光、腾讯会议等十几个腾讯业务,每月生产和发布数百个页面。 基于可视化编辑器的页面生产流程 一、物料开发 主要是

实战AI智能体 5338

基于 SpringBoot + Vue 实现的可视化拖拽编辑的大屏项目

大家好,今天给小伙伴们分享一个基于 SpringBoot + Vue 实现的可视化拖拽编辑的大屏项目;# 简介这个是一个开源的一个BI平台,酷炫大屏展示,能随时随地掌控业务动态,让每个决策都有数据支撑。多数据源支持,内置mysql、elasticsearch、kudu驱动,支持自定义数据集省去数据接口开发,支持17种大屏组件,不会开发,照着设计稿也可以制作大屏。三步轻松完成大屏设计:配置数据源--...

架构文摘 1783

YOLOv8傻瓜式教程

YOLOv8傻瓜式教程,附带详细参数配置。

Father_of_Python的博客 1万+

从数据手册到代码:一步步解读SC7A20寄存器配置与加速度值换算原理

本文详细解析了SC7A20三轴加速度传感器的寄存器配置与加速度值换算原理。从数据手册出发,逐步拆解关键寄存器设置,并推导原始ADC值到物理加速度的完整换算过程,帮助开发者深入理解传感器底层工作原理,提升嵌入式开发效率。

weixin_29179311的博客 376

【亲测免费】 H5-可视化编辑器安装与配置完全指南

**H5-可视化编辑器**, 一个强大的前端工具,专为开发者打造,让H5页面设计如同堆积木般轻松。此项目采用**Vue2**作为主要开发框架,确保界面的高效构建与响应式设计。它不仅支持直观的拖拽操作来生成HTML页面,还具备丰富的编辑特性,如添加图片、文本、形状等元素,并且提供了图层管理、参考线辅助、自动吸附对齐等专业功能。对于开发者而言,内置的编辑器插件系统使得二次开发和集成到现有项目成为可能。...

gitblog_07279的博客 804

【GAN】pytorch-CycleGAN-and-pix2pix开源项目训练自定义数据集

Github:https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix 一、概念简介 图像转换:将一张图片转换为不同风格的图片,如将一张灰度图变成彩色图,素描图换成实物图。 pix2pix:需要成对的数据集,两个不同域的图像一一对应。 CycleGAN:不需要成对的数据集,只用两个不同域(domain)的图像集合X和Y,两个集合中的图像不是一一对应的。 二、训练pix2pix模型 2.1 combine_A_and_B datasets/combin

See_Star的博客 4761

终极指南:使用开源H5可视化编辑器h5maker零代码构建专业移动页面

你是否想要创建精美的H5页面,但又不想学习复杂的编程技术?开源H5可视化编辑器h5maker就是为你准备的完美解决方案!这款基于Vue.js和Node.js的免费工具,让你通过简单的拖拽操作就能制作出专业的移动端页面。h5maker编辑器完全开源免费,支持本地部署,无需任何编程经验,即可快速创建适配各种移动设备的H5页面。 ## 🎯 项目亮点与价值主张 ### 为什么选择h5maker? h

gitblog_00262的博客 202

山东大学软件工程应用与实践——GMSSL开源库(六)——SM9密钥交换协议

2021SC@SDUSC 文章目录基本概念符号及辅助算法SM9密钥交换协议 基本概念 1976年,Diffie和Hellman在其题为《密码学的新方向》的论文中首次给出了公钥密码学的定义,并提出了Diffie-Hellman密钥交换算法。该算法解决了对称密码体制中的密钥分发问题,使得通信双方可以通过公开信道安全地交换共享密钥。 使用SM9通信的双方通过对方的标识和自身的私钥,经过两次或者可选的三次信息传递过程,计算获取一个由双方共同决定的共享秘密密钥。该密钥可以作为对称密码算法的会话密钥,其中可选步骤用来实

m0_51588039的博客 1994

深度学习 load_data_fashion_mnist

pytorch 中报错:PermissionError: [WinError 5] 拒绝访问。: '…/data’ 在学习李沐大神动手学习深度学习卷积神经网络章节中,调用d2l包中load_data_fashion_mnist报错,这可能是***权限***的问题。 batch_size = 256 train_iter, test_iter = d2l.load_data_fashion_mnist(batch_size,batch_size) 我的解决方法是 重新定义一下 load_data_fashi

纸上得来终觉浅,绝知此事要躬行 9151

用 REA 做本地逆向分析的完整指南

在别人的产品里看到一个想要的功能,手里却只有编译产物:打开反编译器能看到函数和跳转,但从几千个函数里人肉追调用链并不现实。REA(npm 包名 rea-agents)做的事,是把 Hopper、Ghidra、IDA 这类逆向引擎接到你的终端和 AI Agent 上,返回的每条结论都附带证据出处与已知局限。它是 MIT 许可的本地工具,适合用 AI Agent 辅助开发、想弄清闭源组件行为、或者希望

gitblog_00509的博客 984

idea出现 EXCEPTION_ACCESS_VIOLATION (0xc0000005) 的解决方法

idea启动的时候出现如下问题,以为没啥事,就索性关闭 后面再打开idea的时候发现直接闪退,之后打开其他软件,直接蓝屏

码农研究僧的博客 4823

@changesets/get-dependents-graph 源码解析:Monorepo 被依赖关系图的构建与版本范围校验

`@changesets/get-dependents-graph` 是 changesets 工具链中负责计算 Monorepo 包之间"谁依赖谁"关系的小型核心库:它从 `@manypkg/get-packages` 提供的包集合出发,构建包依赖图、反向推导每个包的 dependents(被依赖者),并校验依赖版本范围是否与工作区内的当前版本一致。本篇文章以该包的 [CHANGELOG.md]

gitblog_00460的博客 214

UGUI合批杀手:Mask/RectMask2D为何必断合批?

颜色缓冲负责记录像素颜色;模板缓冲负责记录“这个像素的模板值”(一个小整数);渲染时,你可以设定:只有模板值为 X 的地方才允许画;或者往某些区域写特定的模板值。类似于:先拿一支隐形笔在纸上画出一块区域,给它记一个编号“1”,后面的涂色动作只允许涂在“编号为1”的区域上。合批的前提:渲染状态不变,连续元素能一口气画完。材质、贴图、混合模式、Stencil、裁剪区域……都得一致。Mask / RectMask2D 的本质:在渲染状态上加规则——“只在某个区域内允许写像素”。

本博客聚焦游戏开发技巧、创业实战心得及大学热门课程干货。这里既有技术深度,也有思维广度,无论你是开发者、创业者还是高校学子,都能在这里找到适合自己的成长之路! 133

Debezium报错处理系列之二十一:Unable to connect: Communications link failure.The driver has not received any

Debezium报错系列之二十一:Unable to connect: Communications link failure.The driver has not received any。

zhengzaifeidelushang的博客 550

3分钟从零到一:用免费开源H5编辑器h5maker打造专业营销页面

还在为制作H5营销页面而烦恼吗?面对复杂的代码和昂贵的商业工具,你是否渴望一款真正免费且简单易用的解决方案?今天,我将为你介绍h5maker——一款完全开源的可视化H5编辑器,让你在3分钟内从零开始创建专业级的移动端页面。这款工具不仅免费无限制,还支持本地部署,让你的数据完全掌握在自己手中。 ## 为什么你的营销需要h5maker? 在移动互联网时代,H5页面已经成为品牌推广、活动营销和内容展

gitblog_00682的博客 200

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

PRAXIST SAM Optimizer 任务的 Portfolio PI 角色:研究组合治理、桥接审计与反主线预算防护

本指南围绕 PRAXIST 开源仓库中 `templates/tasks/sam_optimizer` 任务模板的 Portfolio PI 角色展开,系统讲解它在 SAM(Sharpness-Aware Minimization)变体自动化科研流程中承担的"研究组合治理"职责:如何用固定审查问题监控主线预算吸收、如何依据桥接覆盖原则决定是否派发 bridge 合约、如何通过 forbidden

gitblog_00955的博客 155

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

腾讯可视化, 低代码生成器,正式开源!

点关注公众号,回复“1024”获取2TB学习资源!腾讯tmagic-editor是一个所见即所得的页面可视化编辑器,实现零代码/低代码生成页面,可以快速搭建可视化页面生产平台,让非技术人员可以通过拖拽和配置,自助生成H5页面、PC页面、TV页面,大大降低页面生产成本。以下是腾讯视频会员业务基于tmagic-editor搭建的可视化页面搭建平台示意图。tmagic-edit...

民工哥的博客 1090

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Uni-App + Vue 实战:手把手教你从零搭建一个可拖拽的DIY小程序页面编辑器

本文详细介绍了如何使用Uni-App和Vue从零构建一个可拖拽的DIY小程序页面编辑器。通过技术选型、拖拽交互实现、Uni-App端动态渲染方案、状态管理与数据同步等核心环节的实战讲解,帮助开发者快速掌握可视化页面编辑器的开发技巧,特别适合电商小程序等需要灵活页面配置的场景。

weixin_30522095的博客 768

腾讯: 可视化, 低代码生成器,正式开源!

开发者(KaiFaX)面向全栈工程师的开发者专注于前端、Java/Python/Go/PHP的技术社区腾讯tmagic-editor是一个所见即所得的页面可视化编辑器,实现零代码/低代码生成页面,可以快速搭建可视化页面生产平台,让非技术人员可以通过拖拽和配置,自助生成H5页面、PC页面、TV页面,大大降低页面生产成本。以下是腾讯视频会员业务基于tmagic-editor搭...

AI研习社 1458

腾讯入局“低代码”赛道:无需敲码,快速生成一个完整系统!

点击关注公众号,利用碎片时间学习腾讯tmagic-editor是一个所见即所得的页面可视化编辑器,实现零代码/低代码生成页面,可以快速搭建可视化页面生产平台,让非技术人员可以通过拖拽和配置,自助生成H5页面、PC页面、TV页面,大大降低页面生产成本。以下是腾讯视频会员业务基于tmagic-editor搭建的可视化页面搭建平台示意图。tmagic-editor已经用于腾讯视...

Java笔记虾 2881

腾讯低代码平台正式开源!可拖拽、生成手机项目、PC 项目!接私活福利啊!...

点击上方“Java基基”,选择“设为星标”做积极的人,而不是积极废人!每天14:00更新文章,每天掉亿点点头发...源码精品专栏原创 | Java 2021超神之路,很肝~中文详细注释的开源项目RPC 框架 Dubbo 源码解析网络应用框架 Netty 源码解析消息中间件 RocketMQ 源码解析数据库中间件 Sharding-JDBC 和 MyCAT 源码解析...

weixin_44421461的博客 410

深入vite-vue3-lowcode架构:理解Vue3.x + Vite2.x + TypeScript的技术栈设计

在当今快速发展的前端开发领域,低代码平台正成为提升开发效率的重要工具。vite-vue3-lowcode项目是一个基于现代前端技术栈构建的H5移动端低代码平台,它巧妙地将Vue3.x、Vite2.x和TypeScript三大技术融合,为开发者提供了一个功能强大的可视化拖拽编辑器。本文将深入解析这个项目的技术架构设计,帮助您理解如何构建一个现代化的低代码平台。 ## 🚀 技术栈全景图 vite

gitblog_00135的博客 921

vue h5 实现拖拽

目前项目遇到拖拽的功能,记录一下,大概逻辑如下: 1)左侧为分类列表,右侧为数据,根据左侧的列表分类展示右侧的数据; 2)右侧的数据还可以拖动到左侧类型里面,类似于文件夹拖动时的剪切,复制 实现: div为目标元素,当鼠标拖动下面的li 移上去并放开时会触发,并且鼠标样式会发生变化,注意上面的两个方法为必须 li 为移动的元素,deaggable ="true",表示此...

qq_40247562的博客 1084
上一篇: 高德地图实现gps轨迹坐标定位代码
下一篇: vue基于高德地图实现城市管网、压力点、区域绘制编辑器
#麻辣小龙虾#
博客等级 码龄11年 1万+粉丝 235原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址