/** * 按钮组 */ Vue.component('spaceButtonTabs', { data: function () { return { mappingObj: {}, } }, name: "spaceButtonTabs", model: { prop: 'modelVal', evnet: 'click' }, props: ['modelVal', "data", "mapping", "label"], created: function () { this.initMapping(); }, methods: { change: function (val) { this.$emit("input", val); space.plugin.search.submit(); }, initMapping: function () { if (!this.mapping) { this.mapping = {}; } if (space.utils.isNull(this.mapping.name)) { this.mapping.name = "name"; } if (space.utils.isNull(this.mapping.value)) { this.mapping.value = "value"; } this.mappingObj = this.mapping; } }, template: `
{{label}}
` }) /** * Picker 组件 */ Vue.component('spacePicker', { data: function () { return { id: "SpacePicker" + space.utils.random(6), txt: '', mobileSelect: undefined, selectIndexArr: undefined, keyMaps: {}, } }, name: "spacePicker", // 选中的值,列名,数据,数据键转换,校验,返回值格式 props: ["value", "label", "wheels", "keymap", "rules", "valpath"], created: function () { this.keyMaps = space.utils.cloneObj(this.initKeyMap(this.keymap)); }, mounted: function () { if (space.utils.isNull(this.value)) { $("#" + this.id).find("div.van-field__right-icon").hide(); } this.initMobileSelect(); if (this.mobileSelect) { this.selectPickerValue(this.value); } }, watch: { value: function (newVal, oldVal) { // 需要指定选择项 this.selectPickerValue(newVal); var iconDom = $("#" + this.id).find("div.van-field__right-icon"); if (space.utils.notNull(newVal)) { $(iconDom).show(); } else { $(iconDom).hide(); } this.$emit('change', newVal); }, wheels: function (newVal, oldVal) { // 需要重新渲染数据 if (!this.mobileSelect) { this.initMobileSelect(); this.selectPickerValue(this.value); return; } // 判断是否存在级联,以调用不同的渲染方法,存在为真,否则为假 var isExistChildrenFlag = false; if (space.utils.notNull(newVal) && JSON.stringify(newVal).indexOf(this.keyMaps.childs) != -1) { isExistChildrenFlag = true; } // 存在级联 if (isExistChildrenFlag) { this.mobileSelect.updateWheels(newVal); } else { if (space.utils.isNull(newVal)) { this.mobileSelect.updateWheels({}); this.mobileSelect.updateWheel(0, {}); } else { this.mobileSelect.updateWheel(0, newVal); } } this.fieldClear(); }, valpath: function (newVal, oldVal) { // 默认是 false,如果是true,返回完整的数组,如果是false,返回最后一列的ID this.valpath = space.utils.isNull(newVal) ? false : newVal; } }, methods: { /** * 初始化 keymap,{id: '隐藏值的 key,默认 value', value: '显示值的 key,默认 text', childs: '子节点的 key,默认 children'} * @param {Object} keymap */ initKeyMap: function (km) { if (!km) { km = { id: 'value', value: 'text', childs: 'children' } } if (!km.id) { km.id = 'value'; } if (!km.value) { km.value = 'text'; } if (!km.childs) { km.childs = 'children'; } return km; }, /** * 初始化滚动选择器 */ initMobileSelect: function () { var that = this; // 防止初始化滚动选择器时,没有数据问题 if (that.wheels == undefined || that.wheels.length == 0) { return; } this.mobileSelect = new MobileSelect({ trigger: "#" + that.id, // title: that.label, wheels: [{ data: that.wheels || [] }], keyMap: that.keyMaps, connector: ' / ', position: [], triggerDisplayData: false, onShow: function () { if (space.utils.isNull(that.wheels)) { that.mobileSelect.hide(); space.message.warning("没有任何可选项"); return; } if (!that.selectIndexArr) { return; } for (var i = 0; i < that.selectIndexArr.length; i++) { that.mobileSelect.locatePosition(i, that.selectIndexArr[i]); } }, callback: function (indexArr, data) { // 默认是 false,如果是true,返回完整的数组,如果是false,返回最后一列的ID that.valpath = space.utils.isNull(that.valpath) ? false : that.valpath; if (that.valpath) { that.$emit("input", data); } else { that.$emit("input", data[data.length - 1][that.keyMaps.id]); } this.position = indexArr; that.selectIndexArr = indexArr; } }); }, /** * 选中值 * @param {Object} value */ selectPickerValue: function (value) { var val = value; // 是数组 [] if (value instanceof Array && value.length > 0) { val = value[value.length - 1][this.keyMaps.id]; } var map = this.getMobileSelectIndexAndText({ data: this.wheels, keyMap: this.keyMaps, selectValue: val }); if (!map) { // 防止已经选了值,再次赋值时未找到选项的时候,页面还显示原值的问题 this.fieldClear(); return; } for (var i = 0; i < map.indexAry.length; i++) { this.mobileSelect.locatePosition(i, map.indexAry[i]); } this.txt = map.text; this.selectIndexArr = map.indexAry; }, /** * 获取移动端下拉框选中的下标与文本 * * @param {Object} setting {data: [下拉框数据], keyMap: {id: '隐藏值的 key,默认 value', value: '显示值的 key,默认 text', childs: '子节点的 key,默认 children'}, selectValue: '选中的值'} */ getMobileSelectIndexAndText: function (setting) { if (!setting.data) { return undefined; } setting.keyMap = this.keyMaps; const indexAry = []; const selectTextAry = []; this.getSelectedByValue(setting.data, setting.keyMap, setting.selectValue, indexAry, selectTextAry); if (indexAry.length == 0 && selectTextAry.length == 0) { return undefined; } return { indexAry: indexAry, text: selectTextAry.join(" / ") }; }, /** * 根据选中的值,获取在数据数组中的索引数组 * * @param {Object} data 下拉框数据 * @param {Object} kayMap 数据的 key map 值,{id: '隐藏值的 key,默认 value', value: '显示值的 key,默认 text', childs: '子节点的 key,默认 children'} * @param {Object} selectValue 选中的值 * @param {Object} indexAry 选中的下标数组 * @param {Object} selectTextAry 选中的回显值数组 */ getSelectedByValue: function (data, kayMap, selectValue, indexAry, selectTextAry) { for (let i = 0; i < data.length; i++) { if (data[i][kayMap.id] == selectValue) { data.defaultIndex = i; indexAry.splice(0, 0, i); // 把 i 插入到索引为 0 的位置上 selectTextAry.splice(0, 0, data[i][kayMap.value]); return true; } if (data[i][kayMap.childs]) { const flag = this.getSelectedByValue(data[i][kayMap.childs], kayMap, selectValue, indexAry, selectTextAry); if (flag) { data.defaultIndex = i; indexAry.splice(0, 0, i); // 把 i 插入到索引为 0 的位置上 selectTextAry.splice(0, 0, data[i][kayMap.value]); return true; } } } return false; }, /** * 清空 */ fieldClear: function () { this.txt = ""; this.$emit("input", ""); if (this.mobileSelect) { this.mobileSelect.locatePosition(0, 0); } this.selectIndexArr = undefined; if (event) { event.stopPropagation(); } $("#" + this.id).find("div.van-field__right-icon").hide(); }, warpClick: function () { if (!this.mobileSelect) { space.message.warning("没有任何可选项"); } } }, template: `
` }) /** * Calendar 日历组件 */ Vue.component('spaceCalendar', { data: function () { return { id: "spaceDatetimePicker" + space.utils.random(6), isShow: false, txt: "", } }, name: "spaceCalendar", props: ["value", "label", "rules"], mounted: function () { if (space.utils.isNull(this.value)) { $("#" + this.id).find("div.van-field__right-icon").hide(); } }, methods: { /** * 清空 */ fieldClear: function () { this.txt = ""; this.isShow = false; this.$emit("input", ""); event.stopPropagation(); $("#" + this.id).find("div.van-field__right-icon").hide(); }, formatDate: function (date) { return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; }, onConfirm: function (date) { this.isShow = false; this.txt = this.formatDate(date); $("#" + this.id).find("div.van-field__right-icon").show(); this.$emit("input", this.txt); } }, template: `
` }) /** * DatetimePicker 组件 * type 时间类型,可选值为 date time year-month month-day datehour * type 的值为year-month,同时 typeflag 的值 year,即是选择年份 * type 的值为datetime,同时 typeflag 的值 noyear,即是选择月日时分,没有年份 */ Vue.component('spaceDatetimePicker', { data: function () { return { id: "spaceDatetimePicker" + space.utils.random(6), showDatetimePickerFlag: false, defalutFormat: 'YYYY-MM-DD HH:mm:ss', txt: '', currentDate: new Date(), minDate: new Date(1998, 0, 1), //可选的最小时间范围 } }, name: "spaceDatetimePicker", props: ["name", "value", "label", "type", "typeflag", "rules"], created: function () { }, mounted: function () { if (space.utils.isNull(this.value)) { $("#" + this.id).find("div.van-field__right-icon").hide(); } else { // 解决iOS时间格式问题 if (this.value.endsWith(".0")) { this.value = this.value.substring(0, this.value.lastIndexOf(".0")); } this.currentDate = new Date(this.value.replace(/-/g, '/')); this.txt = this.formatTime(this.currentDate, this.getTypeTimeFormat()); this.$emit("input", this.formatTime(this.currentDate, this.defalutFormat)); $("#" + this.id).find("div.van-field__right-icon").show(); } if (this.type == "time" && !this.value) { this.currentDate = new Date(); this.currentDate = this.formatTime(this.currentDate, this.getTypeTimeFormat()); } }, watch: { value: function (newVal, oldVal) { var valIsNullFlag = space.utils.isNull(newVal); if (valIsNullFlag) { $("#" + this.id).find("div.van-field__right-icon").hide(); } else { $("#" + this.id).find("div.van-field__right-icon").show(); } this.txt = valIsNullFlag ? "" : this.getTxtValue(newVal); // 如果只选择年份 if (this.type == "year-month" && this.typeflag == "year") { this.txt = this.txt.slice(0, this.txt.indexOf("-")) } // 如果选择月日时分,没有年份 if (this.type == "datetime" && this.typeflag == "noyear") { this.txt = this.txt.slice(this.txt.indexOf("-") + 1, this.txt.length); } if (this.type == "time") { this.currentDate = new Date(this.value.replace(/-/g, '/')); this.currentDate = this.formatTime(this.currentDate, this.getTypeTimeFormat()); } } }, methods: { showClick: function () { this.showDatetimePickerFlag = true; this.$nextTick(function () { // DOM 更新了 if (this.typeflag == "year") { // 如果只选择年份,去掉HTML元素 $(this.$refs.datetimePicker.$el).find(".van-picker-column").last().hide(); } else if (this.typeflag == "noyear") { $(this.$refs.datetimePicker.$el).find(".van-picker-column").first().hide(); } }) }, /** * 格式化时间 * @param {Object} time */ formatTime: function (time, format) { return dayjs(time).format(format); }, /** * 选中时间 * @param {Object} time */ datetimePickerConfirm: function (time) { if (this.type == "time") { this.txt = time; } else if (this.type == "year-month" && this.typeflag == "year") { // 如果只选择年份 this.txt = this.formatTime(time, this.getTypeTimeFormat()); this.txt = this.txt.slice(0, this.txt.indexOf("-")) } else { this.txt = this.formatTime(time, this.getTypeTimeFormat()); } this.showDatetimePickerFlag = false; this.$emit("input", this.getVModelValue(time)); }, getTxtValue: function (time) { if (this.type == "time" && time.length <= 5) { return time; } else { return this.formatTime(time, this.getTypeTimeFormat()); } }, getVModelValue: function (time) { if (this.type == "time") { return "2000-01-01 " + time + ":00"; } else { return this.formatTime(time, this.defalutFormat); } }, /** * 清空 */ fieldClear: function () { this.txt = ""; this.showDatetimePickerFlag = false; this.$emit("input", ""); event.stopPropagation(); $("#" + this.id).find("div.van-field__right-icon").hide(); }, getTypeTimeFormat: function () { if ('date' == this.type) { return 'YYYY-MM-DD';// 年月日 } else if ('time' == this.type) { return 'HH:mm';// 小时和分钟 } else if ('year-month' == this.type) { return 'YYYY-MM';// 年月 } else if ('month-day' == this.type) { return 'MM-DD';// 月和日 } else if ('datehour' == this.type) { return 'YYYY-MM-DD HH';// 年月日时 } else if ('datetime' == this.type) { return 'YYYY-MM-DD HH:mm';// 年月日时分 } } }, template: `
` }) /** * 选择器 * label 有传就是form的显示方式 */ Vue.component('spaceSelect', { data: function () { return { options: [], isOpen: true, // 是否打开 } }, name: "spaceSelect", model: { prop: 'modelAry', evnet: 'click' }, props: ['modelAry', "show", "predefine", "method", "label", "rules", "datasize"], watch: { modelAry: function (newVal, oldVal) { // 没有打开时,则可以初始化选择数据集合 if (!this.isOpen) { this.isOpen = true; } 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 () { this.initSelectedDataList(); }, methods: { /** * 获取最大限制绑定的值 */ getMaxSelectedModelAry: function () { var tmpAry = []; var _this = this; this.options.forEach(function (item) { tmpAry.push(item); }); 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); } }) }, // v-model数组合并去重 uniqFun: function (valueAry) { var that = this; // 数组合并 that.modelAry = that.modelAry.concat(valueAry); var newJson = []; //盛放去重后数据的新数组 for (var item1 of that.modelAry) { //循环json数组对象的内容 var flag = true; //建立标记,判断数据是否重复,true为不重复 for (var item2 of newJson) { //循环新数组的内容 if (item1.id == item2.id) { //让json数组对象的内容与新数组的内容作比较,相同的话,改变标记为false flag = false; } } if (flag) { //判断是否重复 newJson.push(item1); //不重复的放入新数组。 新数组的内容会继续进行上边的循环。 } } that.$emit("input", newJson); }, predefineFun: function () { var that = this; var dataSize2 = that.datasize || "9999"; if (!space.utils.isNumberAsObject(dataSize2)) { dataSize2 = "9999"; } if (that.modelAry) { var choosableSize = parseInt(dataSize2) - that.modelAry.length; if (choosableSize <= 0) { space.message.warning("数据已达上限"); return; } dataSize2 = choosableSize; } if (this.predefine == "person") { space.topWin.space.plugin.personChoose({ datasize: dataSize2 }, function (valueAry) { that.uniqFun(valueAry); }); } else if (this.predefine == "department") { space.topWin.space.plugin.departmentChoose({ datasize: dataSize2 }, function (valueAry) { that.uniqFun(valueAry); }); } else if (this.predefine == "post") { space.topWin.space.plugin.postChoose({ datasize: dataSize2 }, function (valueAry) { that.uniqFun(valueAry); }); } else if (this.predefine == "role") { space.topWin.space.plugin.roleChoose({ datasize: dataSize2 }, function (valueAry) { that.uniqFun(valueAry); }); } else { space.message.warning('预定义选择器不存在:' + this.predefine); } }, removeSingle: function (id) { this.modelAry = this.modelAry.filter(function (item) { return item.id != id; }) this.$emit("input", this.modelAry); }, // 查看全部 checkAll: function () { var that = this; space.topWin.space.plugin.layer.open({ url: '/apps?app=sys&destination=plugins.choose_all', size: 'mini', anim: 5, shade: [0.8, '#393D49'], shadeClose: true, data: { selectData: that.modelAry, show: that.show, predefine: that.predefine, method: that.method, datasize: that.datasize, // 收到回调 callback: function (data) { that.$emit("input", data.selectData); } } }) } }, template: `
` }) /** * 底部导航 */ Vue.component('spaceTabbar', { data: function () { return { config: spaceTabbar.config, tabbarList: spaceTabbar.tabbarList, backgroundColorVal: "", } }, name: "spaceTabbar", model: { prop: 'modelVal', evnet: 'click' }, props: ['modelVal', "spaceTabbar"], created: function () { // 最多支持6个tabbar if (this.tabbarList.length > 6) { this.tabbarList = this.tabbarList.slice(0, 6); console.error("最多支持6个tabbar"); } // 风格,可选值 “white”(白) 和 “grey”(灰),白色色值为 #ffffff, 灰色色值为 #f9f9f9,应用于整体背景色 if (this.config.style) { if (this.config.style == "white") { this.backgroundColorVal = "#ffffff"; } else if (this.config.style == "grey") { this.backgroundColorVal = "#f9f9f9"; } else { console.error("风格的可选值为 “white” 和 “grey”"); } } }, methods: { footBarChange: function (url) { if (space.utils.isNull(url)) { space.message.warning("Navigation URL is null!"); return; } space.plugin.loading.show(); this.$emit("input", space.utils.appendRandom(url)); }, }, template: `
` }) /** * 图片上传 */ Vue.component('spaceUploadImg', { data: function () { return { id: "spaceUploadImg" + space.utils.random(6), newAry: [] } }, name: "spaceUploadImg", model: { prop: 'patharry', evnet: 'click' }, /** * patharry: v-model 绑定的值,非空,字符串数组 * type: 上传按钮的风格,可空,缺省值为 button ,可选值为button / img * width: 图片裁剪的宽度,可空 * height: 图片裁剪的高度,可空 * maxsize: 最大上传的图片数量,可空,缺省值为1 * tip: 提示语,可空 * color: 图片背景,可空,值的类型与css的color值类型一样 * label: 左侧文本 * rules: 定义表单校验规则 */ 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], label: [String, Number], rules: Array }, created: function () { // 对初始化值进行处理,排除掉空数据 if (!this.patharry) { this.patharry = []; } if (typeof this.patharry == "string") { if (space.utils.notNull(this.patharry)) { this.newAry.push(this.patharry); } } else { for (let index = 0; index < this.patharry.length; index++) { const element = this.patharry[index]; if (space.utils.notNull(element)) { this.newAry.push(element); } } } this.$emit("input", this.newAry); }, mounted: function () { var that = this; space.plugin.cropper.init({ el: $("#" + that.id), photoSize: { // 裁剪的图片大小,会自动计算裁剪比例 width: that.width, height: that.height }, show: function (setting) { //打开裁剪框前的回调 setting.photoSize = { width: that.width, height: that.height } }, success: function (path) { // 成功后的回调方法,path为裁剪后的img路径 that.newAry.push(path); that.$emit("input", that.newAry); }, }); }, methods: { uploadClick: function () { if (this.newAry.length >= this.maxsize) { space.message.warning("最多上传" + this.maxsize + "张图片"); return false; } $("#" + this.id).click(); }, removeCropperImg: function (index) { this.newAry.splice(index, 1); this.$emit("input", this.newAry); }, imgPreview: function (index) { //大图预览 var that = this; vant.ImagePreview({ images: that.newAry, startPosition: index, }); } }, template: `
` }) /** * 图片预览 */ Vue.component('spacePreviewImg', { data: function () { return { newAry: [], } }, name: "spacePreviewImg", /** * paths: 绑定的值,非空,字符串/数组 * color: 图片背景色,可空,值的类型与css的color值类型一样 */ props: { paths: { type: [Array, String], required: true }, color: { type: String, }, cell: { type: String, default: 'false', }, label: [String, Number] }, created: function () { this.initNewAry(); }, watch: { paths: function (newVal, oldVal) { this.initNewAry(); }, }, methods: { imgPreview: function (index) { //大图预览 var that = this; space.topWin.vant.ImagePreview({ images: that.newAry, startPosition: index, }); }, initNewAry: function () { // 对初始化值进行处理,排除掉空数据 if (!this.paths) { this.paths = []; } this.newAry = []; 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); } }, template: `
` }) /** * Editor 编辑器 */ Vue.component('spaceEditor', { data: function () { return { id: "spaceEditor" + space.utils.random(6), editor: undefined, isSetData: true, // 是否可设置数据 // 编辑器需要的 js 文件 jsUrl: [ '/apps/space/plug-in/ckeditor5/build/ckeditor.js', '/apps/space/plug-in/ckeditor5/src/plugins/upload/src/myUploadAdapter.js' ], // 标识,全部为 true 则代表全部加载完成 jsUrlFlag: [], notLoadEditor: true, // 未加载完 editor 编辑器,true:未加载完,false:已加载完 } }, 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'], 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); }, myCustomUploadAdapterPlugin: function (editor) { editor.plugins.get('FileRepository').createUploadAdapter = (loader) => { // 第二个参数设置上传图片的地址 return new MyUploadAdapter(loader); }; }, /** * 获取高度 */ getHeight: function () { if (!this.height) { if (this.size == undefined || this.size == "small") { return '200px'; } else if (this.size == "medium") { return '400px'; } else if (this.size == "large") { return '600px'; } } else if (this.height) { if (this.height.toString().toLocaleLowerCase().indexOf('px') == -1) { return this.height + 'px'; } else { return this.height; } } return ""; }, /** * 设置编辑器高度 */ setEditorHeight: function () { if (this.notLoadEditor) { return; } var height = this.getHeight(); if (!this.editor || !height) { return; } var _this = this; // 设置编辑器高度 _this.editor.editing.view.change(writer => { writer.setStyle( "height", height, _this.editor.editing.view.document.getRoot() ); }); }, /** * 获取工具栏 */ getToolbar: function () { var toolbar = { items: ['fontsize', 'fontColor', 'bold', 'italic', 'phrase'] }; if (!this.type) { return toolbar; } var map = new Map(); map.set("flow", ['phrase']); if (map.get(this.type)) { return { items: map.get(this.type) } } return toolbar; }, /** * 初始化编辑器 */ initEditor: function () { var toolbar = this.getToolbar(); var _this = this; ClassicEditor.create(document.querySelector("#" + _this.id), { extraPlugins: [_this.myCustomUploadAdapterPlugin], // 添加上传适配器 toolbar: toolbar || {}, language: 'zh-cn', placeholder: _this.placeholder || '', }).then(editor => { space.vars.editorReady = true; _this.editor = editor; if (_this.htmlContent != undefined) { _this.editor.setData(_this.htmlContent); } /** * 禁止在编辑器内回车事件 */ editor.ui.view.element.onkeydown = function (event) { // 回车键 if (event.keyCode == 13) { event.stopPropagation(); return false; } // tab 转空格 if (event.keyCode == 9) { const model = editor.model; model.change(writer => { const ele = writer.createElement('span'); writer.insertText(" ", ele); // 一定要 Element model.insertContent(ele); }); event.stopPropagation(); return false; } }; // 设置编辑器宽度 if (_this.width) { $(editor.ui.view.element).css({ 'width': _this.width }) } // 监听编辑器的内容变动事件 editor.model.document.on('change:data', function () { _this.$emit("input", editor.getData()); }); }).catch(error => { console.log(error); }); } }, template: `
` }) /** * 对象菜单 */ Vue.component('spaceMobileTabs', { data: function () { return { isShowPop: false, //弹窗 activeUrl: "", //当前iframe的src isScroll: false, //是否出现横向滚动条 random: space.utils.random(6), } }, name: "spaceMobileTabs", model: { prop: 'modelObj', evnet: 'click' }, props: ['modelObj'], created: function () { var that = this; space.topWin.layer.load(2); var index = that.modelObj.length; while (index--) { const element = that.modelObj[index]; // 过滤掉 if (space.utils.notNull(element.filter) && element.filter == 'no') { that.modelObj.splice(index, 1); continue; } } if (that.modelObj.length == 0) { space.topWin.space.message.warning("你无权访问此页面"); space.utils.window.close(); return; } //没有active,默认选中第一个 that.activeUrl = that.modelObj[0].url; // 有active,选中active项 that.modelObj.forEach(function (item, index) { if (item.active) { that.activeUrl = item.url; } }) }, mounted: function () { // DOM 更新了 this.$nextTick(function () { // 是否出现滚动条 this.isScroll = $(this.$refs.spaceMobileTabsWrap).find(".van-tabs__wrap").hasClass("van-tabs__wrap--scrollable"); }) space.vars.isMobileTabs = true; }, methods: { clickFun: function (url, title) { this.activeUrl = url; this.isShowPop = false; this.random = space.utils.random(6); }, }, template: `

  • {{item.label}}
` }) /** * CMS */ Vue.component('spaceCms', { data: function () { return { fileCount: 0, // 文件总数 } }, name: "spaceCms", model: { prop: 'cmsid', evnet: 'click' }, props: { // v-model cmsid: { type: [String], required: true }, // 文件类型 accept: { type: String }, // 最大上传数量,默认199 maxsize: { type: [String, Number], default: 199 }, // 左侧文本 label: String, // 定义表单校验规则 rules: Array }, created: function () { this.getCmsFileCount(this.cmsid); }, watch: { cmsid: function (newVal, oldVal) { this.getCmsFileCount(newVal); } }, methods: { open: function () { space.plugin.cms.openCMS({ "cmsid": this.cmsid, "accept": this.accept, "maxsize": this.maxsize }, this.callback); }, callback: function (data) { this.$emit("input", data.cmsid); this.cmsid = data.cmsid; this.fileCount = data.fileCount; }, getCmsFileCount: function (cmsid) { if (space.utils.isNull(cmsid)) { return; } var that = this; space.utils.ajax({ loadLayer: false, url: '/apps?ark=sys.cms_getCmsInfo', data: { "idcard": cmsid }, dataType: 'json', autoTip: false, async: false, // 同步请求 callback: function (data) { if (data.code == "success") { that.fileCount = data.data.filecount; } } }); } }, template: `
` }) /** * CMS预览 * 有传label就是左侧有文本的cell信息格式,不传则不是 */ Vue.component('spaceCmsView', { data: function () { return { thumbnail: "", //thumbnail: 缩略图 filename: "", //filename: 文件名 filecount: 0, //filecount: 文件数 isShowEl: true, //是否显示整个组件元素 } }, name: "spaceCmsView", /** * cmsid: 绑定的值,非空 * label: 左侧文本 */ props: { cmsid: { type: [String, Number], required: true }, label: String }, created: function () { var that = this; if (space.utils.isNull(that.cmsid)) { // 不显示整个组件元素 that.isShowEl = false; return; } space.utils.ajax({ loadLayer: false, url: '/apps?ark=sys.cms_getCmsInfo', data: { "idcard": that.cmsid }, dataType: 'json', autoTip: false, async: false, // 同步请求 callback: function (data) { if (data.code == "success") { that.thumbnail = data.data.thumbnail; that.filename = data.data.filename; that.filecount = data.data.filecount; } else if (data.code == "warning") { // 不显示整个组件元素 that.isShowEl = false; } } }); }, methods: { open: function () { var that = this; space.plugin.cms.openCMSView({ cmsid: that.cmsid }) }, }, template: `
{{filename}} (空)
` }) /** * 对象选择器内容 */ Vue.component('spaceObjectSelectContent', { data: function () { return { dataList: [], // 数据 selectResult: [], //选中的数据 isShowPop: false, //底部弹窗开关 } }, name: "spaceObjectSelectContent", model: { prop: 'selectDataList', evnet: 'click' }, /** * selectDataList: v-model,绑定的值, 已选数组 * url: 数据源对象 * filter: 过滤条件对象 * maxsize: 最大选择数量,如未声明,则默认为1,如已选数组已超过最大选择数量,则按照数组顺序截取 * confirm: 事件参数,当点击了已选区域的“确定”按钮时,触发此事件 */ props: { selectDataList: { type: Array, required: true }, url: { type: String }, filter: { type: Object }, mapping: { type: Object }, maxsize: { type: [String, Number], default: 1 }, confirm: { type: Function } }, created: function () { this.initMapping(); }, mounted: function () { var that = this; space.plugin.paging.init({ url: that.url, data: that.filter, up: function (resp) { that.dataList.push.apply(that.dataList, resp[that.mapping.data]); }, down: function () { that.dataList = []; }, }); }, methods: { // 选中点击事件 checkboxClick: function (id) { var that = this; // if (this.selectResult.length == this.maxsize) { // this.$toast('最多选择' + this.maxsize + "项"); // } if (this.selectResult.indexOf(id) > -1) { that.selectDataList = []; that.selectResult.forEach(function (item) { that.dataList.forEach(function (dataItem) { if (item == dataItem[that.mapping.id]) { that.selectDataList.indexOf(dataItem) > -1 ? "" : that.selectDataList.push(dataItem); } }) }) } else { this.selectDataList = this.selectDataList.filter(function (item) { return item[that.mapping.id] != id; }) } this.$emit("input", this.selectDataList); }, initMapping: function () { if (!this.mapping) { this.mapping = {}; } if (space.utils.isNull(this.mapping.data)) { this.mapping.data = "data"; } if (space.utils.isNull(this.mapping.id)) { this.mapping.id = "id"; } if (space.utils.isNull(this.mapping.icon)) { this.mapping.icon = "icon"; } if (space.utils.isNull(this.mapping.name)) { this.mapping.name = "name"; } if (space.utils.isNull(this.mapping.tag)) { this.mapping.tag = "tag"; } }, mappingResult: function (data) { var newDataAry = []; for (let index = 0; index < data.length; index++) { const element = data[index]; var newEle = {}; newEle["id"] = ("id" in element) ? element.id : element[this.mapping.id]; newEle["icon"] = ("icon" in element) ? element.icon : element[this.mapping.icon]; newEle["name"] = ("name" in element) ? element.name : element[this.mapping.name]; newEle["tag"] = ("tag" in element) ? element.tag : element[this.mapping.tag]; newDataAry[index] = newEle; } return newDataAry; }, // 初始化选中的数据 initSelectDataList: function () { var that = this; // 反向映射 var newDataAry = []; for (let index = 0; index < that.selectDataList.length; index++) { const element = that.selectDataList[index]; var newEle = {}; newEle[this.mapping.id] = ("id" in element) ? element.id : element[this.mapping.id]; newEle[this.mapping.icon] = ("icon" in element) ? element.icon : element[this.mapping.icon]; newEle[this.mapping.name] = ("name" in element) ? element.name : element[this.mapping.name]; newEle[this.mapping.tag] = ("tag" in element) ? element.tag : element[this.mapping.tag]; newDataAry[index] = newEle; } that.selectDataList = newDataAry; // 重新赋值 that.selectDataList.forEach(function (item) { that.selectResult.push(item[that.mapping.id]); }); //如已选数组已超过最大选择数量,则按照数组顺序截取 if (that.selectResult.length > that.maxsize) { that.selectResult = that.selectResult.slice(0, that.maxsize); that.selectDataList = that.selectDataList.slice(0, that.maxsize); } this.$emit("input", this.selectDataList); }, isShowPopClick: function () { // 没有已选,不弹弹窗 this.isShowPop = this.selectDataList.length <= 0 ? false : !this.isShowPop; }, // 删除 removeSelect: function (id) { var that = this; this.selectResult.splice(this.selectResult.indexOf(id), 1); this.selectDataList = this.selectDataList.filter(function (item) { return item[that.mapping.id] != id; }) if (this.selectResult <= 0) { this.isShowPop = false; } this.$emit("input", this.selectDataList); }, confirmEvent: function () { this.confirm(this.mappingResult(this.selectDataList)); } }, template: `
{{item[mapping.name]}}

{{item[mapping.tag]}}

  • {{item[mapping.name]}}

    {{item[mapping.tag]}}

` }) /** * 对象选择器外层 */ Vue.component('spaceObjectSelect', { data: function () { return { } }, name: "spaceObjectSelect", model: { prop: 'selectResult', evnet: 'click' }, /** * selectResult: v-model,绑定的值, 已选数组 * maxsize: 最大选择数量,如未声明,则默认为1 * page: 路径 * label: 左侧文本 */ props: { selectResult: { type: Array, required: true }, maxsize: { type: [String, Number], default: 1 }, translate: { type: String }, page: { type: String, required: true }, mapping: { type: Object, }, label: { type: String, }, rules: { type: Array, }, show: { type: String, default: "tag" }, }, created: function () { // 初始化映射 this.initMapping(); // 需要翻译,但未传入翻译服务 if (space.utils.notNull(this.selectResult) && space.utils.isNull(this.translate)) { console.error("需要翻译已选数组对象,但未传入翻译服务"); return; } }, mounted: function () { this.translateSelect(); }, watch: { }, methods: { // 初始化映射对象 initMapping: function () { if (!this.mapping) { this.mapping = {}; } if (space.utils.isNull(this.mapping.data)) { this.mapping.data = "data"; } if (space.utils.isNull(this.mapping.id)) { this.mapping.id = "id"; } if (space.utils.isNull(this.mapping.icon)) { this.mapping.icon = "icon"; } if (space.utils.isNull(this.mapping.name)) { this.mapping.name = "name"; } if (space.utils.isNull(this.mapping.tag)) { this.mapping.tag = "tag"; } }, mappingResult: function (data) { for (let index = 0; index < data.length; index++) { var element = data[index]; if (!("id" in element)) { element["id"] = element[this.mapping.id]; } if (!("icon" in element)) { element["icon"] = element[this.mapping.icon]; } if (!("name" in element)) { element["name"] = element[this.mapping.name]; } if (!("tag" in element)) { element["tag"] = element[this.mapping.tag]; } } return data; }, translateSelect: function () { var that = this; // 翻译已选内容 if (space.utils.notNull(that.selectResult)) { space.utils.ajax({ url: that.translate, data: { ids: that.selectResult.join(",") }, dataType: 'json', async: false, callback: function (resp) { if (resp.code == "success") { // 映射字段保持与标准一致 that.selectResult = that.mappingResult(resp[that.mapping.data]); that.$emit("input", that.selectResult); } } }) } }, open: function () { var that = this; space.plugin.layer.open({ url: that.page, data: { selectResult: that.selectResult, maxsize: that.maxsize, callback: function (data) { // 回调 // console.log(data); that.selectResult = data; that.$emit("input", that.selectResult); } } }) }, removeSingle: function (id) { this.selectResult = this.selectResult.filter(function (item) { return item.id != id; }) this.$emit("input", this.selectResult); }, // 查看全部 checkAll: function () { var that = this; space.topWin.space.plugin.layer.open({ url: '/apps?app=sys&destination=plugins.object_choose_all', size: 'mini', anim: 5, shade: [0.8, '#393D49'], shadeClose: true, data: { page: that.page, selectData: that.selectResult, show: that.show, datasize: that.maxsize, callback: function (data, callback2) { that.$emit("input", data.selectData); if (callback2) { callback2(); } } } }) } }, template: `
` })