| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199 |
- /**
- * 按钮组
- */
- 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: `
- <div class="component-wrap">
- <div class="main-AdSearch-title" v-if="space.utils.notNull(label)">{{label}}</div>
- <ul class="main-tabs-ul">
- <li v-for="(item) in data" :class="{'tabs-active' : modelVal == item[mappingObj.value]}" @click="change(item[mappingObj.value])">
- <a href="javascript:;">
- {{item[mappingObj.name]}}
- </a>
- </li>
- </ul>
- </div>
- `
- })
- /**
- * 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: `
- <div class="component-wrap" :id="id" @click="warpClick" >
- <van-field :rules="rules" readonly clickable clearable right-icon="clear" :value="txt" :label="label" :placeholder="'点击选择'+label" @click-right-icon="fieldClear" ></van-field>
- </div>
- `
- })
- /**
- * 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: `
- <div class="component-wrap" :id="id">
- <van-field :rules="rules" readonly clickable clearable right-icon="clear" :value="txt" :label="label" :placeholder="'点击选择'+label" @click="isShow = true;" @click-right-icon="fieldClear"></van-field>
- <van-calendar v-model="isShow" @confirm="onConfirm"></van-calendar>
- </div>
- `
- })
- /**
- * 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: `
- <div class="component-wrap" :id="id">
- <van-field :rules="rules" readonly clickable clearable right-icon="clear" :value="txt" :label="label" :placeholder="'点击选择'+label" @click="showClick" @click-right-icon="fieldClear"></van-field>
- <van-popup v-model="showDatetimePickerFlag" position="bottom" get-container="#space-content">
- <van-datetime-picker :min-date="minDate" v-model="currentDate" :type="type" :title="'选择'+label" @confirm="datetimePickerConfirm" @cancel="showDatetimePickerFlag = false" ref="datetimePicker"></van-datetime-picker>
- </van-popup>
- </div>
- `
- })
- /**
- * 选择器
- * 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: `
- <div class="space-select" :class="{'component-wrap': label}">
- <van-field :label="label" :rules="rules" :value="modelAry">
- <template #input>
- <div class="space-select-image" v-if="show == 'image'">
- <ul>
- <li v-if="modelAry.length > 3" @click="checkAll">
- <div class="space-select-image-wrap space-select-all" >
- <van-icon name="ellipsis" ></van-icon>
- </div>
- <p>查看全部</p>
- </li>
- <li v-for="(item,index) in modelAry.slice(0,3)" :key="item.id" @click="removeSingle(item.id)" >
- <div class="space-select-image-wrap">
- <van-image :src="item.icon">
- <template v-slot:error>{{item.name}}</template>
- </van-image>
- <van-icon name="clear" class="space-select-image-close" @click="removeSingle(item.id)"></van-icon>
- </div>
- <p>{{item.name}}</p>
- </li>
- <li class="space-select-image-choice" @click="predefineFun" v-if="predefine" :class="{'hasOther': modelAry.length > 0}">
- <div class="space-select-image-wrap">
- <van-icon name="plus" ></van-icon>
- </div>
- </li>
- <li class="space-select-image-choice" @click="method" v-if="method" :class="{'hasOther': modelAry.length > 0}">
- <div class="space-select-image-wrap">
- <van-icon name="plus" ></van-icon>
- </div>
- </li>
- </ul>
- </div>
- <div class="space-select-tag" v-if="show != 'image'">
- <van-tag size="medium" color="#eaf2fd" text-color="#5094f2" v-if="modelAry.length > 1" @click="checkAll">
- 全部
- </van-tag>
- <van-tag closeable size="medium" color="#eaf2fd" text-color="#5094f2" @close="removeSingle(item.id)" v-for="(item,index) in modelAry.slice(0,1)" :key="item.id">
- {{item.name}}
- </van-tag>
- <span class="space-select-tag-choice" @click="predefineFun" v-if="predefine">
- <van-icon name="plus" ></van-icon>
- 选择
- </span>
- <span class="space-select-tag-choice" @click="method" v-if="method">
- <van-icon name="plus" ></van-icon>
- 选择
- </span>
- </div>
- </template>
- </van-field>
- </div>
- `
- })
- /**
- * 底部导航
- */
- 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: `
- <div class="space-tabbar">
- <ul class="space-tabbar-list" :style="{'background-color':backgroundColorVal}">
- <li @click="footBarChange(item.url)" v-for="(item,index) in tabbarList" :key="index" v-if="space.utils.isNull(item.filter) || item.filter != 'no'" :style="{'color': modelVal.indexOf(item.url) != -1 ? config.selectedColor : config.color}" :class="item.class">
- <div class="space-tabbar-img-wrap">
- <img :src="modelVal.indexOf(item.url) != -1 ? item.selectedIconPath : item.iconPath" alt="">
- <span class="space-tabbar-dot" v-if="item.dot"></span>
- </div>
- <p>
- {{item.text}}
- </p>
- </li>
- </ul>
- </div>
- `
- })
- /**
- * 图片上传
- */
- 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: `
- <div class="space-upload-img" :class="{'component-wrap': label}">
- <van-field :label="label" :rules="rules" :value="newAry">
- <template #input>
- <van-button icon="upgrade" native-type="button" type="default" size="small" @click="uploadClick" :disabled="newAry.length >= maxsize" v-if="type == 'button'">上传</van-button>
- <span v-show="newAry.length >= maxsize" style="color: #C0C4CC;margin-left: 6px;">
- 最多上传{{maxsize}}张图片
- </span>
- <span v-show="tip" style="color: #888;margin-left: 6px;">
- {{tip}}
- </span>
- <input type="file" accept="image/*" :id="id" style="display: none;" />
- <div class="cropper-img-wrap">
- <div v-show="newAry" class="cropper-img-content" v-for="(item, index) in newAry" :key="index"">
- <van-image width="80" height="80" fit="contain" :style="{'background-color': color}"
- :src="item" @click="imgPreview(index)">
- <template v-slot:error>加载失败</template>
- </van-image>
- <div class="cropper-preview-delete">
- <van-icon name="cross" @click="removeCropperImg(index)"></van-icon>
- </div>
- </div>
- <div class="uploadButton-img" v-if="type == 'img'" @click="uploadClick" v-show="newAry.length < maxsize">
- <van-icon name="photograph"></van-icon>
- </div>
- </div>
- </template>
- </van-field>
- </div>
- `
- })
- /**
- * 图片预览
- */
- 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: `
- <van-cell v-if="cell == 'true'" :title="label" size="large">
- <template #right-icon>
- <div class="van-cell__value">
- <div class="space-preview-img" style="flex:1.2;" >
- <div class="cropper-img-content" v-for="(item, index) in newAry" :key="index">
- <van-image width="80" height="80" fit="contain" :style="{'background-color': color}"
- :src="item" @click="imgPreview(index)">
- <template v-slot:error>加载失败</template>
- </van-image>
- </div>
- </div>
- </div>
- </template>
- </van-cell>
- <div v-else class="space-preview-img" style="margin-left:12px">
- <div class="cropper-img-content" v-for="(item, index) in newAry" :key="index">
- <van-image width="80" height="80" fit="contain" :style="{'background-color': color}"
- :src="item" @click="imgPreview(index)">
- <template v-slot:error>加载失败</template>
- </van-image>
- </div>
- </div>
- `
- })
- /**
- * 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: `
- <div :id="id">
- <script type="text/plain"></script>
- </div>
- `
- })
- /**
- * 对象菜单
- */
- 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: `
- <div class="space-mobile-tabs">
- <div class="space-mobile-tabs-list" ref="spaceMobileTabsWrap">
- <van-tabs v-model="activeUrl" color="#1989fa" @click="clickFun">
- <van-tab :title="item.label" v-for="(item, index) in modelObj" :name="item.url" ></van-tab>
- </van-tabs>
- <p v-if="isScroll">
- <van-icon class="space-mobile-tabs-icon" name="wap-nav" @click="isShowPop = true;"></van-icon>
- </p>
- <van-popup v-model="isShowPop" position="top" :style="{ height: '40%' }">
- <ul class="space-mobile-tabs-popList">
- <li :class="{'active': activeUrl == item.url}" v-for="(item, index) in modelObj" @click="clickFun(item.url, index)" >
- {{item.label}}
- </li>
- </ul>
- </van-popup>
- </div>
- <div class="space-mobile-tabs-iframe">
- <iframe :src="activeUrl + '&rn=' + random" frameborder="0"></iframe>
- </div>
- </div>
- `
- })
- /**
- * 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: `
- <div class="space-upload-CMS" :class="{'component-wrap': label}">
- <van-field :label="label" :rules="rules" :value="cmsid">
- <template #input>
- <van-badge :content="fileCount" v-show="fileCount > 0" color="#1989fa">
- <van-button icon="upgrade" native-type="button" type="default" size="small" @click="open">上传文件</van-button>
- </van-badge>
- <van-button icon="upgrade" native-type="button" type="default" size="small" @click="open" v-show="fileCount == 0">上传文件</van-button>
- </template>
- </van-field>
- </div>`
- })
- /**
- * 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: `
- <van-cell v-if="label" :title="label" size="large">
- <template #right-icon>
- <div class="van-cell__value">
- <div class="space-cms-view" v-if="isShowEl">
- <div class="space-cms-view-wrap" @click="open">
- <div class="space-cms-view-main">
- <van-image fit="contain" :src="thumbnail""></van-image>
- <span>{{filename}}</span>
- </div>
- <div v-show="filecount >=2 " class="more-file"></div>
- <div v-show="filecount >=2 " class="more-file more-file-bottom"></div>
- </div>
- </div>
- </div>
- </template>
- </van-cell>
- <div class="space-cms-view" v-else >
- <div class="space-cms-view-wrap" @click="open" v-if="isShowEl" >
- <div class="space-cms-view-main">
- <van-image fit="contain" :src="thumbnail""></van-image>
- <span>{{filename}}</span>
- <span v-if="filecount==0">(空)</span>
- </div>
- <div v-show="filecount >=2 " class="more-file"></div>
- <div v-show="filecount >=2 " class="more-file more-file-bottom"></div>
- </div>
- </div>
- `
- })
- /**
- * 对象选择器内容
- */
- 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: `
- <div class="space-object-select-content">
- <div class="obj-select-list">
- <div id="mescroll" class="mescroll importantMescroll">
- <van-checkbox-group v-model="selectResult" :max="maxsize">
- <van-checkbox v-for="item in dataList" :key="item[mapping.id]" :name="item[mapping.id]" shape="square" @click="checkboxClick(item[mapping.id])" >
- <!-- 左边 -->
- <div class="contacts-list-left">
- <van-image :src="item[mapping.icon]" v-show="item[mapping.icon]">
- <template v-slot:error>
- <van-icon name="user-o"></van-icon>
- </template>
- </van-image>
- </div>
- <!-- 右边 -->
- <div class="contacts-list-right">
- <div class="contacts-list-title">
- {{item[mapping.name]}}
- </div>
- <div class="contacts-list-desc">
- <p>
- <span>
- {{item[mapping.tag]}}
- </span>
- </p>
- </div>
- </div>
- </van-checkbox>
- </van-checkbox-group>
- </div>
- </div>
- <div class="obj-select-footer" @click="isShowPopClick">
- 已选
- <span class="obj-select-count">
- {{selectResult.length}}
- </span>
- / {{maxsize}}
- 项
- <van-button square type="info" @click.stop="confirmEvent">确定</van-button>
- </div>
- <!-- 底部弹出框 -->
- <van-popup v-model="isShowPop" round position="bottom" :style="{ 'max-height': '85%' }" >
- <div class="obj-selecte-pop">
- <ul>
- <li v-for="item in selectDataList">
- <!-- 左边 -->
- <div class="contacts-list-left">
- <van-image :src="item[mapping.icon]" v-show="item[mapping.icon]">
- <template v-slot:error>
- <van-icon name="user-o"></van-icon>
- </template>
- </van-image>
- </div>
- <!-- 右边 -->
- <div class="contacts-list-right">
- <div class="contacts-list-title">
- {{item[mapping.name]}}
- </div>
- <div class="contacts-list-desc">
- <p>
- <span>
- {{item[mapping.tag]}}
- </span>
- </p>
- </div>
- </div>
- <!-- 删除 -->
- <van-icon name="close" class="obj-remove-icon" @click="removeSelect(item[mapping.id])"></van-icon>
- </li>
- </ul>
- </div>
- </van-popup>
- </div>`
- })
- /**
- * 对象选择器外层
- */
- 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: `
- <div class="space-select space-object-select" :class="{'component-wrap': label}">
- <van-field :label="label" :rules="rules" :value="selectResult">
- <template #input>
- <div class="space-select-image" v-if="show == 'image'">
- <ul>
- <li v-if="selectResult.length > 3" @click="checkAll">
- <div class="space-select-image-wrap space-select-all" >
- <van-icon name="ellipsis" ></van-icon>
- </div>
- <p>查看全部</p>
- </li>
- <li v-for="(item,index) in selectResult.slice(0,3)" :key="item.id" @click="removeSingle(item.id)" >
- <div class="space-select-image-wrap">
- <van-image :src="item.icon">
- <template v-slot:error>{{item.name}}</template>
- </van-image>
- <van-icon name="clear" class="space-select-image-close" @click="removeSingle(item.id)"></van-icon>
- </div>
- <p>{{item.name}}</p>
- </li>
- <li class="space-select-image-choice" @click="open" :class="{'hasOther': selectResult.length > 0}">
- <div class="space-select-image-wrap">
- <van-icon name="plus" ></van-icon>
- </div>
- </li>
- </ul>
- </div>
- <div class="space-select-tag" v-if="show != 'image'">
- <van-tag size="medium" color="#eaf2fd" text-color="#5094f2" v-if="selectResult.length > 1" @click="checkAll">
- 全部
- </van-tag>
- <van-tag closeable size="medium" color="#eaf2fd" text-color="#5094f2" @close="removeSingle(item.id)" v-for="(item,index) in selectResult.slice(0,1)" :key="item.id">
- {{item.name}}
- </van-tag>
- <span class="space-select-tag-choice" @click="open">
- <van-icon name="plus" ></van-icon>
- 选择
- </span>
- </div>
- </template>
- </van-field>
- </div>`
- })
|