";
+
+/**
+ * Created by peak on 2017/2/10.
+ */
+var dashboard$3 = {
+ template: template$3,
+ data: function data() {
+ return {
+ imageUrl: '',
+ upload: {
+ status: 'ready', // progress,success,error,abort
+ errorMsg: null,
+ progressComputable: false,
+ complete: 0
+ }
+ }
+ },
+ methods: {
+ reset: function reset(){
+ this.upload.status = 'ready';
+ },
+ insertImageUrl: function insertImageUrl() {
+ if (!this.imageUrl) {
+ return
+ }
+ this.$parent.execCommand(Command.INSERT_IMAGE, this.imageUrl);
+ this.imageUrl = null;
+ },
+ pick: function pick() {
+ this.$refs.file.click();
+ },
+ setUploadError: function setUploadError(msg){
+ this.upload.status = 'error';
+ this.upload.errorMsg = msg;
+ },
+ process: function process() {
+ var this$1 = this;
+
+ var component = this;
+ var config = this.$options.module.config;
+ // compatibility with older format
+ // {
+ // server: null,
+ // fieldName: 'image',
+ // compress: true,
+ // width: 1600,
+ // height: 1600,
+ // quality: 80
+ // }
+ // ----------- divider ----------------
+ // {
+ // upload: {
+ // url: null,
+ // headers: {},
+ // params: {},
+ // fieldName: {}
+ // },
+ // compress: {
+ // width: 1600,
+ // height: 1600,
+ // quality: 80
+ // },
+ // }
+
+ if (!config.upload && typeof config.server === 'string') {
+ config.upload = {url: config.server};
+ }
+ if (config.upload && !config.upload.url) {
+ config.upload = null;
+ }
+ if (config.upload && typeof config.fieldName === 'string') {
+ config.upload.fieldName = config.fieldName;
+ }
+
+ if (typeof config.compress === 'boolean') {
+ config.compress = {
+ width: config.width,
+ height: config.height,
+ quality: config.quality
+ };
+ }
+
+ var file = this.$refs.file.files[0];
+ if (file.size > config.sizeLimit) {
+ this.setUploadError(this.$parent.locale['exceed size limit']);
+ return
+ }
+ this.$refs.file.value = null;
+
+ if (config.compress) {
+ config.compress.fieldName = config.upload && config.upload.fieldName
+ ? config.upload.fieldName : 'image';
+ lrz_all_bundle(file, config.compress).then(function (rst) {
+ if (config.upload) {
+ component.uploadToServer(rst.file);
+ } else {
+ component.insertBase64(rst.base64);
+ }
+ }).catch(function (err) {
+ this$1.setUploadError(err.toString());
+ });
+ return
+ }
+ // 不需要压缩
+ // base64
+ if (!config.upload) {
+ var reader = new FileReader();
+ reader.onload = function (e) {
+ component.insertBase64(e.target.result);
+ };
+ reader.readAsDataURL(file);
+ return
+ }
+ // 上传服务器
+ component.uploadToServer(file);
+ },
+ insertBase64: function insertBase64(data) {
+ this.$parent.execCommand(Command.INSERT_IMAGE, data);
+ },
+ uploadToServer: function uploadToServer(file) {
+ var this$1 = this;
+
+ var config = this.$options.module.config;
+
+ var formData = new FormData();
+ formData.append(config.upload.fieldName || 'image', file);
+
+ if (typeof config.upload.params === 'object') {
+ Object.keys(config.upload.params).forEach(function (key) {
+ var value = config.upload.params[key];
+ if (Array.isArray(value)) {
+ value.forEach(function (v) {
+ formData.append(key, v);
+ });
+ } else {
+ formData.append(key, value);
+ }
+ });
+ }
+
+ var xhr = new XMLHttpRequest();
+
+ xhr.onprogress = function (e) {
+ this$1.upload.status = 'progress';
+ if (e.lengthComputable) {
+ this$1.upload.progressComputable = true;
+ var percentComplete = e.loaded / e.total;
+ this$1.upload.complete = (percentComplete * 100).toFixed(2);
+ } else {
+ this$1.upload.progressComputable = false;
+ }
+ };
+
+ xhr.onload = function () {
+ if (xhr.status >= 300) {
+ this$1.setUploadError(("request error,code " + (xhr.status)));
+ return
+ }
+
+ try {
+ var url = config.uploadHandler(xhr.responseText);
+ if (url) {
+ this$1.$parent.execCommand(Command.INSERT_IMAGE, url);
+ }
+ } catch (err) {
+ this$1.setUploadError(err.toString());
+ } finally {
+ this$1.upload.status = 'ready';
+ }
+ };
+
+ xhr.onerror = function () {
+ // find network info in brower tools
+ this$1.setUploadError('request error');
+ };
+
+ xhr.onabort = function () {
+ this$1.upload.status = 'abort';
+ };
+
+ xhr.open('POST', config.upload.url);
+ if (typeof config.upload.headers === 'object') {
+ Object.keys(config.upload.headers).forEach(function (k) {
+ xhr.setRequestHeader(k, config.upload.headers[k]);
+ });
+ }
+ xhr.send(formData);
+ }
+ }
+};
+
+/**
+ * insert image
+ * Created by peak on 16/8/18.
+ */
+var image = {
+ name: 'image',
+ icon: 'fa fa-file-image-o',
+ i18n: 'image',
+ config: {
+ // server: null,
+ // fieldName: 'image',
+ // compress: true,
+ // width: 1600,
+ // height: 1600,
+ // quality: 80,
+ sizeLimit: 512 * 1024,// 512k
+ // upload: {
+ // url: null,
+ // headers: {},
+ // params: {},
+ // fieldName: {}
+ // },
+ compress: {
+ width: 1600,
+ height: 1600,
+ quality: 80
+ },
+ uploadHandler: function uploadHandler(responseText){
+ var json = JSON.parse(responseText);
+ return json.ok ? json.data : null
+ }
+ },
+ dashboard: dashboard$3
+};
+
+var template$4 = "