|
@@ -0,0 +1,263 @@
|
|
|
+"use strict";
|
|
|
+const common_vendor = require("../../common/vendor.js");
|
|
|
+const submit_1 = () => "./common/submit_1.js";
|
|
|
+const _sfc_main = {
|
|
|
+ components: {
|
|
|
+ submit_1
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ config: {},
|
|
|
+ user: {},
|
|
|
+ // 聊天记录
|
|
|
+ msgList: [],
|
|
|
+ total: 0,
|
|
|
+ skip: 0,
|
|
|
+ limit: 6,
|
|
|
+ page: 0,
|
|
|
+ // 判断是否跳到最后一条
|
|
|
+ is_bottom: true,
|
|
|
+ // 判断是否下拉刷新复位
|
|
|
+ triggered: false,
|
|
|
+ scrollToView: "",
|
|
|
+ //滑动最后一条信息
|
|
|
+ // 判断是否是选择图片刷新
|
|
|
+ is_img: false
|
|
|
+ };
|
|
|
+ },
|
|
|
+ onShow: async function() {
|
|
|
+ const that = this;
|
|
|
+ that.searchToken();
|
|
|
+ that.searchConfig();
|
|
|
+ if (!that.is_img) {
|
|
|
+ await that.clearPage();
|
|
|
+ await that.search();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onPullDownRefresh: async function() {
|
|
|
+ const that = this;
|
|
|
+ that.clearPage();
|
|
|
+ await that.search();
|
|
|
+ common_vendor.index.stopPullDownRefresh();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ searchToken() {
|
|
|
+ const that = this;
|
|
|
+ try {
|
|
|
+ const res = common_vendor.index.getStorageSync("token");
|
|
|
+ if (res)
|
|
|
+ that.$set(that, `user`, res);
|
|
|
+ } catch (e) {
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: err.errmsg,
|
|
|
+ icon: "error",
|
|
|
+ duration: 2e3
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ searchConfig() {
|
|
|
+ const that = this;
|
|
|
+ try {
|
|
|
+ const res = common_vendor.index.getStorageSync("config");
|
|
|
+ if (res)
|
|
|
+ that.$set(that, `config`, res);
|
|
|
+ } catch (e) {
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: err.errmsg,
|
|
|
+ icon: "error",
|
|
|
+ duration: 2e3
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async search() {
|
|
|
+ const that = this;
|
|
|
+ if (!that.user._id)
|
|
|
+ return;
|
|
|
+ let info = {
|
|
|
+ skip: that.skip,
|
|
|
+ limit: that.limit,
|
|
|
+ user: that.user._id
|
|
|
+ };
|
|
|
+ const res = await that.$api(`/chat`, "GET", {
|
|
|
+ ...info
|
|
|
+ });
|
|
|
+ if (res.errcode == "0") {
|
|
|
+ let list = [...res.data.reverse(), ...that.msgList];
|
|
|
+ that.$set(that, `msgList`, list);
|
|
|
+ that.$set(that, `total`, res.total);
|
|
|
+ } else {
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: res.errmsg
|
|
|
+ });
|
|
|
+ }
|
|
|
+ that.goBottom();
|
|
|
+ },
|
|
|
+ // 进行图片的预览
|
|
|
+ previewImg(e) {
|
|
|
+ common_vendor.index.previewImage({
|
|
|
+ current: 0,
|
|
|
+ urls: [e],
|
|
|
+ longPressActions: {
|
|
|
+ itemList: ["发送给朋友", "保存图片", "收藏"],
|
|
|
+ success: function(data) {
|
|
|
+ console.log("选中了第" + (data.tapIndex + 1) + "个按钮,第" + (data.index + 1) + "张图片");
|
|
|
+ },
|
|
|
+ fail: function(err2) {
|
|
|
+ console.log(err2.errMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 判断是否是选择图片刷新
|
|
|
+ choseImg(e) {
|
|
|
+ const that = this;
|
|
|
+ that.$set(that, `is_img`, e);
|
|
|
+ },
|
|
|
+ //接受输入内容
|
|
|
+ async inputs(e) {
|
|
|
+ const that = this;
|
|
|
+ let user = that.user;
|
|
|
+ if (user._id) {
|
|
|
+ let data = {
|
|
|
+ "user": user._id,
|
|
|
+ "speaker": user._id,
|
|
|
+ "content": e.message,
|
|
|
+ "time": common_vendor.hooks().format("YYYY-MM-DD HH:mm:ss"),
|
|
|
+ "msg_type": e.type
|
|
|
+ };
|
|
|
+ let res = await that.$api(`/chat`, `POST`, data);
|
|
|
+ if (res.errcode == "0") {
|
|
|
+ that.msgList.push(res.data);
|
|
|
+ } else {
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: res.errmsg,
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ }
|
|
|
+ that.goBottom();
|
|
|
+ } else {
|
|
|
+ common_vendor.index.navigateTo({
|
|
|
+ url: `/pagesIndex/login/index`
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //输入框高度
|
|
|
+ heights(e) {
|
|
|
+ const that = this;
|
|
|
+ that.goBottom();
|
|
|
+ },
|
|
|
+ // 滚动到底部
|
|
|
+ async goBottom() {
|
|
|
+ const that = this;
|
|
|
+ that.scrollToView = "";
|
|
|
+ that.$nextTick(function() {
|
|
|
+ that.scrollToView = "msg123456789";
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 下拉刷新分页
|
|
|
+ getFresh(e) {
|
|
|
+ const that = this;
|
|
|
+ that.$set(that, `triggered`, true);
|
|
|
+ that.$set(that, `is_img`, false);
|
|
|
+ let msgList = that.msgList;
|
|
|
+ let limit = that.limit;
|
|
|
+ setTimeout(() => {
|
|
|
+ if (that.total > msgList.length) {
|
|
|
+ common_vendor.index.showLoading({
|
|
|
+ title: "加载中",
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+ let page = that.page + 1;
|
|
|
+ that.$set(that, `page`, page);
|
|
|
+ let skip = page * limit;
|
|
|
+ that.$set(that, `skip`, skip);
|
|
|
+ that.$set(that, `is_bottom`, false);
|
|
|
+ that.search();
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ } else {
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: `没有更多聊天记录了`,
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ }
|
|
|
+ that.triggered = false;
|
|
|
+ }, 1e3);
|
|
|
+ },
|
|
|
+ // 分页
|
|
|
+ toPage(e) {
|
|
|
+ const that = this;
|
|
|
+ let list = that.list;
|
|
|
+ let limit = that.limit;
|
|
|
+ if (that.total > list.length) {
|
|
|
+ common_vendor.index.showLoading({
|
|
|
+ title: "加载中",
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+ let page = that.page + 1;
|
|
|
+ that.$set(that, `page`, page);
|
|
|
+ let skip = page * limit;
|
|
|
+ that.$set(that, `skip`, skip);
|
|
|
+ that.search();
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ } else
|
|
|
+ that.$set(that, `is_bottom`, true);
|
|
|
+ },
|
|
|
+ // 清空列表
|
|
|
+ clearPage() {
|
|
|
+ const that = this;
|
|
|
+ that.$set(that, `msgList`, []);
|
|
|
+ that.$set(that, `skip`, 0);
|
|
|
+ that.$set(that, `limit`, 6);
|
|
|
+ that.$set(that, `page`, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+if (!Array) {
|
|
|
+ const _component_submit_1 = common_vendor.resolveComponent("submit_1");
|
|
|
+ _component_submit_1();
|
|
|
+}
|
|
|
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
+ return {
|
|
|
+ a: common_vendor.f($data.msgList, (item, index, i0) => {
|
|
|
+ return common_vendor.e({
|
|
|
+ a: item.time != ""
|
|
|
+ }, item.time != "" ? {
|
|
|
+ b: common_vendor.t(item.time)
|
|
|
+ } : {}, {
|
|
|
+ c: item.speaker != $data.user._id
|
|
|
+ }, item.speaker != $data.user._id ? common_vendor.e({
|
|
|
+ d: $data.config.logo_url && $data.config.logo_url.length > 0 ? $data.config.logo_url[0].url : "",
|
|
|
+ e: item.msg_type == "0"
|
|
|
+ }, item.msg_type == "0" ? {
|
|
|
+ f: common_vendor.t(item.content)
|
|
|
+ } : item.msg_type == "1" ? {
|
|
|
+ h: item.content,
|
|
|
+ i: common_vendor.o(($event) => $options.previewImg(item.content), index)
|
|
|
+ } : {}, {
|
|
|
+ g: item.msg_type == "1"
|
|
|
+ }) : item.speaker == $data.user._id ? common_vendor.e({
|
|
|
+ k: $data.user.logo && $data.user.logo.length > 0 ? $data.user.logo[0].url : "",
|
|
|
+ l: item.msg_type == "0"
|
|
|
+ }, item.msg_type == "0" ? {
|
|
|
+ m: common_vendor.t(item.content)
|
|
|
+ } : item.msg_type == "1" ? {
|
|
|
+ o: item.content,
|
|
|
+ p: common_vendor.o(($event) => $options.previewImg(item.content), index)
|
|
|
+ } : {}, {
|
|
|
+ n: item.msg_type == "1"
|
|
|
+ }) : {}, {
|
|
|
+ j: item.speaker == $data.user._id,
|
|
|
+ q: index,
|
|
|
+ r: "msg" + item._id
|
|
|
+ });
|
|
|
+ }),
|
|
|
+ b: $data.scrollToView,
|
|
|
+ c: $data.triggered,
|
|
|
+ d: common_vendor.o((...args) => $options.getFresh && $options.getFresh(...args)),
|
|
|
+ e: common_vendor.o($options.choseImg),
|
|
|
+ f: common_vendor.o($options.inputs),
|
|
|
+ g: common_vendor.o($options.heights)
|
|
|
+ };
|
|
|
+}
|
|
|
+const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-22cb3e28"], ["__file", "D:/project/赋强公证/notarization_applet/pagesHome/customer/index.vue"]]);
|
|
|
+wx.createPage(MiniProgramPage);
|