This commit is contained in:
@@ -257,7 +257,11 @@ func (ctl *posts) Mine(
|
||||
|
||||
conds := []gen.Condition{
|
||||
models.PostQuery.Status.Eq(fields.PostStatusPublished),
|
||||
models.PostQuery.Title.Like(database.WrapLike(*query.Keyword)),
|
||||
}
|
||||
if query.Keyword != nil && *query.Keyword != "" {
|
||||
conds = append(conds,
|
||||
models.PostQuery.Title.Like(database.WrapLike(*query.Keyword)),
|
||||
)
|
||||
}
|
||||
|
||||
pager, err := services.Users.PostList(ctx, user.ID, pagination, conds...)
|
||||
|
||||
@@ -56,39 +56,26 @@ func (m *users) PostList(
|
||||
// OFFSET(pagination.Offset)
|
||||
// m.log().Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
// var posts []Posts
|
||||
// err := stmt.QueryContext(ctx, db, &posts)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, qrm.ErrNoRows) {
|
||||
// return &requests.Pager{
|
||||
// Items: nil,
|
||||
// Total: 0,
|
||||
// Pagination: *pagination,
|
||||
// }, nil
|
||||
// }
|
||||
// m.log().Errorf("error querying posts: %v", err)
|
||||
// return nil, err
|
||||
// }
|
||||
tbl, query := models.UserPostQuery.QueryContext(ctx)
|
||||
pagePosts, cnt, err := query.Select(tbl.PostID).
|
||||
Where(tbl.UserID.Eq(userId)).
|
||||
FindByPage(int(pagination.Offset()), int(pagination.Limit))
|
||||
|
||||
// // total count
|
||||
// var cnt struct {
|
||||
// Cnt int64
|
||||
// }
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
postIds := lo.Map(pagePosts, func(item *models.UserPost, _ int) int64 { return item.PostID })
|
||||
|
||||
// stmtCnt := tblUserPosts.SELECT(COUNT(tblUserPosts.ID).AS("cnt")).WHERE(tblUserPosts.UserID.EQ(Int64(userId)))
|
||||
// m.log().Infof("sql: %s", stmtCnt.DebugSql())
|
||||
|
||||
// if err := stmtCnt.QueryContext(ctx, db, &cnt); err != nil {
|
||||
// m.log().Errorf("error counting users: %v", err)
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// return &requests.Pager{
|
||||
// Items: posts,
|
||||
// Total: cnt.Cnt,
|
||||
// Pagination: *pagination,
|
||||
// }, nil
|
||||
return nil, nil
|
||||
postTbl, postQuery := models.PostQuery.QueryContext(ctx)
|
||||
items, err := postQuery.Where(postTbl.ID.In(postIds...)).Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &requests.Pager{
|
||||
Items: items,
|
||||
Total: cnt,
|
||||
Pagination: *pagination,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetUsersMapByIDs
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import client from './client';
|
||||
|
||||
export const wechatApi = {
|
||||
jsSdk() {
|
||||
return client.get('/wechats/js-sdk', {
|
||||
params: {
|
||||
url: window.location.href.split('#')[0],
|
||||
},
|
||||
});
|
||||
},
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import wx from "weixin-js-sdk";
|
||||
|
||||
export function useWxSDK() {
|
||||
let ready = false;
|
||||
|
||||
/**
|
||||
* 初始化设置
|
||||
*/
|
||||
@@ -24,8 +26,13 @@ export function useWxSDK() {
|
||||
});
|
||||
wx.ready(() => {
|
||||
console.log("wx.ready called");
|
||||
ready = true;
|
||||
resolve(true);
|
||||
});
|
||||
wx.error(() => {
|
||||
ready = false;
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,39 +42,46 @@ export function useWxSDK() {
|
||||
onSuccess = () => { },
|
||||
onCancel = () => { }
|
||||
) {
|
||||
if (!ready) {
|
||||
return;
|
||||
}
|
||||
console.log("setShareInfo called", shareInfo);
|
||||
wx.updateTimelineShareData({
|
||||
title: shareInfo.title, // 分享标题
|
||||
link: shareInfo.link, // 分享链接,可以不是当前页面,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
||||
imgUrl: shareInfo.imgUrl,
|
||||
success: function (e) {
|
||||
console.log("分享朋友圈成功", e);
|
||||
// 用户确认分享后执行的回调函数
|
||||
onSuccess();
|
||||
},
|
||||
cancel: function (e) {
|
||||
console.log("分享朋友圈取消", e);
|
||||
onCancel();
|
||||
// 用户取消分享后执行的回调函数
|
||||
},
|
||||
});
|
||||
wx.updateAppMessageShareData({
|
||||
title: shareInfo.title, // 分享标题
|
||||
desc: shareInfo.desc,
|
||||
link: shareInfo.link, // 分享链接,可以不是当前页面,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
||||
imgUrl: shareInfo.imgUrl,
|
||||
type: "link", // 分享类型,music、video或link,不填默认为link
|
||||
success: function (e) {
|
||||
// 用户确认分享后执行的回调函数
|
||||
console.log("分享成功", e);
|
||||
onSuccess();
|
||||
},
|
||||
cancel: function (e) {
|
||||
// 用户取消分享后执行的回调函数
|
||||
console.log("分享取消", e);
|
||||
onCancel();
|
||||
},
|
||||
});
|
||||
try {
|
||||
wx.updateTimelineShareData({
|
||||
title: shareInfo.title, // 分享标题
|
||||
link: shareInfo.link, // 分享链接,可以不是当前页面,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
||||
imgUrl: shareInfo.imgUrl,
|
||||
success: function (e) {
|
||||
console.log("分享朋友圈成功", e);
|
||||
// 用户确认分享后执行的回调函数
|
||||
onSuccess();
|
||||
},
|
||||
cancel: function (e) {
|
||||
console.log("分享朋友圈取消", e);
|
||||
onCancel();
|
||||
// 用户取消分享后执行的回调函数
|
||||
},
|
||||
});
|
||||
wx.updateAppMessageShareData({
|
||||
title: shareInfo.title, // 分享标题
|
||||
desc: shareInfo.desc,
|
||||
link: shareInfo.link, // 分享链接,可以不是当前页面,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
||||
imgUrl: shareInfo.imgUrl,
|
||||
type: "link", // 分享类型,music、video或link,不填默认为link
|
||||
success: function (e) {
|
||||
// 用户确认分享后执行的回调函数
|
||||
console.log("分享成功", e);
|
||||
onSuccess();
|
||||
},
|
||||
cancel: function (e) {
|
||||
// 用户取消分享后执行的回调函数
|
||||
console.log("分享取消", e);
|
||||
onCancel();
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
/** 是否是ios微信 */
|
||||
@@ -80,4 +94,4 @@ export function useWxSDK() {
|
||||
setShareInfo,
|
||||
isiOSWechat,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import { onMounted, onUnmounted, ref } from "vue";
|
||||
import { BsChevronLeft } from "vue-icons-plus/bs";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { postApi } from "../api/postApi";
|
||||
import { wechatApi } from "../api/wechatApi";
|
||||
import { useWxSDK } from "../hooks/useWxSDK";
|
||||
|
||||
const wx = useWxSDK();
|
||||
@@ -172,25 +171,6 @@ const handleBack = () => {
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
wechatApi
|
||||
.jsSdk()
|
||||
.then((resp) => {
|
||||
wx.initConfig(resp.data).then(() => {
|
||||
wx.setShareInfo({
|
||||
title: article.value.title,
|
||||
desc: article.value.content,
|
||||
link: window.location.href,
|
||||
imgUrl: article.value.head_images[0],
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to initialize WeChat SDK:", error);
|
||||
})
|
||||
.finally(() => {
|
||||
|
||||
});
|
||||
|
||||
await fetchArticle();
|
||||
});
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user