index.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_index = require("../../sheep/index.js");
  4. const pages_chat_emoji = require("./emoji.js");
  5. const pages_chat_socket = require("./socket.js");
  6. require("../../sheep/url/index.js");
  7. require("../../sheep/store/index.js");
  8. require("../../sheep/store/app.js");
  9. require("../../sheep/api/promotion/diy.js");
  10. require("../../sheep/request/index.js");
  11. require("../../sheep/config/index.js");
  12. require("../../sheep/platform/index.js");
  13. require("../../sheep/platform/provider/wechat/index.js");
  14. require("../../sheep/platform/provider/wechat/miniProgram.js");
  15. require("../../sheep/api/member/auth.js");
  16. require("../../sheep/api/member/social.js");
  17. require("../../sheep/api/member/user.js");
  18. require("../../sheep/platform/provider/apple/index.js");
  19. require("../../sheep/platform/share.js");
  20. require("../../sheep/router/index.js");
  21. require("../../sheep/hooks/useModal.js");
  22. require("../../sheep/helper/index.js");
  23. require("../../sheep/helper/test.js");
  24. require("../../sheep/helper/digit.js");
  25. require("../../sheep/helper/throttle.js");
  26. require("../../sheep/platform/pay.js");
  27. require("../../sheep/api/pay/order.js");
  28. require("../../sheep/store/user.js");
  29. require("../../sheep/store/cart.js");
  30. require("../../sheep/api/trade/cart.js");
  31. require("../../sheep/api/pay/wallet.js");
  32. require("../../sheep/api/trade/order.js");
  33. require("../../sheep/api/promotion/coupon.js");
  34. require("../../sheep/store/sys.js");
  35. require("../../sheep/store/modal.js");
  36. require("../../sheep/config/zIndex.js");
  37. if (!Array) {
  38. const _easycom_su_image2 = common_vendor.resolveComponent("su-image");
  39. const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
  40. const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
  41. const _easycom_s_uploader2 = common_vendor.resolveComponent("s-uploader");
  42. const _easycom_su_popup2 = common_vendor.resolveComponent("su-popup");
  43. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  44. (_easycom_su_image2 + _easycom_uni_easyinput2 + _easycom_su_fixed2 + _easycom_s_uploader2 + _easycom_su_popup2 + _easycom_s_layout2)();
  45. }
  46. const _easycom_su_image = () => "../../sheep/ui/su-image/su-image.js";
  47. const _easycom_uni_easyinput = () => "../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
  48. const _easycom_su_fixed = () => "../../sheep/ui/su-fixed/su-fixed.js";
  49. const _easycom_s_uploader = () => "../../sheep/components/s-uploader/s-uploader.js";
  50. const _easycom_su_popup = () => "../../sheep/ui/su-popup/su-popup.js";
  51. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  52. if (!Math) {
  53. (_easycom_su_image + GoodsItem + OrderItem + _easycom_uni_easyinput + _easycom_su_fixed + _easycom_s_uploader + _easycom_su_popup + SelectPopup + _easycom_s_layout)();
  54. }
  55. const SelectPopup = () => "./components/select-popup.js";
  56. const GoodsItem = () => "./components/goods.js";
  57. const OrderItem = () => "./components/order.js";
  58. const _sfc_main = {
  59. __name: "index",
  60. setup(__props) {
  61. const {
  62. socketInit,
  63. state: chatData,
  64. socketSendMsg,
  65. formatChatInput,
  66. socketHistoryList,
  67. onDrop,
  68. onPaste,
  69. getFocus,
  70. // upload,
  71. getUserToken,
  72. // socketTest,
  73. showTime,
  74. formatTime
  75. } = pages_chat_socket.useChatWebSocket();
  76. const chatList = common_vendor.toRefs(chatData).chatList;
  77. const customerServiceInfo = common_vendor.toRefs(chatData).customerServerInfo;
  78. const chatHistoryPagination = common_vendor.toRefs(chatData).chatHistoryPagination;
  79. const customerUserInfo = common_vendor.toRefs(chatData).customerUserInfo;
  80. const socketState = common_vendor.toRefs(chatData).socketState;
  81. const sys_navBar = sheep_index.sheep.$platform.navbar;
  82. const chatConfig = common_vendor.computed(() => sheep_index.sheep.$store("app").chat);
  83. const { screenHeight, safeAreaInsets, safeArea, screenWidth } = sheep_index.sheep.$platform.device;
  84. const pageHeight = safeArea.height - 44 - 35 - 50;
  85. const loadingMap = {
  86. loadmore: {
  87. title: "查看更多",
  88. icon: "el-icon-d-arrow-left"
  89. },
  90. nomore: {
  91. title: "没有更多了",
  92. icon: ""
  93. },
  94. loading: {
  95. title: "加载中... ",
  96. icon: "el-icon-loading"
  97. }
  98. };
  99. const onLoadMore = () => {
  100. chatHistoryPagination.value.page < chatHistoryPagination.value.lastPage && socketHistoryList();
  101. };
  102. const chat = common_vendor.reactive({
  103. msg: "",
  104. scrollInto: "",
  105. showTools: false,
  106. toolsMode: "",
  107. showSelect: false,
  108. selectMode: "",
  109. chatStyle: {
  110. mode: "inner",
  111. color: "#F8270F",
  112. type: "color",
  113. alwaysShow: 1,
  114. src: "",
  115. list: {}
  116. }
  117. });
  118. function onTools(mode) {
  119. if (!socketState.value.isConnect) {
  120. sheep_index.sheep.$helper.toast(socketState.value.tip || "您已掉线!请返回重试");
  121. return;
  122. }
  123. if (!chat.toolsMode || chat.toolsMode === mode) {
  124. chat.showTools = !chat.showTools;
  125. }
  126. chat.toolsMode = mode;
  127. if (!chat.showTools) {
  128. chat.toolsMode = "";
  129. }
  130. }
  131. function onShowSelect(mode) {
  132. chat.showTools = false;
  133. chat.showSelect = true;
  134. chat.selectMode = mode;
  135. }
  136. async function onSelect({ type, data }) {
  137. let msg = "";
  138. switch (type) {
  139. case "image":
  140. const { path, fullurl } = await sheep_index.sheep.$api.app.upload(data.tempFiles[0].path, "default");
  141. msg = {
  142. from: "customer",
  143. mode: "image",
  144. date: (/* @__PURE__ */ new Date()).getTime(),
  145. content: {
  146. url: fullurl,
  147. path
  148. }
  149. };
  150. break;
  151. case "goods":
  152. msg = {
  153. from: "customer",
  154. mode: "goods",
  155. date: (/* @__PURE__ */ new Date()).getTime(),
  156. content: {
  157. item: {
  158. id: data.goods.id,
  159. title: data.goods.title,
  160. image: data.goods.image,
  161. price: data.goods.price,
  162. stock: data.goods.stock
  163. }
  164. }
  165. };
  166. break;
  167. case "order":
  168. msg = {
  169. from: "customer",
  170. mode: "order",
  171. date: (/* @__PURE__ */ new Date()).getTime(),
  172. content: {
  173. item: {
  174. id: data.id,
  175. order_sn: data.order_sn,
  176. create_time: data.create_time,
  177. pay_fee: data.pay_fee,
  178. items: data.items.filter((item) => ({
  179. goods_id: item.goods_id,
  180. goods_title: item.goods_title,
  181. goods_image: item.goods_image,
  182. goods_price: item.goods_price
  183. })),
  184. status_text: data.status_text
  185. }
  186. }
  187. };
  188. break;
  189. }
  190. if (msg) {
  191. socketSendMsg(msg, () => {
  192. scrollBottom();
  193. });
  194. chat.showTools = false;
  195. chat.showSelect = false;
  196. chat.selectMode = "";
  197. }
  198. }
  199. function onSendMessage() {
  200. if (!socketState.value.isConnect) {
  201. sheep_index.sheep.$helper.toast(socketState.value.tip || "您已掉线!请返回重试");
  202. return;
  203. }
  204. if (!chat.msg)
  205. return;
  206. const data = {
  207. from: "customer",
  208. mode: "text",
  209. date: (/* @__PURE__ */ new Date()).getTime(),
  210. content: {
  211. text: chat.msg
  212. }
  213. };
  214. socketSendMsg(data, () => {
  215. scrollBottom();
  216. });
  217. chat.showTools = false;
  218. setTimeout(() => {
  219. chat.msg = "";
  220. }, 100);
  221. }
  222. function onTemplateList(e) {
  223. if (!socketState.value.isConnect) {
  224. sheep_index.sheep.$helper.toast(socketState.value.tip || "您已掉线!请返回重试");
  225. return;
  226. }
  227. const data = {
  228. from: "customer",
  229. mode: "text",
  230. date: (/* @__PURE__ */ new Date()).getTime(),
  231. content: {
  232. text: e.title
  233. },
  234. customData: {
  235. question_id: e.id
  236. }
  237. };
  238. socketSendMsg(data, () => {
  239. scrollBottom();
  240. });
  241. }
  242. function onEmoji(item) {
  243. chat.msg += item.name;
  244. }
  245. function selEmojiFile(name) {
  246. for (let index in pages_chat_emoji.emojiList) {
  247. if (pages_chat_emoji.emojiList[index].name === name) {
  248. return pages_chat_emoji.emojiList[index].file;
  249. }
  250. }
  251. return false;
  252. }
  253. function replaceEmoji(data) {
  254. let newData = data;
  255. if (typeof newData !== "object") {
  256. let reg = /\[(.+?)\]/g;
  257. let zhEmojiName = newData.match(reg);
  258. if (zhEmojiName) {
  259. zhEmojiName.forEach((item) => {
  260. let emojiFile = selEmojiFile(item);
  261. newData = newData.replace(
  262. item,
  263. `<img class="chat-img" style="width: 24px;height: 24px;margin: 0 3px;" src="${sheep_index.sheep.$url.cdn(
  264. "/static/img/chat/emoji/" + emojiFile
  265. )}"/>`
  266. );
  267. });
  268. }
  269. }
  270. return newData;
  271. }
  272. function scrollBottom() {
  273. let timeout = null;
  274. chat.scrollInto = "";
  275. clearTimeout(timeout);
  276. timeout = setTimeout(() => {
  277. chat.scrollInto = "scrollBottom";
  278. }, 100);
  279. }
  280. common_vendor.onLoad(async () => {
  281. const { error } = await getUserToken();
  282. if (error === 0) {
  283. socketInit(chatConfig.value, () => {
  284. scrollBottom();
  285. });
  286. } else {
  287. socketState.value.isConnect = false;
  288. }
  289. });
  290. return (_ctx, _cache) => {
  291. return common_vendor.e({
  292. a: common_vendor.t(common_vendor.unref(socketState).isConnect ? common_vendor.unref(customerServiceInfo).title : "网络已断开,请检查网络后刷新重试"),
  293. b: common_vendor.unref(sys_navBar) + "px",
  294. c: common_vendor.unref(chatList).length && common_vendor.unref(chatHistoryPagination).lastPage > 1 && loadingMap[common_vendor.unref(chatHistoryPagination).loadStatus].title
  295. }, common_vendor.unref(chatList).length && common_vendor.unref(chatHistoryPagination).lastPage > 1 && loadingMap[common_vendor.unref(chatHistoryPagination).loadStatus].title ? {
  296. d: common_vendor.t(loadingMap[common_vendor.unref(chatHistoryPagination).loadStatus].title),
  297. e: common_vendor.n(loadingMap[common_vendor.unref(chatHistoryPagination).loadStatus].icon),
  298. f: common_vendor.o(onLoadMore)
  299. } : {}, {
  300. g: common_vendor.f(common_vendor.unref(chatList), (item, index, i0) => {
  301. var _a;
  302. return common_vendor.e({
  303. a: item.from !== "system" && common_vendor.unref(showTime)(item, index)
  304. }, item.from !== "system" && common_vendor.unref(showTime)(item, index) ? {
  305. b: common_vendor.t(common_vendor.unref(formatTime)(item.date))
  306. } : {}, {
  307. c: item.from === "system"
  308. }, item.from === "system" ? {
  309. d: common_vendor.t(item.content.text)
  310. } : {}, {
  311. e: item.mode === "template" && item.content.list.length
  312. }, item.mode === "template" && item.content.list.length ? {
  313. f: common_vendor.f(item.content.list, (item2, index2, i1) => {
  314. return {
  315. a: common_vendor.t(item2.title),
  316. b: index2,
  317. c: common_vendor.o(($event) => onTemplateList(item2), index2)
  318. };
  319. })
  320. } : {}, {
  321. g: item.from === "customer_service" && item.mode !== "template" || item.from === "customer"
  322. }, item.from === "customer_service" && item.mode !== "template" || item.from === "customer" ? common_vendor.e({
  323. h: item.from === "customer_service",
  324. i: common_vendor.unref(sheep_index.sheep).$url.cdn((_a = item == null ? void 0 : item.sender) == null ? void 0 : _a.avatar) || common_vendor.unref(sheep_index.sheep).$url.static("/static/img/shop/chat/default.png"),
  325. j: item.from === "customer" && index == common_vendor.unref(chatData).chatList.length - 1 && common_vendor.unref(chatData).isSendSucces !== 0
  326. }, item.from === "customer" && index == common_vendor.unref(chatData).chatList.length - 1 && common_vendor.unref(chatData).isSendSucces !== 0 ? common_vendor.e({
  327. k: common_vendor.unref(chatData).isSendSucces == -1
  328. }, common_vendor.unref(chatData).isSendSucces == -1 ? {
  329. l: common_vendor.unref(sheep_index.sheep).$url.static("/static/img/shop/chat/loading.png")
  330. } : {}) : {}, {
  331. m: item.mode === "text"
  332. }, item.mode === "text" ? {
  333. n: replaceEmoji(item.content.text),
  334. o: common_vendor.o((...args) => _ctx.onRichtext && _ctx.onRichtext(...args), index),
  335. p: common_vendor.n(item.from)
  336. } : {}, {
  337. q: item.mode === "image"
  338. }, item.mode === "image" ? {
  339. r: "5a559478-1-" + i0 + ",5a559478-0",
  340. s: common_vendor.p({
  341. isPreview: true,
  342. previewList: [common_vendor.unref(sheep_index.sheep).$url.cdn(item.content.url)],
  343. current: 0,
  344. src: common_vendor.unref(sheep_index.sheep).$url.cdn(item.content.url),
  345. height: 200,
  346. width: 200,
  347. mode: "aspectFill"
  348. }),
  349. t: common_vendor.n(item.from)
  350. } : {}, {
  351. v: item.mode === "goods"
  352. }, item.mode === "goods" ? {
  353. w: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  354. id: item.content.item.id
  355. }), index),
  356. x: "5a559478-2-" + i0 + ",5a559478-0",
  357. y: common_vendor.p({
  358. goodsData: item.content.item
  359. })
  360. } : {}, {
  361. z: item.mode === "order"
  362. }, item.mode === "order" ? {
  363. A: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/order/detail", {
  364. id: item.content.item.id
  365. }), index),
  366. B: "5a559478-3-" + i0 + ",5a559478-0",
  367. C: common_vendor.p({
  368. from: "msg",
  369. orderData: item.content.item
  370. })
  371. } : {}, {
  372. D: item.from === "customer",
  373. E: common_vendor.unref(sheep_index.sheep).$url.cdn(common_vendor.unref(customerUserInfo).avatar),
  374. F: common_vendor.n(item.from === "customer_service" ? `ss-row-left` : item.from === "customer" ? `ss-row-right` : "")
  375. }) : {}, {
  376. G: index
  377. });
  378. }),
  379. h: pageHeight + "px",
  380. i: chat.scrollInto,
  381. j: pageHeight + "px",
  382. k: common_vendor.o(($event) => chat.msg = $event),
  383. l: common_vendor.p({
  384. inputBorder: false,
  385. clearable: false,
  386. placeholder: "请输入你要咨询的问题",
  387. modelValue: chat.msg
  388. }),
  389. m: common_vendor.o(($event) => onTools("emoji")),
  390. n: !chat.msg
  391. }, !chat.msg ? {
  392. o: chat.toolsMode == "tools" ? 1 : "",
  393. p: common_vendor.o(($event) => onTools("tools"))
  394. } : {}, {
  395. q: chat.msg
  396. }, chat.msg ? {
  397. r: common_vendor.o(onSendMessage)
  398. } : {}, {
  399. s: common_vendor.p({
  400. bottom: true
  401. }),
  402. t: common_vendor.o(($event) => chat.msg = $event),
  403. v: common_vendor.p({
  404. inputBorder: false,
  405. clearable: false,
  406. placeholder: "请输入你要咨询的问题",
  407. modelValue: chat.msg
  408. }),
  409. w: common_vendor.o(($event) => onTools("emoji")),
  410. x: !chat.msg
  411. }, !chat.msg ? {
  412. y: chat.toolsMode == "tools" ? 1 : "",
  413. z: common_vendor.o(($event) => onTools("tools"))
  414. } : {}, {
  415. A: chat.msg
  416. }, chat.msg ? {
  417. B: common_vendor.o(onSendMessage)
  418. } : {}, {
  419. C: chat.toolsMode == "emoji"
  420. }, chat.toolsMode == "emoji" ? {
  421. D: common_vendor.f(common_vendor.unref(pages_chat_emoji.emojiPage), (emoji, k0, i0) => {
  422. return {
  423. a: common_vendor.f(emoji, (item, k1, i1) => {
  424. return {
  425. a: common_vendor.unref(sheep_index.sheep).$url.cdn(`/static/img/chat/emoji/${item.file}`),
  426. b: common_vendor.o(($event) => onEmoji(item), item),
  427. c: item
  428. };
  429. }),
  430. b: emoji
  431. };
  432. })
  433. } : {
  434. E: common_vendor.unref(sheep_index.sheep).$url.static("/static/img/shop/chat/image.png"),
  435. F: common_vendor.o(($event) => onSelect({
  436. type: "image",
  437. data: $event
  438. })),
  439. G: common_vendor.p({
  440. ["file-mediatype"]: "image",
  441. imageStyles: {
  442. width: 50,
  443. height: 50,
  444. border: false
  445. }
  446. }),
  447. H: common_vendor.unref(sheep_index.sheep).$url.static("/static/img/shop/chat/goods.png"),
  448. I: common_vendor.o(($event) => onShowSelect("goods")),
  449. J: common_vendor.unref(sheep_index.sheep).$url.static("/static/img/shop/chat/order.png"),
  450. K: common_vendor.o(($event) => onShowSelect("order"))
  451. }, {
  452. L: common_vendor.o(($event) => {
  453. chat.showTools = false;
  454. chat.toolsMode = "";
  455. }),
  456. M: common_vendor.p({
  457. show: chat.showTools
  458. }),
  459. N: common_vendor.o(onSelect),
  460. O: common_vendor.o(($event) => chat.showSelect = false),
  461. P: common_vendor.p({
  462. mode: chat.selectMode,
  463. show: chat.showSelect
  464. }),
  465. Q: common_vendor.p({
  466. title: "客服",
  467. navbar: "inner"
  468. })
  469. });
  470. };
  471. }
  472. };
  473. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-5a559478"], ["__file", "/Users/RuHu.Xu/Desktop/mall-newfeifan-zx-app/pages/chat/index.vue"]]);
  474. wx.createPage(MiniProgramPage);