From e12ba0d011a3089c952756f566108a53c8a48fba Mon Sep 17 00:00:00 2001 From: HueiFeng <695979933@qq.com> Date: Wed, 21 Apr 2021 14:46:34 +0800 Subject: [PATCH] fix: Buttons do not need to be displayed when WeChat share is off. --- Core/StlShare.cs | 8 +- Pages/ss-admin/share/Index.cshtml | 167 ++++++++-------- wwwroot/assets/share/index.js | 305 +++++++++++++++--------------- 3 files changed, 245 insertions(+), 235 deletions(-) diff --git a/Core/StlShare.cs b/Core/StlShare.cs index 241a73e..c5ad42c 100644 --- a/Core/StlShare.cs +++ b/Core/StlShare.cs @@ -46,7 +46,7 @@ public async Task ParseAsync(IParseStlContext context) var origin = string.Empty; var description = string.Empty; var image = string.Empty; - var sites = "wechat, weibo, qq, qzone, douban"; + var sites = "weibo, qq, qzone, douban"; var disabled = string.Empty; var wechatQrcodeTitle = string.Empty; var wechatQrcodeHelper = string.Empty; @@ -104,6 +104,12 @@ public async Task ParseAsync(IParseStlContext context) var settings = await _shareManager.GetSettingsAsync(context.SiteId); var site = await _siteRepository.GetAsync(context.SiteId); + + if (settings.IsWxShare) + { + sites += ",wechat"; + } + var cssUrl = _pathManager.GetApiHostUrl(site, "/assets/share/css/share.min.css"); var jsUrl = _pathManager.GetApiHostUrl(site, "/assets/share/js/social-share.min.js"); diff --git a/Pages/ss-admin/share/Index.cshtml b/Pages/ss-admin/share/Index.cshtml index 6bc1d9b..ea04f60 100644 --- a/Pages/ss-admin/share/Index.cshtml +++ b/Pages/ss-admin/share/Index.cshtml @@ -1,101 +1,104 @@ @page -@{ Layout = "_Layout"; } +@{ + Layout = "_Layout"; +} - + - - 页面分享标签:<stl:share></stl:share> - + + 页面分享标签:<stl:share></stl:share> + -
+
- - - -
当分享插件未获取到页面标题时将使用默认页面标题
-
- - - - 上传 - - - 选择 - - - 预览 - - - - -
当分享插件未获取到封面图片时将使用默认封面图片
-
- - -
当分享插件未获取到页面介绍时将使用默认页面介绍
-
-
+ + + +
当分享插件未获取到页面标题时将使用默认页面标题
+
+ + + + 上传 + + + 选择 + + + 预览 + + + + +
当分享插件未获取到封面图片时将使用默认封面图片
+
+ + +
当分享插件未获取到页面介绍时将使用默认页面介绍
+
+
- -
+ +
- - - 保 存 - - -
- + + + 保 存 + + + + - - + + -
+
- - - 启用 - 不启用 -
启用微信分享后,微信转发或分享时将显示完整的标题、封面及介绍
-
- - -
请进入微信公众平台,获取AppId
-
- - -
请进入微信公众平台,获取AppSecret
-
-
+ + + + 启用 + 不启用 + +
启用微信分享后,微信转发或分享时将显示完整的标题、封面及介绍
+
+ + +
请进入微信公众平台,获取AppId
+
+ + +
请进入微信公众平台,获取AppSecret
+
+
- - -
+ +
- - - 保 存 - - -
+ + + 保 存 + + +
@section Scripts{ - + } \ No newline at end of file diff --git a/wwwroot/assets/share/index.js b/wwwroot/assets/share/index.js index 018fe45..ad0f711 100644 --- a/wwwroot/assets/share/index.js +++ b/wwwroot/assets/share/index.js @@ -3,163 +3,164 @@ var $urlWxShare = '/share/wxShare'; var $urlSettings = '/share/settings'; var data = utils.init({ - siteId: utils.getQueryInt('siteId'), - siteUrl: null, - ipAddress: null, - settingsForm: null, - wxShareForm: null, - mpResult: null + siteId: utils.getQueryInt('siteId'), + siteUrl: null, + ipAddress: null, + settingsForm: null, + wxShareForm: null, + mpResult: null }); var methods = { - runFormLayerImageUploadText: function(attributeName, no, text) { - this.insertText(attributeName, no, text); - }, - - runMaterialLayerImageSelect: function(attributeName, no, text) { - this.insertText(attributeName, no, text); - }, - - insertText: function(attributeName, no, text) { - this.settingsForm[attributeName] = text; - this.settingsForm = _.assign({}, this.settingsForm); - }, - - apiGet: function () { - var $this = this; - - utils.loading(this, true); - $api.get($url, { - params: { - siteId: this.siteId - } - }).then(function (response) { - var res = response.data; - - $this.siteUrl = res.siteUrl; - $this.ipAddress = res.ipAddress; - $this.settingsForm = Object.assign({}, res.settings); - $this.wxShareForm = Object.assign({}, res.settings); - }).catch(function (error) { - utils.error(error); - }).then(function () { - utils.loading($this, false); - }); - }, - - apiWxShareSubmit: function () { - this.mpResult = null; - var $this = this; - - utils.loading(this, true); - $api.post($urlWxShare, { - siteId: this.siteId, - mpAppId: this.wxShareForm.mpAppId, - mpAppSecret: this.wxShareForm.mpAppSecret - }).then(function (response) { - var res = response.data; - - $this.mpResult = { - success: res.success, - errorMessage: res.errorMessage - }; - }).catch(function (error) { - utils.error(error); - }).then(function () { - utils.loading($this, false); - }); - }, - - apiSettingsSubmit: function () { - var $this = this; - - utils.loading(this, true); - $api.post($urlSettings, { - siteId: this.siteId, - defaultTitle: this.settingsForm.defaultTitle, - defaultImageUrl: this.settingsForm.defaultImageUrl, - defaultDescription: this.settingsForm.defaultDescription - }).then(function (response) { - var res = response.data; - - utils.success('页面分享设置保存成功!'); - }).catch(function (error) { - utils.error(error); - }).then(function () { - utils.loading($this, false); - }); - }, - - btnSettingsSubmitClick: function () { - var $this = this; - - this.$refs.settingsForm.validate(function(valid) { - if (valid) { - $this.apiSettingsSubmit(); - } - }); - }, - - btnWxShareSubmitClick: function () { - var $this = this; - - this.$refs.wxShareForm.validate(function(valid) { - if (valid) { - $this.apiWxShareSubmit(); - } - }); - }, - - btnLayerClick: function(options) { - var query = { - siteId: this.siteId, - channelId: this.channelId - }; - - if (options.contentId) { - query.contentId = options.contentId; + runFormLayerImageUploadText: function (attributeName, no, text) { + this.insertText(attributeName, no, text); + }, + + runMaterialLayerImageSelect: function (attributeName, no, text) { + this.insertText(attributeName, no, text); + }, + + insertText: function (attributeName, no, text) { + this.settingsForm[attributeName] = text; + this.settingsForm = _.assign({}, this.settingsForm); + }, + + apiGet: function () { + var $this = this; + + utils.loading(this, true); + $api.get($url, { + params: { + siteId: this.siteId + } + }).then(function (response) { + var res = response.data; + + $this.siteUrl = res.siteUrl; + $this.ipAddress = res.ipAddress; + $this.settingsForm = Object.assign({}, res.settings); + $this.wxShareForm = Object.assign({}, res.settings); + }).catch(function (error) { + utils.error(error); + }).then(function () { + utils.loading($this, false); + }); + }, + + apiWxShareSubmit: function () { + this.mpResult = null; + var $this = this; + + utils.loading(this, true); + $api.post($urlWxShare, { + siteId: this.siteId, + mpAppId: this.wxShareForm.mpAppId, + mpAppSecret: this.wxShareForm.mpAppSecret, + isWxShare: this.wxShareForm.isWxShare + }).then(function (response) { + var res = response.data; + + $this.mpResult = { + success: res.success, + errorMessage: res.errorMessage + }; + }).catch(function (error) { + utils.error(error); + }).then(function () { + utils.loading($this, false); + }); + }, + + apiSettingsSubmit: function () { + var $this = this; + + utils.loading(this, true); + $api.post($urlSettings, { + siteId: this.siteId, + defaultTitle: this.settingsForm.defaultTitle, + defaultImageUrl: this.settingsForm.defaultImageUrl, + defaultDescription: this.settingsForm.defaultDescription + }).then(function (response) { + var res = response.data; + + utils.success('页面分享设置保存成功!'); + }).catch(function (error) { + utils.error(error); + }).then(function () { + utils.loading($this, false); + }); + }, + + btnSettingsSubmitClick: function () { + var $this = this; + + this.$refs.settingsForm.validate(function (valid) { + if (valid) { + $this.apiSettingsSubmit(); + } + }); + }, + + btnWxShareSubmitClick: function () { + var $this = this; + + this.$refs.wxShareForm.validate(function (valid) { + if (valid) { + $this.apiWxShareSubmit(); + } + }); + }, + + btnLayerClick: function (options) { + var query = { + siteId: this.siteId, + channelId: this.channelId + }; + + if (options.contentId) { + query.contentId = options.contentId; + } + if (options.attributeName) { + query.attributeName = options.attributeName; + } + if (options.no) { + query.no = options.no; + } + + var args = { + title: options.title, + url: utils.getCommonUrl(options.name, query) + }; + if (!options.full) { + args.width = options.width ? options.width : 700; + args.height = options.height ? options.height : 500; + } + + utils.openLayer(args); + }, + + btnPreviewClick: function (attributeName, no) { + var data = []; + var imageUrl = this.settingsForm.defaultImageUrl; + imageUrl = utils.getUrl(this.siteUrl, imageUrl); + data.push({ + "src": imageUrl + }); + layer.photos({ + photos: { + "start": no, + "data": data + } + , anim: 5 + }); } - if (options.attributeName) { - query.attributeName = options.attributeName; - } - if (options.no) { - query.no = options.no; - } - - var args = { - title: options.title, - url: utils.getCommonUrl(options.name, query) - }; - if (!options.full) { - args.width = options.width ? options.width : 700; - args.height = options.height ? options.height : 500; - } - - utils.openLayer(args); - }, - - btnPreviewClick: function(attributeName, no) { - var data = []; - var imageUrl = this.settingsForm.defaultImageUrl; - imageUrl = utils.getUrl(this.siteUrl, imageUrl); - data.push({ - "src": imageUrl - }); - layer.photos({ - photos: { - "start": no, - "data": data - } - ,anim: 5 - }); - } }; var $vue = new Vue({ - el: '#main', - data: data, - methods: methods, - created: function () { - this.apiGet(); - } + el: '#main', + data: data, + methods: methods, + created: function () { + this.apiGet(); + } }); \ No newline at end of file