Skip to content

Commit

Permalink
Merge pull request #110 from wu-jj/wxshare
Browse files Browse the repository at this point in the history
[feat] WeChat sharing function completed
  • Loading branch information
IRONICBo authored Feb 6, 2024
2 parents 5bf7a78 + 6e228e2 commit 1dc09bb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 61 deletions.
76 changes: 37 additions & 39 deletions cmd/gopcomm/gop_autogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (this *community) MainEntry() {
//line cmd/gopcomm/community_yap.gox:152:1
uid := ctx.Param("uid")
//line cmd/gopcomm/community_yap.gox:153:1
files, err := this.community.ListMediaByUserId(todo, uid, format)
token, err := core.GetToken(ctx)
//line cmd/gopcomm/community_yap.gox:154:1
if err != nil {
//line cmd/gopcomm/community_yap.gox:155:1
Expand Down Expand Up @@ -277,9 +277,8 @@ func (this *community) MainEntry() {
//line cmd/gopcomm/community_yap.gox:241:1
// todo middleware
var user *core.User
//line cmd/gopcomm/community_yap.gox:242:1
//line cmd/gopcomm/community_yap.gox:201:1
token, err := core.GetToken(ctx)
//line cmd/gopcomm/community_yap.gox:243:1
if err == nil {
//line cmd/gopcomm/community_yap.gox:244:1
user, err = this.community.GetUser(token.Value)
Expand All @@ -299,9 +298,8 @@ func (this *community) MainEntry() {
})
//line cmd/gopcomm/community_yap.gox:260:1
this.Get("/edit/:id", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:261:1
//line cmd/gopcomm/community_yap.gox:220:1
token, err := core.GetToken(ctx)
//line cmd/gopcomm/community_yap.gox:262:1
if err != nil {
//line cmd/gopcomm/community_yap.gox:263:1
ctx.Json__1(map[string]interface {
Expand Down Expand Up @@ -360,9 +358,9 @@ func (this *community) MainEntry() {
mdData := ctx.Param("content")
//line cmd/gopcomm/community_yap.gox:309:1
htmlData := ctx.Param("html")
//line cmd/gopcomm/community_yap.gox:311:1
//line cmd/gopcomm/community_yap.gox:270:1
token, err := core.GetToken(ctx)
//line cmd/gopcomm/community_yap.gox:312:1
//line cmd/gopcomm/community_yap.gox:271:1
if err != nil {
//line cmd/gopcomm/community_yap.gox:313:1
ctx.Json__1(map[string]interface {
Expand All @@ -386,9 +384,9 @@ func (this *community) MainEntry() {
})
//line cmd/gopcomm/community_yap.gox:348:1
this.Post("/translate", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:350:1
//line cmd/gopcomm/community_yap.gox:309:1
token, err := core.GetToken(ctx)
//line cmd/gopcomm/community_yap.gox:351:1
//line cmd/gopcomm/community_yap.gox:310:1
if err != nil {
//line cmd/gopcomm/community_yap.gox:352:1
ctx.Json__1(map[string]interface {
Expand Down Expand Up @@ -449,75 +447,75 @@ func (this *community) MainEntry() {
ctx.Json__1(map[string]interface {
}{"code": 200, "url": htmlUrl})
})
//line cmd/gopcomm/community_yap.gox:408:1
//line cmd/gopcomm/community_yap.gox:367:1
this.Post("/upload", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:409:1
//line cmd/gopcomm/community_yap.gox:368:1
core.UploadFile(ctx, this.community)
})
//line cmd/gopcomm/community_yap.gox:412:1
//line cmd/gopcomm/community_yap.gox:371:1
this.Get("/login", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:417:1
//line cmd/gopcomm/community_yap.gox:376:1
redirectURL := fmt.Sprintf("%s/%s", ctx.Request.Referer(), "callback")
//line cmd/gopcomm/community_yap.gox:419:1
//line cmd/gopcomm/community_yap.gox:378:1
loginURL := this.community.RedirectToCasdoor(redirectURL)
//line cmd/gopcomm/community_yap.gox:420:1
//line cmd/gopcomm/community_yap.gox:379:1
ctx.Redirect(loginURL, http.StatusFound)
})
//line cmd/gopcomm/community_yap.gox:424:1
//line cmd/gopcomm/community_yap.gox:383:1
this.Get("/logout", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:425:1
//line cmd/gopcomm/community_yap.gox:384:1
err := core.RemoveToken(ctx)
//line cmd/gopcomm/community_yap.gox:426:1
//line cmd/gopcomm/community_yap.gox:385:1
if err != nil {
//line cmd/gopcomm/community_yap.gox:427:1
//line cmd/gopcomm/community_yap.gox:386:1
xLog.Error("remove token error:", err)
}
//line cmd/gopcomm/community_yap.gox:431:1
//line cmd/gopcomm/community_yap.gox:390:1
http.Redirect(ctx.ResponseWriter, ctx.Request, fmt.Sprintf("/"), http.StatusFound)
})
//line cmd/gopcomm/community_yap.gox:434:1
//line cmd/gopcomm/community_yap.gox:393:1
this.Get("/callback", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:435:1
//line cmd/gopcomm/community_yap.gox:394:1
err := core.SetToken(ctx)
//line cmd/gopcomm/community_yap.gox:436:1
//line cmd/gopcomm/community_yap.gox:395:1
if err != nil {
//line cmd/gopcomm/community_yap.gox:437:1
//line cmd/gopcomm/community_yap.gox:396:1
xLog.Error("set token error:", err)
}
//line cmd/gopcomm/community_yap.gox:442:1
//line cmd/gopcomm/community_yap.gox:401:1
http.Redirect(ctx.ResponseWriter, ctx.Request, fmt.Sprintf("/"), http.StatusFound)
})
//line cmd/gopcomm/community_yap.gox:445:1
//line cmd/gopcomm/community_yap.gox:404:1
conf := &core.Config{}
//line cmd/gopcomm/community_yap.gox:446:1
//line cmd/gopcomm/community_yap.gox:405:1
this.community, _ = core.New(todo, conf)
//line cmd/gopcomm/community_yap.gox:447:1
//line cmd/gopcomm/community_yap.gox:406:1
this.trans = translation.New(os.Getenv("NIUTRANS_API_KEY"), "", "")
//line cmd/gopcomm/community_yap.gox:448:1
//line cmd/gopcomm/community_yap.gox:407:1
core.CasdoorConfigInit()
//line cmd/gopcomm/community_yap.gox:451:1
//line cmd/gopcomm/community_yap.gox:410:1
this.Handle("/", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:452:1
//line cmd/gopcomm/community_yap.gox:411:1
ctx.Yap__1("4xx", map[string]interface {
}{})
})
//line cmd/gopcomm/community_yap.gox:455:1
//line cmd/gopcomm/community_yap.gox:414:1
xLog.Info("Started in endpoint: ", endpoint)
//line cmd/gopcomm/community_yap.gox:458:1
//line cmd/gopcomm/community_yap.gox:417:1
this.Run(endpoint, func(h http.Handler) http.Handler {
//line cmd/gopcomm/community_yap.gox:460:1
//line cmd/gopcomm/community_yap.gox:419:1
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
//line cmd/gopcomm/community_yap.gox:461:1
//line cmd/gopcomm/community_yap.gox:420:1
defer func() {
//line cmd/gopcomm/community_yap.gox:462:1
//line cmd/gopcomm/community_yap.gox:421:1
if
//line cmd/gopcomm/community_yap.gox:462:1
//line cmd/gopcomm/community_yap.gox:421:1
err := recover(); err != nil {
//line cmd/gopcomm/community_yap.gox:463:1
//line cmd/gopcomm/community_yap.gox:422:1
http.Redirect(w, r, "/failed", http.StatusFound)
}
}()
//line cmd/gopcomm/community_yap.gox:467:1
//line cmd/gopcomm/community_yap.gox:426:1
h.ServeHTTP(w, r)
})
})
Expand Down
42 changes: 20 additions & 22 deletions cmd/gopcomm/yap/article_yap.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
<!-- Share to Twitter -->
<meta charset="UTF-8">
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="test">
<meta name="twitter:description" content="test">
<meta name="twitter:title" content="GoplusCommunity">
<meta name="twitter:description" content="GoplusCommunity">
<meta name="twitter:image" content="https://public-cdn.mokahr.com/72f7c42e-b069-4e14-9c29-ee20229cc256.png">

<!-- Share to Facebook -->
<meta name="description" content="Linz">
<meta property="og:title" content="Linz">
<meta property="og:description" content="Linz">
<meta name="description" content="GoplusCommunity">
<meta property="og:title" content="GoplusCommunity">
<meta property="og:description" content="GoplusCommunity">
<meta property="og:image" content="https://public-cdn.mokahr.com/72f7c42e-b069-4e14-9c29-ee20229cc256.png">
<meta property="og:url" content="http://8.130.26.238/animation/fb.html">

<meta property="og:type" content="website">

<!-- UI -->
Expand All @@ -41,6 +41,7 @@
font-family: 'Inter', 'Noto Sans SC'
}
</style>

</head>

<body style="background-color: #f7fafc;">
Expand Down Expand Up @@ -289,11 +290,14 @@ <h1 class="my-4 text-4xl font-extrabold leading-tight text-gray-900">
<n-button text class="mr-2" style="--n-text-color-hover: #3182ce;
--n-text-color-pressed: #3182ce;
--n-text-color-focus: #3182ce;
--n-text-color: #a0aec0;" @click="shareToWeChat">
--n-text-color: #a0aec0;">
<i class="ph-fill ph-wechat-logo" style="font-size: 20px;"></i>
</n-button>
</template>
WeChat
<n-space vertical>
<n-qr-code :value="currentHref" />
</n-space>
Scan qrcode to share on WeChat
</n-tooltip>
</div>
</n-gi>
Expand Down Expand Up @@ -384,6 +388,7 @@ <h1 class="my-4 text-4xl font-extrabold leading-tight text-gray-900">
Avatar: '',
Name: 'Nick_1977',
})
const currentHref = ref(window.location.href)

/*======= share related functions =======*/
function shareToFacebook() {
Expand All @@ -393,8 +398,8 @@ <h1 class="my-4 text-4xl font-extrabold leading-tight text-gray-900">
wTop = window.screenTop ? window.screenTop : window.screenY;
var left = wLeft + (window.innerWidth / 2) - (w / 2);
var top = wTop + (window.innerHeight / 2) - (h / 2);

var shareUrl = "http://www.facebook.com/sharer/sharer.php?u=http://8.130.26.238/animation/fb.html";
var url = window.location.href;
var shareUrl = "http://www.facebook.com/sharer/sharer.php?u="+url;
var title = 'facebook';

window.open(shareUrl, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
Expand All @@ -403,33 +408,26 @@ <h1 class="my-4 text-4xl font-extrabold leading-tight text-gray-900">
function shareToTwitter() {
// var url = encodeURIComponent('http://8.130.26.238/animation/fb.html');
// var text = encodeURIComponent('Linz');
var url = 'http://8.130.26.238/animation/fb.html';
var text = "Test"
var via = "Test";
var url = window.location.href;
var hashtags = "Test";
var intentUrl = "https://twitter.com/intent/tweet?text="
+ encodeURIComponent(text) + "&url=" + encodeURIComponent(url)
+ "&via=" + encodeURIComponent(via) + "&hashtags=" + encodeURIComponent(hashtags);
var intentUrl = "https://twitter.com/intent/tweet?url=" + encodeURIComponent(url)
+"&hashtags=" + encodeURIComponent(hashtags);
// var shareUrl = 'https://twitter.com/intent/tweet?text=' + text + '&url=' + url;
window.open(intentUrl, "_blank", "width=900, height=600");
};

function shareToWeChat() {
// TODO: @Lin 分享到微信
};

/*======= register vue component =======*/
const app = Vue.createApp({
data() {
return {
article,
author
author,
currentHref
}
},
methods: {
shareToFacebook,
shareToTwitter,
shareToWeChat,
}
});

Expand Down

0 comments on commit 1dc09bb

Please sign in to comment.