From d6dd93e4064d176a66d3e8df2038432af3446b83 Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 2 Jan 2020 19:10:33 +0800 Subject: [PATCH] add share --- lib/page.js | 4 ++++ lib/user.js | 5 +++-- pane/Storm.js | 23 +++++++++++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/page.js b/lib/page.js index 8408f9b1..9713d6e0 100644 --- a/lib/page.js +++ b/lib/page.js @@ -119,6 +119,10 @@ Volcanos("page", {help: "网页模块", data.title = data.title || data.placeholder; data.autocomplete = data.autocomplete || "current-password" + } else if (item.img) {var list = can.core.List(item.img); + type = "img"; + data.src = list[0]; + } else if (item.row) {type = "tr"; item.list = item.row.map(function(text) {return {text: [text, item.sub||"td"]}}); } diff --git a/lib/user.js b/lib/user.js index 0b3f72ac..4d1cabf2 100644 --- a/lib/user.js +++ b/lib/user.js @@ -8,9 +8,10 @@ Volcanos("user", {help: "用户模块", toast: function(text) {}, carte: function(event, cb) {}, - Share: shy("共享链接", function(can, objs, clear) {var obj = objs || {}; + Share: shy("共享链接", function(can, objs, clear) {var obj = objs || {}; var path = location.pathname; + obj.path && (path = obj.path, delete(obj.path)) !clear && can.core.Item(can.user.Search(), function(key, value) {obj[key] || (obj[key] = value)}); - return location.origin+location.pathname+(objs? "?"+can.core.Item(obj, function(key, value) { + return location.origin+path+(objs? "?"+can.core.Item(obj, function(key, value) { return can.core.List(value, function(value) {return key+"="+encodeURIComponent(value)}).join("&"); }).join("&"): ""); }), diff --git a/pane/Storm.js b/pane/Storm.js index 97059523..78da321b 100644 --- a/pane/Storm.js +++ b/pane/Storm.js @@ -4,6 +4,9 @@ Volcanos("onimport", {help: "导入数据", list: [], can.Export(event, line.key, "storm") }) }, + layout: function(event, can, value, cmd, output) { + can.Conf("layout", value) + }, river: function(event, can, value, cmd, output) { if (value == "update") {return} can.run(event, [can.Conf("river", value)], function(msg) { @@ -15,6 +18,8 @@ Volcanos("onimport", {help: "导入数据", list: [], can.run(event, [can.Conf("river")], function(msg) { can.onimport.init(event, can, msg, cmd, output) }) + } else { + can.Conf("storm", value) } }, favor: function(event, can, msg, cmd, output) {var key = msg.detail[0]; @@ -29,7 +34,7 @@ Volcanos("onimport", {help: "导入数据", list: [], }) }, }) -Volcanos("onaction", {help: "组件交互", list: ["创建", "刷新"], +Volcanos("onaction", {help: "组件交互", list: ["创建", "刷新", "共享"], "创建": function(event, can, meta, cmd, output) { can.Export(event, "create", "steam") }, @@ -38,6 +43,9 @@ Volcanos("onaction", {help: "组件交互", list: ["创建", "刷新"], can.onimport.init(event, can, msg, cmd, output) }) }, + "共享": function(event, can, meta, cmd, output) { + can.ondetail[cmd](event, can, meta, "", cmd, output) + }, }) Volcanos("onchoice", {help: "组件菜单", list: ["创建", "刷新"], "创建": function(event, can, msg, cmd, output) { @@ -49,7 +57,18 @@ Volcanos("onchoice", {help: "组件菜单", list: ["创建", "刷新"], }) }, }) -Volcanos("ondetail", {help: "组件详情", list: ["保存", "恢复", "重命名", "删除"], +Volcanos("ondetail", {help: "组件详情", list: ["共享", "保存", "恢复", "重命名", "删除"], + "共享": function(event, can, line, value, cmd, item) {can.share || (can.share = {}); + var p = can.user.Share(can, {layout: can.Conf("layout"), river: can.Conf("river"), storm: can.Conf("storm")}, true) + if (can.share[p]) { + can.user.toast({duration: 10000, height: 300, text: p, list: [{img: [can.user.Share(can, {path: "/share/"+can.share[p]}, true)]}]}); + } else { + can.run(event, [can.Conf("river"), can.Conf("storm"), "share", "qrcode", can.Conf("storm"), p], function(msg) { + can.share[p] = msg.Result(); + can.user.toast({duration: 10000, height: 300, text: p, list: [{img: [can.user.Share(can, {path: "/share/"+msg.Result()}, true)]}]}); + }) + } + }, "重命名": function(event, can, line, value, cmd, item) { can.user.prompt("输入新名:", function(name) { can.run(event, [can.Conf("river"), value, "rename", name], function(msg) {