Vue.prototype.debug = config.debug; Vue.prototype.isMobile = config.isMobile; Vue.prototype.baseUrl = config.baseUrl; Vue.prototype.uploadUrl = config.uploadUrl; Vue.use(window.vuelidate.default); Vue.directive('valid', { bind: function (el, binding) { if (binding.value) { $(el).attr('data-val',true); if (binding.value.required) { $(el).attr('data-val-required', binding.value.required); } else if (binding.value.pattern) { $(el).attr('data-val-regex-pattern', binding.value.pattern.regex); $(el).attr('data-val-regex-message', binding.value.pattern.message); } } }, update: function (el, binding) { if (binding.value !== binding.oldValue) { console.log('value changed:' + el.value); } } }); function vueComponent(name, url) { Vue.component(name, function (resolve, reject) { axios.get(url).then(function (response) { resolve(parseModel(response)); }); }); } function parseModel(response) { var html = new DOMParser().parseFromString(response.data, 'text/html'); var template = html.getElementsByTagName('template')[0].innerHTML; var script = html.getElementsByTagName('script')[0].innerHTML; script = '(' + script.replace(/^\s*export\s*default\s*/, '').replace(/;?\s*$/, '') + ')\n//# sourceURL=' + response.config.url; var model = eval(script); model.template = template; return model; } //update function updateById(list, item) { return update(list, item, 'id'); } function updateByNumber(list, item) { return update(list, item, 'number'); } function updateByKey(list, item) { return update(list, item, 'key'); } function update(list, item, key) { key = key || 'number'; var result = false; var to = Enumerable.from(list).where(function (o) { return o[key] === item[key]; }).firstOrDefault(); if (to) { copy(item, to); } else { list.push(item); result = true; } //console.log(result ? 'insert' : 'update' + ' data by ' + key); return result; } //delete function removeById(list, item) { return remove(list, item, 'id'); } function removeByKey(list, item) { return remove(list, item, 'key'); } function remove(list, item, key) { var result = false; for (var i = 0; i < list.length; i++) { if (list[i][key] === item[key]) { list.splice(i, 1); result = true; break; } } return result; } //util function copy(from, to) { for (var attr in to) { if (from.hasOwnProperty(attr)) { if (!(from[attr] instanceof Array)) { to[attr] = from[attr]; } } } } function subscribe(events, action) { if (!events || !action) { return; } for (var i = 0; i < events.length; i++) { PubSub.subscribe(events[i], function (m, d) { action(m, d); }); } } function unsubscribe(events) { if (!events) { return; } for (var i = 0; i < events.length; i++) { PubSub.unsubscribe(events[i]); } } // function nodePower(number, command) { loading.show(); axios.post('/IoTCenter/api/v1/node/power' + command, '"' + number + '"', { headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }) .finally(function () { loading.hide(); }); } function nodeMethod(number, method) { loading.show(); axios.post('/IoTCenter/api/v1/node/' + method, '"' + number + '"', { headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }) .finally(function () { loading.hide(); }); } // function selectNode(e) { var checkbox = $(e.target); if (checkbox.hasClass('checkall')) { if (e.target.checked) { $('input.item:visible').not(':checked').prop("checked", true); } else { $('input.item:visible').filter(':checked').prop("checked", false); } } else if (checkbox.hasClass('uncheck')) { $('input.item:visible').each(function () { $(this).prop("checked", !$(this).prop("checked")).change(); }); } var parent = $('input.checkall'); if ($('input.item').not(':checked').length === 0) { parent.prop("indeterminate", false); parent.prop("checked", true); } else if ($('input.item').filter(':checked').length === 0) { parent.prop("indeterminate", false); parent.prop("checked", false); } else { parent.prop("indeterminate", true); } } //batch select $(function () { $(document).on('change', 'th :checkbox',function () { if ($(this).is(':checked')) { $(this).parents('table').find(':checkbox').not(':checked').prop("checked", true); } else { $(this).parents('table').find(':checkbox').filter(':checked').prop("checked", false); } }); $(document).on('change','td :checkbox',function () { var parent = $(this).parents('table').find('th :checkbox'); var children = $(this).parents('table').find('td :checkbox'); if ($(this).is(':checked')) { if (parent.not(':checked')) { if (children.not(':checked').length === 0) { parent.prop("indeterminate", false); parent.prop("checked", true); } else { parent.prop("indeterminate", true); } } } else { if (parent.is(':checked')) { if (children.filter(':checked').length === 0) { parent.prop("indeterminate", false); parent.prop("checked", false); } else { parent.prop("indeterminate", true); } } } }); });