/**
* 图片上传
*/
Vue.component('spaceUploadImg', {
data: function () {
return {
id: "spaceUploadImg" + space.utils.random(6),
}
},
name: "spaceUploadImg",
model: {
prop: 'patharry',
evnet: 'click'
},
/**
* patharry: v-model 绑定的值,非空,字符串数组
* type: 上传按钮的风格,可空,缺省值为 button ,可选值为button / img
* width: 图片裁剪的宽度,可空
* height: 图片裁剪的高度,可空
* maxsize: 最大上传的图片数量,可空,缺省值为1
* tip: 提示语,可空
* color: 图片背景,可空,值的类型与css的color值类型一样
* source: 是否可上传原图
*/
props: {
patharry: {
type: Array,
required: true
},
type: {
type: String,
default: "button"
},
width: [String, Number],
height: [String, Number],
maxsize: {
type: [String, Number],
default: 1
},
tip: [String, Number],
color: [String, Number],
source: {
type: Boolean,
default: false,
}
},
created: function () {
// 对初始化值进行处理,排除掉空数据
if (!this.patharry) {
this.patharry = [];
}
var newAry = [];
if (typeof this.patharry == "string") {
if (space.utils.notNull(this.patharry)) {
newAry.push(this.patharry);
}
} else {
for (let index = 0; index < this.patharry.length; index++) {
const element = this.patharry[index];
if (space.utils.notNull(element)) {
newAry.push(element);
}
}
}
this.patharry = newAry;
this.$emit("input", newAry);
},
mounted: function () {
var that = this;
space.plugins.cropper.init({
el: $("#" + that.id),
photoSize: { // 裁剪的图片大小,会自动计算裁剪比例
width: that.width,
height: that.height,
source: that.source,
},
show: function (setting) { //打开裁剪框前的回调
setting.photoSize = {
width: that.width,
height: that.height,
source: that.source,
}
},
success: function (path) { // 成功后的回调方法,path为裁剪后的img路径
that.patharry.push(path);
that.$emit("input", that.patharry);
},
});
},
methods: {
uploadClick: function () {
if (this.patharry.length >= this.maxsize) {
space.message.warning("最多上传" + this.maxsize + "张图片");
return false;
}
$("#" + this.id).click();
},
removeCropperImg: function (index) {
this.patharry.splice(index, 1);
space.message.success("图片已删除");
this.$emit("input", this.patharry);
},
},
template: `
`
})
/**
* 图片预览
*/
Vue.component('spacePreviewImg', {
data: function () {
return {
newAry: [],
}
},
name: "spacePreviewImg",
/**
* paths: 绑定的值,非空,字符串/数组
* color: 图片背景色,可空,值的类型与css的color值类型一样
*/
props: {
paths: {
type: [Array, String],
required: true
},
color: {
type: String,
}
},
created: function () {
// 对初始化值进行处理,排除掉空数据
if (!this.paths) {
this.paths = [];
}
if (typeof this.paths == "string") {
if (space.utils.notNull(this.paths)) {
this.newAry.push(this.paths);
}
} else {
for (let index = 0; index < this.paths.length; index++) {
const element = this.paths[index];
if (space.utils.notNull(element)) {
this.newAry.push(element);
}
}
}
this.$emit("input", this.newAry);
},
mounted: function () {
},
methods: {
},
template: `
`
})
/**
* 对象选择器
*/
Vue.component('spaceSelect', {
data: function () {
return {
id: "spaceSelect" + space.utils.random(6),
randomNum: space.utils.random(6),
options: [],
isOpen: true, // 是否打开
}
},
name: "spaceSelect",
model: {
prop: 'modelAry',
evnet: 'click'
},
/**
* modelAry: 绑定的值,非空,字符串/数组
* predefine: 预定义对象,非空,可选值有person、department、post、role
* datasize: 最多选择的数量,可空,默认值为1
* method:自定义方法
*/
props: ['modelAry', "predefine", "datasize", "method"],
watch: {
modelAry: function (newVal, oldVal) {
// 没有打开时,则可以初始化选择数据集合
if (!this.isOpen) {
this.isOpen = true;
this.initSelectedDataList();
} else {
this.isOpen = false;
}
}
},
created: function () {
if (this.predefine && this.method) {
space.message.error('predefine 与 method 不能同时存在');
}
if (!this.isPredefine()) {
if (!this.method) {
space.message.warning('预定义选择器不存在:' + this.predefine);
}
}
},
mounted: function () {
var that = this;
if (!this.method) {
// 初始化选择窗
space.choose[that.predefine].init({
el: $("#choose" + that.predefine + that.randomNum), // 点击弹出选择窗的元素
selectAry: function () {
return that.modelAry;
}, // 已选的数组
selectCountNum: that.datasize || 1, // 最多选择的数量
success: function (param) { // 成功后的回调
that.options = param;
that.modelAry = [];
that.options.forEach(function (item) {
that.modelAry.push(item["id"]);
});
that.$emit("input", that.modelAry);
}
})
}
/* 监听容器高度 */
const erd = elementResizeDetectorMaker();
var eles = $("#" + that.id).find("div.el-input--suffix")[0];
erd.listenTo(eles, element => {
const height = element.offsetHeight;
$("#choose" + that.predefine + that.randomNum).css("height", height);
});
this.initSelectedDataList();
},
methods: {
removeFun: function () {
this.$emit("input", this.modelAry);
},
/**
* 获取最大限制绑定的值
*/
getMaxSelectedModelAry: function () {
var tmpAry = [];
var _this = this;
this.options.forEach(function (item) {
tmpAry.push(item["id"]);
});
if (this.datasize == undefined || this.datasize == 1) {
return tmpAry.length > 0 ? [tmpAry[tmpAry.length - 1]] : [];
} else if (this.datasize > 1) {
var selectedAry = [];
tmpAry.forEach(function (item, index) {
if ((index + 1) > _this.datasize) {
return;
}
selectedAry.push(item);
});
return selectedAry;
} else if (this.datasize == '*') {
return tmpAry;
} else {
return [];
}
},
/**
* 是否预定义选择器,false:不是预定义选择器,true:是预定义选择器
*/
isPredefine: function () {
if (this.predefine != "person" && this.predefine != "department" && this.predefine != "post" && this.predefine != "role") {
return false; // 不是预定义选择器
} else {
return true; // 预定义选择器
}
},
/**
* 获取预定义的服务
*/
getPredefineService: function () {
var map = new Map();
map.set("person", "/apps?ark=personnel.person_getChoolsePersonInfoApi");
map.set("department", "/apps?ark=sys.department_getChoolseDepartmentInfoApi");
map.set("post", "/apps?ark=sys.post_getChoolsePostInfoApi");
map.set("role", "/apps?ark=sys.role_getChoolseRoleInfoApi");
return map.get(this.predefine);
},
/**
* 初始化选择数据集合
*/
initSelectedDataList: function () {
if (!this.isPredefine() || this.method) {
return;
}
if (!this.modelAry || this.modelAry.length == 0) {
this.isOpen = false; // 没有数据时,则关闭
return;
}
var url = this.getPredefineService();
var ids = typeof (this.modelAry) == 'string' || typeof (this.modelAry) == 'number' ? this.modelAry : this.modelAry.join(',');
var _this = this;
// 查询选中的列表
space.utils.ajax({
url: url,
data: {
"ids": ids
},
dataType: 'json',
callback: function (data) {
_this.options = data.data;
var tmpAry = _this.getMaxSelectedModelAry();
_this.$emit("input", tmpAry);
}
})
},
},
template: `
`
})
/**
* Editor 编辑器
*/
Vue.component('spaceEditor', {
data: function () {
return {
id: "spaceEditor" + space.utils.random(6),
editor: undefined,
// 编辑器需要的 js 文件
jsUrl: [
'/apps/space/plug-in/ckeditor5/build/ckeditor.js',
'/apps/space/plug-in/ckeditor5/src/plugins/upload/src/myUploadAdapter.js?v=20260719-image-src'
],
// 标识,全部为 true 则代表全部加载完成
jsUrlFlag: [],
notLoadEditor: true, // 未加载完 editor 编辑器,true:未加载完,false:已加载完
imageQuality: 'standard',
uploading: false,
uploadStatus: '',
previewVisible: false,
previewMode: 'pc',
previewUrl: '',
previewLoading: false,
videoPlaybackSyncTimer: undefined,
activePdf: null,
uploadedImageUrls: [],
pdfFloatToolbarStyle: null,
_emitEditorHtmlTimer: undefined,
_enhancePdfTimer: undefined,
_pdfEnhancing: false,
defaultEditorFontFamily: "'仿宋_GB2312', 'FangSong_GB2312', FangSong, serif",
defaultEditorFontSize: "20pt",
defaultEditorLineHeight: "1.75",
pendingImportedWordImageSizes: [],
}
},
name: "spaceEditor",
model: {
prop: 'htmlContent',
evnet: 'click'
},
/**
* htmlContent: v-model 绑定的值,非空,html 字符串
* size: 编辑器的大小,small、medium、large
* width: 编辑器的宽度,可空
* height: 编辑器的高度,可空
* placeholder:占位符
* type:编辑器工具栏类型
* isfullscreen:是否有全屏,
*/
props: ['htmlContent', 'size', 'width', 'height', 'placeholder', 'type', 'isfullscreen', 'articlepreview', 'previewdata', 'previewurl', 'wordconverturl'],
computed: {
previewFrameStyle: function () {
var widthMap = {
pc: '1200px',
pad: '768px',
mobile: '390px'
};
return {
width: widthMap[this.previewMode] || widthMap.pc,
height: '680px'
};
}
},
watch: {
height: function (newVal, oldVal) {
if (this.height && this.height.toString().toLocaleLowerCase().indexOf('px') == -1) {
this.height += 'px';
} else {
this.setEditorHeight();
}
},
editor: function (newVal, oldVal) {
this.setEditorHeight();
},
jsUrlFlag: function (newVal, oldVal) {
if (this.jsUrl.length > 0 && this.jsUrl.length == this.jsUrlFlag.length) {
if (this.jsUrlFlag.indexOf('false') != -1) {
return;
}
this.initEditor();
this.notLoadEditor = false;
this.setEditorHeight();
}
},
notLoadEditor: function (newVal, oldVal) {
this.setEditorHeight();
},
},
created: function () {
var _this = this;
for (var i = 0; i < _this.jsUrl.length; i++) {
_this.loadJS(_this.jsUrl[i], function () {
_this.jsUrlFlag.push('true');
});
}
},
methods: {
loadJS: function (url, callback) {
for (var i = 0; i < document.getElementsByTagName('head')[0].getElementsByTagName('script').length; i++) {
var src = document.getElementsByTagName('head')[0].getElementsByTagName('script')[i].getAttribute('src');
if (url == src) {
// 防止一个页面有多个编辑器时,编辑器加载失败
if (space.vars.editorReady != true) {
var winInterval = setInterval(function () {
if (space.vars.editorReady != true) {
return;
}
window.clearInterval(winInterval);
if (callback) {
callback();
}
}, 100)
}
return;
}
}
var script = document.createElement('script');
script.type = 'text/javascript';
script.onload = function () {
if (callback) {
callback();
}
};
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
},
isArticlePreview: function () {
return this.articlepreview === true || this.articlepreview === 'true';
},
showEditorTools: function () {
return this.type != 'flow' && this.isArticlePreview();
},
normalizeEditorMediaUrl: function (url) {
if (space.utils.isNull(url)) {
return "";
}
return this.normalizeLocalUploadUrl(url);
},
getEditorEditableElement: function (editor) {
if (!editor) {
return null;
}
if (editor.ui && editor.ui.view && editor.ui.view.editable && editor.ui.view.editable.element) {
return editor.ui.view.editable.element;
}
if (editor.editing && editor.editing.view && typeof editor.editing.view.getDomRoot === 'function') {
var domRoot = editor.editing.view.getDomRoot();
if (domRoot) {
return domRoot;
}
}
if (editor.ui && typeof editor.ui.getEditableElement === 'function') {
var editable = editor.ui.getEditableElement();
if (editable) {
return editable;
}
}
if (editor.ui && editor.ui.view && editor.ui.view.element) {
return editor.ui.view.element.querySelector('.ck-editor__editable_inline');
}
return null;
},
normalizeVideoHtmlForEditor: function (html) {
if (!html || html.indexOf("