main.js 1.6 KB
Newer Older
璃白.'s avatar
璃白. 已提交
1 2
import Vue from "vue";
import App from "./App";
璃白.'s avatar
璃白. 已提交
3 4
import Vtip from "vtip";
import "vtip/lib/index.min.css";
5
import { initStyle, setzIndex, isNotEmpty } from "@/assets/js/utils";
璃白.'s avatar
璃白. 已提交
6 7
import "@/assets/style/global.less";

璃白.'s avatar
璃白. 已提交
8 9
Vue.use(Vtip.directive);

璃白.'s avatar
璃白. 已提交
10
function initMdEditor(obj) {
璃白.'s avatar
璃白. 已提交
11 12
  const {
    el,
13 14 15 16 17 18
    onChange = () => {},
    onUpload = () => {},
    onFocus = () => {},
    onBlur = () => {},
    onInput = () => {},
    onSubmit = () => {},
璃白.'s avatar
璃白. 已提交
19
    placeholder,
璃白.'s avatar
璃白. 已提交
20
    value,
21 22 23 24 25 26
    zIndex = 2000,
    rule,
    rows = 10,
    maxLength,
    showWordLimit,
    throttle,
璃白.'s avatar
璃白. 已提交
27
    canPreview,
璃白.'s avatar
璃白. 已提交
28
    canAttachFile,
璃白.'s avatar
璃白. 已提交
29 30
    themeOptions,
    toolsOptions
璃白.'s avatar
璃白. 已提交
31
  } = obj;
璃白.'s avatar
璃白. 已提交
32
  if (!el || !document.querySelector(el)) throw new Error("请指定容器");
璃白.'s avatar
璃白. 已提交
33
  if (isNotEmpty(themeOptions)) initStyle(themeOptions);
34
  if (isNotEmpty(zIndex)) setzIndex(zIndex);
璃白.'s avatar
璃白. 已提交
35
  new Vue({
璃白.'s avatar
璃白. 已提交
36
    render: h =>
璃白.'s avatar
璃白. 已提交
37 38 39 40
      h(App, {
        on: {
          change(val) {
            onChange(val);
G
guoweijia 已提交
41
          },
42 43 44
          input(val) {
            onInput(val);
          },
璃白.'s avatar
璃白. 已提交
45 46 47 48 49 50 51 52 53
          focus(val) {
            onFocus(val);
          },
          blur(val) {
            onBlur(val);
          },
          submit(val) {
            onSubmit(val);
          },
璃白.'s avatar
璃白. 已提交
54
          upload({ val, callback }) {
G
guoweijia 已提交
55
            onUpload(val, function(res) {
璃白.'s avatar
璃白. 已提交
56
              callback(res);
G
guoweijia 已提交
57
            });
璃白.'s avatar
璃白. 已提交
58
          }
璃白.'s avatar
璃白. 已提交
59 60 61
        },
        props: {
          canAttachFile,
璃白.'s avatar
璃白. 已提交
62
          value,
63 64 65
          rule,
          rows,
          throttle,
璃白.'s avatar
璃白. 已提交
66 67
          canPreview,
          toolsOptions,
68 69 70
          placeholder,
          maxLength,
          showWordLimit
璃白.'s avatar
璃白. 已提交
71 72 73 74 75
        }
      })
  }).$mount(el);
}

璃白.'s avatar
璃白. 已提交
76
window.MdEditor = initMdEditor;