/***********************************************/ //vue 常用组件封装 //CREATE:zh 2018-6-1 /***********************************************/ //mixin 键盘扫描公共事件 var documentKeyMixin = { data: function () { return { focus: "", //当前扫码码值 workPlatform: "", //当前分拣台 } }, methods: { //键盘回车工厂事件,可在外部vue的methods中重写 keyDownFactory: function () { var $this = this; console.log($this.focus); }, documentKeyDown: function (e) { var $this = this; var keyArray = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ".", "+", "-", "*", "/", "_"]; var _focus = $("#txtFocus"); if (_focus.length > 0) _focus.focus(); var _key = e.key.toUpperCase(); if ($.inArray(_key, keyArray) > -1) { $this.focus += _key; } if (e.keyCode == 8) { if (window.event.srcElement.tagName.toUpperCase() != "INPUT" && window.event.srcElement.tagName.toUpperCase() != "TEXTAREA" && window.event.srcElement.tagName.toUpperCase() != "TEXT") { e.keyCode = 0; e.returnValue = false; e.preventDefault(); } else { if ($this.focus) { $this.focus = $this.focus.substr(0, $this.focus.length - 1); e.preventDefault(); } } } if (e.keyCode == 13 && $this.focus) { $this.keyDownFactory(); } }, alert: function (msg) { var $this = this; document.onkeydown = function (e) { return false; } layer.alert(msg, { icon: 0, yes: function (index, layero) { document.onkeydown = $this.documentKeyDown; layer.close(index); }, cancel: function (index, layero) { document.onkeydown = $this.documentKeyDown; } }); }, notifyAlert: function (type, msg) { var $this = this; if (type == "success" || type == "warning") { var title = type == "success" ? "成功" : "警告"; $this.$notify({ title: title, message: msg, type: type }); } else { $this.$notify.error({ title: '错误', message: msg }); } }, setCookie: function (name, value) {//设置cookie,时间30天 var days = 30; var expires = new Date(); expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000); document.cookie = name + "=" + escape(value) + ";expires=" + expires.toGMTString(); } }, mounted: function () { document.onkeydown = this.documentKeyDown; if ($('#txtFocus')) { $('#txtFocus').focus(); } //初始化条码前缀 GetNumRule(); } }; //带标题text Vue.component('input-text', { props: ['title', 'id', 'value', 'width', 'readonly', 'expandstyle', 'disabled'], data: function () { return { w: this.width || 160, s: this.expandstyle || '', defaultTitle: this.title ? this.title + ":" : "" }; }, template: '
', methods: { inputChange: function ($event) { this.$emit('input', $event.target.value); } } }); Vue.component('input-number', { props: ['title', 'id', 'value', 'width', 'readonly', 'expandstyle'], data: function () { return { w: this.width || 160, s: this.expandstyle || '' }; }, template: '
', methods: { inputChange: function ($event) { this.$emit('input', $event.target.value); }, keyEvent: function ($event) { if ($event.target.value.length == 1) { var reg = /[^1-9]/g; //return reg.test($event.target.value); $event.target.value = $event.target.value.replace(/[^1-9]/g, ''); } else { var reg = /\D/g; //return reg.test($event.target.value); $event.target.value = $event.target.value.replace(/\D/g, ''); } } } }); //带标题下拉框dropbox Vue.component('input-drowdownbox', { props: ['title', 'id', 'width', 'name', 'datalist', 'val', 'defaultvalue'], data: function () { return { w: this.width || 140, dataList: this.datalist, defaultValue: this.defaultvalue || '全部', defaultVal: this.val || '全部', defaultTitle: this.title ? this.title + ":" : "" } }, template: '
' + '' + '
' + '' + '' + '' + '' + '' + '
' + '
', methods: { itemclick: function (val) { this.$emit('getvalue', val); } }, watch: { datalist: function (val) { this.dataList = val; }, val: function (newValue) { this.defaultVal = newValue; } } }); //配置属性列表 Vue.component('input-config', { props: ['configlist'], template: '
' + '
' + '配置' + '' + '
' + '
', methods: { itemchangechecked: function (c) { c.value = !c.value; this.$emit('changechecked', c); } } }); //单列div button Vue.component('div-button', { props: ['title', 'classname'], data: function () { return { class_name: this.classname || 'button' } }, template: '
' + '{{title}}' + '
', methods: { childclick: function () { this.$emit('btnclick'); } } }); Vue.component('a-button', { props: ['title', 'classname'], data: function () { return { class_name: this.classname || 'button' } }, template: '' + '{{title}}' + '', methods: { childclick: function () { this.$emit('btnclick'); } } }); Vue.component('datagrid', { props: ['data', 'fields'], data: function () { return { options: [] } }, template: '' + '' + '' + '' + '' + '' + '' + '' + '' + '
{{f.field}}
{{d.A}}{{d.B}}{{d.C}}
', mounted: function () { this.options = []; for (var i = 0; i < this.fields.length; i++) { this.options.push({ field: this.fields[i], option: "field:'" + this.fields[i] + "',width:100,align:'center'" }); } }, watch: { data: function (val) { $("#dg").datagrid('loadData', val); } } }); //datagrid 封装 to do... Vue.component('easyui-datagrid', { props: ['id', 'options', 'jsondata'], data: function () { return { propJsonData: [], jsonData: [], fields: [], dataOptions: [] } }, template: '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
{{f.name}}
{{f}}
', mounted: function () { var $this = this; //将field 跟数据列对应 for (var f in $this.options.fields) { var isField = 0; var dataOpt = []; var dataOptObj = {}; for (_f in $this.options.fields[f]) { var _v = $this.options.fields[f][_f]; if (isField > 0) { switch (_f) { case "width": dataOpt.push("width:" + _v); break; case "formatter": dataOpt.push("formatter:" + _v); break; } } else { dataOpt.push("field:'" + _f + "'"); dataOpt.push("align:'center'"); var field = {}; eval("field." + _f + "='" + _v + "'"); $this.fields.push(field); dataOptObj.name = _v; } isField++; } dataOptObj.opt = dataOpt.join(','); $this.dataOptions.push(dataOptObj); } }, watch: { jsondata: function (val) { console.log('val:'); console.log(val); var $this = this; $this.jsonData = []; $this.propJsonData = val; //将field 跟数据列对应 for (var d in $this.propJsonData) { var row = {}; for (var f in $this.fields) { for (var _f in $this.fields[f]) { for (var _d in $this.propJsonData[d]) { if (_f == _d) { eval("row." + _f + "='" + $this.propJsonData[d][_d] + "'"); } } } } $this.jsonData.push(row); } console.log($this.jsonData); } } }); //下拉框(饿了么) Vue.component('hh-select', { props: ['options', 'defaultdata', 'multiple', 'title', 'width'], data: function () { return { defaultValue: { value: '', label: '全部' }, modelTitle: this.title ? this.title + ":" : '', modelValue: this.defaultdata || '', elOptions: this.options || [], isMultiple: this.multiple == "true" ? true : false, selectWidth: this.width || 130 } }, template: '{{modelTitle}}' + '' + '' + '', methods: { inputChange: function ($event) { this.modelValue = $event; this.$emit('input', $event); }, }, computed: { optionsData: function () { var $this = this; var tempOptions = this.elOptions; if (!$this.multiple) tempOptions.unshift(this.defaultValue); return tempOptions; } }, watch: { options: function (val) { this.elOptions = val; } } }); Vue.component('hh-select-url', { props: ['url', 'defaultdata', 'multiple', 'title', 'valuefield', 'textfield', 'datafield', 'ajaxtype', 'postdata', 'iseval', 'width', 'disabled'], data: function () { return { defaultValue: { value: '', label: '全部' }, modelTitle: this.title ? this.title + ":" : '', modelValue: this.defaultdata || '', isMultiple: this.multiple == "true" ? true : false, ajaxType: this.ajaxtype || "GET", selectWidth: this.width || 130, isDisabled: this.disabled || false } }, template: '{{modelTitle}}' + '' + '' + '', methods: { inputChange: function ($event) { this.modelValue = $event; this.$emit('input', $event); }, }, computed: { optionsData: function () { var $this = this; var _url = $this.url; var tempOptions = []; $.ajax({ type: $this.ajaxType, url: _url, data: $this.postdata, dataType: "json", async: false, success: function (data) { if (data) { if ($this.iseval) { data = eval("(" + data + ")"); } var rows = data; if ($this.datafield) { rows = eval("rows." + $this.datafield); } if (!$this.multiple) tempOptions.push($this.defaultValue); rows.forEach(function (n) { tempOptions.push({ value: eval("n." + $this.valuefield), label: eval("n." + $this.textfield) }); }); } } }); return tempOptions; } }, watch: { disabled: function (val) { this.isDisabled = val; }, defaultdata: function (val) { this.modelValue = val; } } }); Vue.component('hh-input', { props: ['defaultdata', 'title', 'width'], data: function () { return { defaultValue: { value: '', label: '全部' }, modelTitle: this.title ? this.title + ":" : '', modelValue: this.defaultdata || '', inputWidth: this.width || 130 } }, methods: { inputChange: function ($event) { this.modelValue = $event; this.$emit('input', $event); }, }, template: '{{modelTitle}} ' + '' }); Vue.component('location-state', { template: '
' });