diff --git a/projects/IoTCenter/Views/Home/Index.cshtml b/projects/IoTCenter/Views/Home/Index.cshtml index 05bf3e5f..230e0296 100644 --- a/projects/IoTCenter/Views/Home/Index.cshtml +++ b/projects/IoTCenter/Views/Home/Index.cshtml @@ -18,7 +18,7 @@ -
+

{{item.Name}}

@@ -39,9 +39,6 @@ } @section scripts{ + - } \ No newline at end of file diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/config.html b/projects/IoTClient/Assets/StreamingAssets/wwwroot/config.html index 609b00d0..c9b45192 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/config.html +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/config.html @@ -56,15 +56,17 @@ + - \ No newline at end of file diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html b/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html index be3898d2..54c8aedb 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html @@ -32,7 +32,7 @@ -
  • +
  • {{n.Name}} @@ -62,96 +62,17 @@
    + + - - + + + + \ No newline at end of file diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/index.js b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/index.js index 8e36643f..ae0dc9b6 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/index.js +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/index.js @@ -1,164 +1,56 @@ -/*var*/ -var isApp = location.href.indexOf('http') !== 0; -var server = isApp ? localStorage.getItem('server') : null; -var iotCenter = isApp ? server + '/IoTCenter' : ''; -var dataUrl = iotCenter + '/App/GetProducts'; -var token = isApp ? localStorage.getItem('token') : null; -var wsUrl = iotCenter + '/hub?group=page'; -var connectionId; -const connection = new signalR.HubConnectionBuilder() - .withUrl(wsUrl) - .build(); -var app; -var vm; -// -if (isApp) { - Framework7.use(Framework7Vue); +isDebug = true; +useSingalR = false; dataUrl = iotCenter + '/App/GetProducts'; +data = function data() { + return { + f7params: f7params, + server: localStorage.getItem('server'), + token: localStorage.getItem('token'), + model: { + Products: [], + Scenes: [] + } + }; } -toastr.options.timeOut = 500; -toastr.options.positionClass = "toast-top-center"; -/*fun*/ -function alert(message, title) { +function mounted() { if (isApp) { - title = title || '消息'; - app.dialog.alert(message, title); - } - else { - alert(message); - } -} -function hideLoading(message) { - toastr.success(message || '请求成功'); - $('.overlay').hide(); -} -function ajax(url, data, type) { - url = iotCenter + url - console.log(url); - type = type || 'get'; - $('.overlay').show(); - $.ajax({ - type: type, - url: url, - data: data, - success: AjaxCallBack - }).fail(function (result) { - toastr.error('请求发送失败!'); - console.log(result); - }).always(function () { - $('.overlay').hide(); - }); -} -function AjaxCallBack(response) { - var result = response; - if (result.code === 0) { - if (result.type === 0) { - if (result.format === 1) { - console.log('format/1/base64 jpeg image'); - $('#callback .page-content').html(''); - } - else { - console.log('format/0/json object'); - $('#callback .page-content').html(result.data); - } - app.popup.open('#callback'); + if (!this.server) { + location.href = "config.html"; + } + if (!this.token) { + location.href = "login.html"; } } -} -/*ws*/ -function connect() { - if (debug) { - console.log('start connect to server:' + Date()); - } - if (connection.state === signalR.HubConnectionState.Disconnected) { - connection.start().then(function () { - toastr.success('客户端与服务器连接成功!'); - }).catch(function (err) { - toastr.error('客户端与服务器连接失败!'); - setTimeout(connect, 15 * 1000); - }); - } -} -connection.on('Connected', function (id) { - connectionId = id; -}); -connection.onclose(function (err) { - setTimeout(connect, 15 * 1000); -}); -connection.on("ServerToClient", function (method, json, to, from) { - console.log(method + ':' + json); - onMessage(method, json, to, from); -}); +}; +methods = { + GetProducts() { + return Enumerable.from(this.model.Products).orderBy('o=>o.DisplayOrder').toArray(); + }, + GetScenes() { + return Enumerable.from(this.model.Scenes).orderBy('o=>o.DisplayOrder').toArray(); + }, + CallScene(id) { + ajax('/App/ExecGlobalScene', { token: token, connectionId: connectionId, id: id }, 'post'); + } +}; function onMessage(method, json, to, from) { + debug(method + ':' + json); var item = JSON.parse(json); - if (method === 'ExecApiRsponse') { - console.log(json); - toastr.success('操作调用成功'); - } - else if (method === 'ExecSceneRsponse') { - console.log(json); - toastr.success('场景调用成功'); - } - else if (method == 'ProductEntityInserted' || + console.log(method + ':' + json); + var item = JSON.parse(json); + if (method == 'ProductEntityInserted' || method == 'ProductEntityUpdated' || method == 'ProductEntityDeleted' || method == 'DeviceEntityInserted' || method == 'DeviceEntityDeleted' || - method == 'SceneEntityInserted' || + method == 'DeviceEntityDeleted') { + loadData(); + } + else if (method == 'SceneEntityInserted' || method == 'SceneEntityUpdated' || method == 'SceneEntityDeleted') { - vm.load(); - } -} -/*vue*/ -function loadData() { - vm = new Vue({ - el: '#app', - data() { - return { - f7params: { - routes: [], - name: 'My App', - id: 'com.myapp.test', - theme: 'ios', - }, - model: null - }; - }, - mounted() { - if (isApp) { - if (!server) { - location.href = "config.html"; - } - if (!token) { - location.href = "login.html"; - } - this.$f7ready((f7) => { - app = this.$f7; - }); - } - this.load(); - }, - methods: { - load() { - connect(); - axios.post(dataUrl) - .then(function (response) { - vm.model = response.data; - }) - .catch(function (error) { - toastr.error('数据加载失败!'); - }) - .then(hideLoading); - }, - CallApi(number, method, query) { - ajax('/App/ExecApi', { token: token, connectionId: connectionId, number: number, method: method, query: query }, 'post'); - }, - GetScenes() { - return Enumerable.from(this.model.Scenes).orderBy('o=>o.DisplayOrder').toArray(); - }, - CallScene(id) { - ajax('/App/ExecGlobalScene', { token: token, connectionId: connectionId, id: id }, 'post'); - } + if (item.NodeId == null) { + loadData(); } - }); + } } +start(); \ No newline at end of file diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/page.js b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/page.js index 82d5f03d..89de8ad2 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/page.js +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/page.js @@ -25,6 +25,12 @@ if (isApp) { } toastr.options.timeOut = 500; toastr.options.positionClass = "toast-top-center"; +var f7params = isApp? { + routes: [], + name: 'My App', + id: 'com.myapp.test', + theme: 'ios', +}:null; // //log function debug(message) { @@ -62,7 +68,9 @@ function loadTemplate() { axios.post(templateUrl, { crossDomain: true }) .then(function (response) { var html = response.data; - $('#template').html(html); + if (html) { + $('#template').html(html); + } init(); }) .catch(function (error) { @@ -80,7 +88,7 @@ function loadData() { axios.post(dataUrl, formData) .then(function (response) { debug(response); - data.model = response.data; + vm.model = response.data; toastr.success('数据加载成功!'); }) .catch(function (error) { @@ -103,19 +111,13 @@ function start() { } } //初始化vue -var mounted = mounted || function () { }; +var data = function () { }; +var mounted = function () { }; +var methods ={ }; function init() { $('#template style').each(function (i, n) { $('head').append(n); }); - if (isApp) { - data['f7params'] = { - root: '#app', - id: 'io.framework7.testapp', - name: 'Framework7', - theme: 'ios', - }; - } vm = new Vue({ el: '#app', data: data, @@ -131,8 +133,6 @@ function init() { loadData(); } }, - methods:methods + methods: methods }); -} -// -start(); \ No newline at end of file +} \ No newline at end of file diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/login.html b/projects/IoTClient/Assets/StreamingAssets/wwwroot/login.html index b5e6b115..715da5f0 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/login.html +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/login.html @@ -68,10 +68,12 @@ + - \ No newline at end of file