articleDetail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <view class="page">
  3. <view class="topUser">
  4. <image :src="home_image" class="home_image" mode="aspectFill"></image>
  5. <view class="list">
  6. <view class="img" :class="selImg==index?'active':''" v-for="(item,index) in image_list" :key="index"
  7. @click="selPhoto(item,index)">
  8. <image :src="item" mode="aspectFill"></image>
  9. </view>
  10. </view>
  11. </view>
  12. <view class="body">
  13. <view class="item">
  14. <view class="title">
  15. 标题标题标题标题标题
  16. </view>
  17. <view class="title2">
  18. 时间:2025-02-20
  19. </view>
  20. </view>
  21. <view class="item">
  22. <view class="content">内容内容内容内容内容</view>
  23. </view>
  24. <view class="list_info">
  25. <view class="blankHeight"></view>
  26. </view>
  27. </view>
  28. <!-- <view class="btn_submit" @click="chatTA()">
  29. <image class="icon" src="../../static/icon/icon_chat_white.png" mode="widthFix"></image>
  30. 私聊
  31. </view> -->
  32. <view class="thread2"></view>
  33. <view class="thread2"></view>
  34. <previewImage ref="previewImage" :opacity="0.8" :circular="true" :imgs="imgs" :descs="descs"></previewImage>
  35. <CComment ref="ccRef" :myInfo="myInfo" :userInfo="userInfo" :tableData="tableData" :tableTotal.sync="tableTotal"
  36. :deleteMode="deleteMode" @likeFun="likeFun" @replyFun="replyFun" @deleteFun="deleteFun"></CComment>
  37. <view class="btn" @tap="openComment">发表新评论</view>
  38. <view class="thread2"></view>
  39. </view>
  40. </template>
  41. <script>
  42. import CComment from "@/components/cc-comment/cc-comment.vue";
  43. import previewImage from '@/components/kxj-previewImage/kxj-previewImage.vue'; //引用插件
  44. export default {
  45. components: {
  46. previewImage,
  47. CComment
  48. },
  49. data() {
  50. return {
  51. title: '',
  52. userID: 0,
  53. selImg: 0,
  54. home_image: '',
  55. myinfo: {},
  56. tag_list: [],
  57. image_list: [],
  58. imgs: [],
  59. descs: [],
  60. list_wish: [],
  61. myInfo: {
  62. user_id: 1, // 用户id
  63. user_name: "cc", // 用户名
  64. user_avatar: "https://img0.baidu.com/it/u=2836960144,3650263035&fm=253&fmt=auto&app=138&f=JPEG?w=474&h=474", // 用户头像地址
  65. },
  66. // 文章作者信息(提示: 一般来自localstorage, 如果是实时获取的话, 那么获取到数据后再v-if显示评论组件)
  67. userInfo: {
  68. user_id: 2, // 用户id
  69. user_name: "ikun", // 用户名
  70. user_avatar: "https://pic1.zhimg.com/80/v2-a79071a705f55c5d88f6c74e6111fe84_720w.webp", // 用户头像地址
  71. },
  72. deleteMode: "all", //删除模式
  73. // 评论总数
  74. tableTotal: 4,
  75. // 评论表
  76. tableData: [{
  77. id: 120, // 评论id
  78. parent_id: null, // 评论父级的id
  79. reply_id: null, // 被回复评论的id
  80. reply_name: null, // 被回复人的名称
  81. user_id: 2, // 用户id
  82. user_name: "ikun", // 用户名
  83. user_avatar: "https://pic1.zhimg.com/80/v2-a79071a705f55c5d88f6c74e6111fe84_720w.webp", // 用户头像地址
  84. user_content: "唱,跳,rap,篮球", // 用户评论内容
  85. is_like: false, // 用户是否点赞
  86. like_count: 120, // 点赞数统计
  87. create_time: "2025-02-19 09:16", // 创建时间
  88. },
  89. {
  90. id: 130, // 评论id
  91. parent_id: 120, // 评论父级的id
  92. reply_id: 120, // 被回复评论的id
  93. reply_name: "ikun", // 被回复人的名称
  94. user_id: 3, // 用户id
  95. user_name: "小黑子", // 用户名
  96. user_avatar: "https://pic2.zhimg.com/80/v2-06eade66ec837713d765b1557bf20b25_720w.webp", // 用户头像地址
  97. user_content: "姬霓太美~祝自己生日快乐~~", // 用户评论内容
  98. is_like: false, // 用户是否点赞
  99. like_count: 67, // 点赞数统计
  100. create_time: "2025-03-07 00:06", // 创建时间
  101. },
  102. {
  103. id: 140, // 评论id
  104. parent_id: 120, // 评论父级的id
  105. reply_id: 130, // 被回复评论的id
  106. reply_name: "小黑子", // 被回复人的名称
  107. user_id: 4, // 用户id
  108. user_name: "守护宗主维护宗门", // 用户名
  109. user_avatar: "https://pic3.zhimg.com/80/v2-244696a62fa750b8570cf56bfaa5b26a_720w.webp", // 用户头像地址
  110. user_content: "你露出鸡脚了", // 用户评论内容
  111. is_like: false, // 用户是否点赞
  112. like_count: 16, // 点赞数统计
  113. create_time: "2025-05-10 17:08", // 创建时间
  114. },
  115. {
  116. id: 150, // 评论id
  117. parent_id: null, // 评论父级的id
  118. reply_id: null, // 被回复评论的id
  119. reply_name: null, // 被回复人的名称
  120. user_id: 5, // 用户id
  121. user_name: "音乐制作人", // 用户名
  122. user_avatar: "https://pic2.zhimg.com/80/v2-88ec6f8c6d3305122664dd18a28730e5_720w.webp", // 用户头像地址
  123. user_content: "只因你太美baby 只因你太美baby 只因你实在是太美baby 只因你太美baby 迎面走来的你让我如此蠢蠢欲动 这种感觉我从未有 Cause I got a crush on you who you 你是我的 我是你的 谁 再多一眼看一眼就会爆炸 再近一点靠近点快被融化", // 用户评论内容
  124. is_like: true, // 用户是否点赞
  125. like_count: 8, // 点赞数统计
  126. create_time: "2025-12-21 00:45", // 创建时间
  127. },
  128. ],
  129. }
  130. },
  131. onLoad(parms) {
  132. let self = this;
  133. this.userID = parms.uid || 1069;
  134. },
  135. onShow() {
  136. uni.$emit('check_update');
  137. this.loadData();
  138. this.loadWishData();
  139. },
  140. methods: {
  141. onLinqu(item) {
  142. uni.navigateTo({
  143. url: '/pages/my/wishHelp?id=' + item.myid,
  144. })
  145. },
  146. selPhoto(item, sel) {
  147. this.selImg = sel;
  148. this.home_image = this.image_list[sel];
  149. },
  150. chatTA() {
  151. // uni.navigateTo({
  152. // url: '/pages/chat/detail?userID=1&nickName=' + encodeURIComponent("昵称") +
  153. // "&conversationType=C2C"
  154. // });
  155. let conversationID = "";
  156. let conversationType = "C2C";
  157. let userID = "" + this.myinfo.userID;
  158. let nickName = this.myinfo.nickname;
  159. var jsonConversationID = encodeURIComponent(JSON.stringify(conversationID));
  160. var jsonConversationType = encodeURIComponent(JSON.stringify(conversationType));
  161. var jsonUserID = encodeURIComponent(JSON.stringify(userID));
  162. var jsonNickName = encodeURIComponent(JSON.stringify(nickName));
  163. uni.navigateTo({
  164. url: "/pages/chat/detail?userID=" + jsonUserID + "&nickName=" + jsonNickName +
  165. "&conversationID=" + jsonConversationID + "&conversationType=" + jsonConversationType
  166. })
  167. },
  168. toArr(imgs) {
  169. let arr = imgs.split("|");
  170. return arr;
  171. },
  172. previewOpen(imgs1, index) {
  173. this.imgs = imgs1.split("|");
  174. setTimeout(() => this.$refs.previewImage.open(index), 0)
  175. // 传入当前选中的图片地址或序号
  176. return; //如需测试和uni原生预览差别可注释这两行
  177. },
  178. loadWishData() {
  179. uni.request({
  180. url: this.$apiHost + '/Wish/getMyList',
  181. data: {
  182. uuid: getApp().globalData.uuid,
  183. userID: this.userID
  184. },
  185. header: {
  186. 'content-type': 'application/json'
  187. },
  188. success: (res) => {
  189. console.log("res", res.data)
  190. this.list_wish = res.data.list;
  191. }
  192. });
  193. },
  194. loadData() {
  195. // console.log({
  196. // uuid: getApp().globalData.uuid,
  197. // skey: getApp().globalData.skey
  198. // });
  199. uni.request({
  200. url: this.$apiHost + '/Member/getHomeInfo',
  201. data: {
  202. uuid: getApp().globalData.uuid,
  203. userID: this.userID
  204. },
  205. header: {
  206. "content-type": "application/json",
  207. 'sign': getApp().globalData.headerSign
  208. },
  209. success: (res) => {
  210. console.log("----:", res.data);
  211. this.myinfo = res.data;
  212. if (res.data.tags != "") {
  213. this.tag_list = res.data.tags.split(",");
  214. }
  215. if (res.data.images != "") {
  216. this.image_list = res.data.images.split(",");
  217. this.home_image = this.image_list[0];
  218. } else {
  219. this.home_image = "../../static/home/avator.png";
  220. }
  221. },
  222. complete: (com) => {
  223. // uni.hideLoading();
  224. },
  225. fail: (e) => {
  226. console.log("----e:", e);
  227. }
  228. });
  229. },
  230. ZhanTA(item, index) {
  231. // this.list[index].is_like = 1;
  232. // this.list[index].num_like++;
  233. // return;
  234. let that = this;
  235. uni.request({
  236. url: this.$apiHost + '/Article/zanTA',
  237. data: {
  238. uuid: getApp().globalData.uuid,
  239. id: item.id
  240. },
  241. header: {
  242. "content-type": "application/json",
  243. 'sign': getApp().globalData.headerSign
  244. },
  245. success: (res) => {
  246. console.log("----:", res.data);
  247. if (res.data.success == "yes") {
  248. that.myinfo.article_list[index].is_like = 1;
  249. that.myinfo.article_list[index].num_like++;
  250. }
  251. },
  252. complete: (com) => {
  253. // uni.hideLoading();
  254. },
  255. fail: (e) => {
  256. console.log("----e:", e);
  257. }
  258. });
  259. },
  260. // 唤起新评论弹框
  261. openComment() {
  262. let ccRef = this.$refs["ccRef"];
  263. ccRef.newCommentFun();
  264. },
  265. // 点赞回调事件
  266. likeFun({
  267. params
  268. }, callback) {
  269. console.log("likeFun", params);
  270. uni.request({
  271. url: this.$apiHost + '/ArticleReply/zanTA',
  272. data: {
  273. uuid: getApp().globalData.uuid,
  274. id: params.id
  275. },
  276. header: {
  277. "content-type": "application/json",
  278. 'sign': getApp().globalData.headerSign
  279. },
  280. success: (res) => {
  281. console.log("点赞结果:", res.data);
  282. if (res.data.success !== "yes") {
  283. callback(res); // 请求失败时重置点赞效果
  284. }
  285. },
  286. fail: (e) => {
  287. console.log("点赞失败:", e);
  288. callback(e); // 请求失败时重置点赞效果
  289. }
  290. });
  291. },
  292. // 评论回调事件
  293. replyFun({
  294. params
  295. }, callback) {
  296. // params = {
  297. // ...params,
  298. // user_id: this.myInfo.user_id, // 用户id
  299. // user_name: this.myInfo.user_name, // 用户名
  300. // user_avatar: this.myInfo.user_avatar, // 用户头像地址
  301. // user_content: this.commentValue, // 用户评论内容
  302. // is_like: false, // 是否点赞
  303. // like_count: 0, // 点赞数统计
  304. // create_time: "刚刚", // 创建时间
  305. // owner: true, // 是否为所有者 所有者可以进行删除 管理员默认true
  306. // };
  307. console.log("replyFun", params);
  308. uni.request({
  309. url: this.$apiHost + '/ArticleReply/new',
  310. data: {
  311. uuid: getApp().globalData.uuid,
  312. article_id: this.userID, // 文章ID
  313. content: params.user_content, // 评论内容
  314. parent_id: params.parent_id || 0, // 父评论ID
  315. reply_id: params.reply_id || 0, // 回复的评论ID
  316. reply_name: params.reply_name || '' // 被回复人名称
  317. },
  318. header: {
  319. "content-type": "application/json",
  320. 'sign': getApp().globalData.headerSign
  321. },
  322. success: (res) => {
  323. console.log("评论结果:", res.data);
  324. if (res.data.success === "yes") {
  325. callback(res.data); // 评论成功,传入后端返回的数据
  326. }
  327. },
  328. fail: (e) => {
  329. console.log("评论失败:", e);
  330. uni.showToast({
  331. title: '评论失败,请重试',
  332. icon: 'none'
  333. });
  334. }
  335. });
  336. },
  337. /** 删除回调事件
  338. * mode 删除模式
  339. * -- bind: 当被删除的一级评论存在回复评论, 那么该评论内容变更显示为[当前评论内容已被移除]
  340. * -- only: 仅删除当前评论(后端删除相关联的回复评论, 否则总数显示不对)
  341. * -- all : 删除所有评论包括回复评论 前端遍历子评论上报
  342. */
  343. deleteFun({
  344. params,
  345. mode
  346. }, callback) {
  347. console.log("deleteFun", {
  348. params,
  349. mode
  350. });
  351. // 当请求成功, 调用callback执行评论删除;
  352. // Demo如下:
  353. // axios.post("http://xxx/delete", { ids: params, mode }).then((res) => {
  354. // if (res.code === 0) {
  355. // callback(res);
  356. // }
  357. // });
  358. switch (mode) {
  359. case "bind":
  360. // 逻辑: 调用接口进行评论内容修改 update
  361. setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  362. break;
  363. case "only":
  364. // 逻辑: 调用接口删除一个评论 delete
  365. setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  366. break;
  367. default:
  368. // all
  369. // 逻辑: 调用接口删除多个评论 [delete]
  370. setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  371. break;
  372. }
  373. },
  374. }
  375. }
  376. </script>
  377. <style scoped lang="scss">
  378. @import 'articleDetail.scss';
  379. </style>