zxl
2025-08-04 406d27d67d643c91bb9a5cff5582994cec19b1a1
厨神二维码,新闻添加的bug
2个文件已修改
1个文件已添加
226 ■■■■ 已修改文件
manager/src/views/kitchen/kitchenVideo.vue 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manager/src/views/news/index.vue 149 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manager/src/views/news/video.js 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manager/src/views/kitchen/kitchenVideo.vue
@@ -587,17 +587,15 @@
    },
    generalQrCode(row){
      console.log(row)
      this.QRCodeUrl = '';
      this.showGeneralQrCode = true
      console.log('-------------------->',row);
      //shareType可能会是动态的,会加判断视频来源
      console.log(item)
      // uni.navigateTo({
      //   url: `/pages/product/goods?id=${item.id}&goodsId=${item.goodsId}`
      // });
      this.QRCodeUrl = this.codeUrl + '?shareType=cook' + '&videoId='+ row.id + '&source=' + 'system';
      //TODO 根据视频信息中的 ,作者id获得用户 判断 来源 ,用户作者的uniid为null则是系统上传,不为空则是用户上传
      console.log(this.QRCodeUrl)
      // console.log(this.QRCodeUrl)
    },
manager/src/views/news/index.vue
@@ -53,7 +53,7 @@
      <!-- 操作按钮 -->
      <Row class="operation">
        <Button @click="openAdd" type="primary" icon="md-add">新增活动</Button>
        <Button @click="openAdd" type="primary" icon="md-add">新增新闻</Button>
        <Button @click="delBatch" type="error" icon="md-trash" :disabled="selectCount === 0">批量删除</Button>
      </Row>
@@ -134,7 +134,7 @@
              </FormItem>
            </Col>
            <Col span="24">
              <FormItem label="新闻内容:" prop="content">
              <FormItem label="快讯内容:" prop="content">
                <Upload
                  :show-upload-list="false"
                  ref="upload"
@@ -232,7 +232,7 @@
import 'quill/dist/quill.bubble.css';
import * as Quill from 'quill' //引入编辑器
import VideoBlot from '../activity/video.js';
import VideoBlot from './video.js';
const toolbarOptions = [
  ['bold', 'italic', 'underline', 'strike'],        // 加粗,斜体,下划线,删除线
@@ -443,10 +443,15 @@
  },
  mounted() {
    //初始化
    this.Quill=this.$refs.QuillEditor.quill
    this.getNewsList();
    this.initTitle();
    this.initButton();
    this.$nextTick(() => {
      if (this.$refs.QuillEditor) {
        this.Quill=this.$refs.QuillEditor.quill
        this.getNewsList();
        this.initTitle();
        this.initButton();
      }
    })
  },
  methods:{
    onEditorBlur(editor) {
@@ -492,8 +497,57 @@
      this.uploadFile2()
      return false
    },
    uploadFile2() {
    getFileType(file) {
      // 获取文件类型或扩展名
      let type, extension;
      if (file instanceof File) {
        // 如果是File对象
        type = file.type;
        const name = file.name.toLowerCase();
        extension = name.substring(name.lastIndexOf('.') + 1);
      } else if (typeof file === 'string') {
        // 如果是字符串(文件名或URL)
        const name = file.toLowerCase();
        extension = name.substring(name.lastIndexOf('.') + 1);
        // 尝试从URL中提取MIME类型(如果有)
        const mimeMatch = file.match(/^data:(.+?);/);
        if (mimeMatch) {
          type = mimeMatch[1];
        }
      } else {
        return 'unknown';
      }
      // 常见图片和视频的MIME类型
      const imageTypes = [
        'image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/bmp', 'image/svg+xml'
      ];
      const videoTypes = [
        'video/mp4', 'video/webm', 'video/ogg', 'video/quicktime', 'video/x-msvideo', 'video/x-matroska'
      ];
      // 检查MIME类型
      if (type) {
        if (imageTypes.includes(type)) return 'image';
        if (videoTypes.includes(type)) return 'video';
      }
      // 常见图片和视频的扩展名
      const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg'];
      const videoExtensions = ['mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv'];
      // 检查文件扩展名
      if (extension) {
        if (imageExtensions.includes(extension)) return 'image';
        if (videoExtensions.includes(extension)) return 'video';
      }
      return 'unknown';
    },
    uploadFile2() {
      if (!this.file) return
      this.submitLoading = true
@@ -505,11 +559,12 @@
          let url = res.data.url;
          let fileKey = res.data.fileKey;
          let fileType = this.getFileType(this.file);
          console.log("打印")
          console.log(this.Quill);
          const range = this.Quill.getSelection();
          const index = range ? range.index : this.Quill.getLength();
          console.log("--------");
          console.log(fileType);
          if (fileType === 'video') {
            this.Quill.insertEmbed(index, 'video', {
              url:url,
@@ -528,6 +583,8 @@
          console.log(this.newsForm.content)
          this.Quill.setSelection(index + 1);
          this.$Message.success('上传成功')
        }else{
          this.$Message.error(res.msg)
        }
      }).catch(() => {
        this.submitLoading = false
@@ -551,39 +608,39 @@
    saveOrUpdate(){
      console.log(this.newsForm)
      // this.$refs.form.validate(valid => {
      //   if (valid) {
      //     this.submitLoading = true
      //     const submitData = {
      //       ...this.newsForm,
      //       publish: this.newsForm.publish !== 0,  // true → 1, false → 0
      //     };
      //     if (this.newsForm.id){
      //       editNews(submitData).then(res => {
      //         this.submitLoading = false
      //         if (res.code === 200) {
      //           this.$Message.success(res.msg)
      //           this.modelClose()
      //           this.getNewsList()
      //         }
      //       }).catch(() => {
      //         this.submitLoading = false
      //       })
      //     }else {
      //       addNews(submitData).then(res => {
      //         this.submitLoading = false
      //         if (res.code === 200) {
      //           this.$Message.success(res.msg)
      //           this.modelClose()
      //           this.getNewsList()
      //         }
      //       }).catch(() => {
      //         this.submitLoading = false
      //       })
      //     }
      //
      //   }
      // })
      this.$refs.form.validate(valid => {
        if (valid) {
          this.submitLoading = true
          const submitData = {
            ...this.newsForm,
            publish: this.newsForm.publish !== 0,  // true → 1, false → 0
          };
          if (this.newsForm.id){
            editNews(submitData).then(res => {
              this.submitLoading = false
              if (res.code === 200) {
                this.$Message.success(res.msg)
                this.modelClose()
                this.getNewsList()
              }
            }).catch(() => {
              this.submitLoading = false
            })
          }else {
            addNews(submitData).then(res => {
              this.submitLoading = false
              if (res.code === 200) {
                this.$Message.success(res.msg)
                this.modelClose()
                this.getNewsList()
              }
            }).catch(() => {
              this.submitLoading = false
            })
          }
        }
      })
    },
    infoModelClose(){
@@ -617,17 +674,17 @@
    },
    openEdit(row){
      this.modelTitle = '修改新闻';
      this.modelTitle = '修改快讯';
      this.modelShow = true;
      this.$refs.form.resetFields();
      this.newsForm.title = row.title;
      this.newsForm.content = row.content;
      this.newsForm.id = row.id;
      this.$refs.editor.setContent(this.newsForm.content)
      // this.$refs.editor.setContent(this.newsForm.content)
    },
    openAdd(){
      this.modelTitle = '新增新闻';
      this.modelTitle = '新增快讯';
      this.modelShow = true;
      this.$refs.form.resetFields()
      this.newsForm.id = '';
manager/src/views/news/video.js
New file
@@ -0,0 +1,69 @@
import { Quill } from 'vue-quill-editor';
const BlockEmbed = Quill.import('blots/block/embed');
const Link = Quill.import('formats/link');
const ATTRIBUTES = ['height', 'width', 'controls', 'src', ];
class VideoBlot extends BlockEmbed {
  static create(value) {
    const node = super.create();
    if (typeof value === 'object') {
      node.setAttribute('src', this.sanitize(value.url));
      node.setAttribute('width', value.width || '100%');
      node.setAttribute('height', value.height || 'auto');
      node.setAttribute('controls', value.controls || 'controls');
    } else {
      node.setAttribute('src', this.sanitize(value));
    }
    return node;
  }
  static formats(node) {
    return ATTRIBUTES.reduce((formats, attribute) => {
      if (node.hasAttribute(attribute)) {
        formats[attribute] = node.getAttribute(attribute);
      }
      return formats;
    }, {});
  }
  static sanitize(url) {
    return Link.sanitize(url);
  }
  static value(node) {
    return {
      url: node.getAttribute('src'),
      width: node.getAttribute('width'),
      height: node.getAttribute('height'),
      controls: node.getAttribute('controls'),
    };
  }
  format(name, value) {
    if (ATTRIBUTES.includes(name)) {
      if (value) {
        this.domNode.setAttribute(name, value);
      } else {
        this.domNode.removeAttribute(name);
      }
    } else {
      super.format(name, value);
    }
  }
}
VideoBlot.blotName = 'video';
VideoBlot.className = 'ql-video';
VideoBlot.tagName = 'video';
// 添加不会被 sanitize 的标记
VideoBlot.sanitize = function(url) {
  const sanitized = Link.sanitize(url);
  return sanitized === Link.PROTOCOL_WHITELIST[0] ? 'about:blank' : sanitized;
};
export default VideoBlot;