index.vue 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622
  1. <!-- FastAdmin在线客服插件不是开源产品,所有文字、图片、样式、风格等版权归在线客服作者所有,如有复制、仿冒、抄袭、盗用,FastAdmin和在线客服作者将追究法律责任 -->
  2. <template>
  3. <view>
  4. <shopro-navbar backIconColor="#333":backText="headTitle"></shopro-navbar>
  5. <view class="kefu_container">
  6. <view v-if="errorTips" class="error_tips">{{ errorTips }}</view>
  7. <view v-if="config.announcement && errorTips == ''" class="notice">
  8. <text>{{ config.announcement }}</text>
  9. <text class="u-iconfont uicon-close-circle-fill close_notice" style="color: #e0e0e0;font-size: 36rpx;" @tap="close_notice"></text>
  10. </view>
  11. <!--留言板 -->
  12. <view v-if="showLeaveMessage" class="leave_message">
  13. <form>
  14. <view class="form-group">
  15. <label for="c-name" class="control-label">
  16. <view class="label-title">姓名</view>
  17. <input
  18. type="text"
  19. @input="leave_message"
  20. name="name"
  21. v-model="leaveMessage.name"
  22. class="form-control"
  23. id="c-name"
  24. placeholder-style="color:#B1B3C7"
  25. placeholder="请输入您的姓名"
  26. />
  27. </label>
  28. </view>
  29. <view class="form-group">
  30. <label for="c-contact" class="control-label"><view class="label-title">联系方式</view></label>
  31. <input
  32. type="text"
  33. @input="leave_message"
  34. name="contact"
  35. v-model="leaveMessage.contact"
  36. class="form-control"
  37. id="c-contact"
  38. placeholder-style="color:#B1B3C7"
  39. placeholder="请输入手机/QQ/微信号"
  40. />
  41. </view>
  42. <view class="form-group">
  43. <label for="c-message" class="control-label"><view class="label-title">留言内容</view></label>
  44. <textarea
  45. rows="5"
  46. @input="leave_message"
  47. name="message"
  48. v-model="leaveMessage.message"
  49. class="form-control"
  50. id="c-message"
  51. style="height: 240rpx;"
  52. placeholder-style="color:#B1B3C7"
  53. placeholder="遇到的问题、所需服务、产品等,我们将尽快与您取得联系"
  54. ></textarea>
  55. </view>
  56. <button @tap="post_leave_message" class="leave_success u-reset-button">确认留言</button>
  57. </form>
  58. </view>
  59. <!-- 留言板end -->
  60. <!-- 主界面 -->
  61. <!-- #ifdef H5 -->
  62. <view class="content_wrapper" v-if="!showLeaveMessage" :style="{ height: 'calc(100vh - ' + writeBottom + 'px)' }">
  63. <!-- #endif -->
  64. <!-- #ifndef H5 -->
  65. <view class="content_wrapper" v-if="!showLeaveMessage" :style="{ height: 'calc(100vh - ' + writeBottom + 'px)' }">
  66. <!-- #endif -->
  67. <view :style="{ height: 'calc(100% - ' + wrapperHeight + 'px)' }" class="chat_wrapper">
  68. <!-- 遮罩 -->
  69. <view class="mask" @tap="hideMask" v-if="showTool || selectModel"></view>
  70. <scroll-view
  71. @scrolltoupper="wrapper_scrolltoupper"
  72. @tap="tap_scroll_view"
  73. :scroll-y="true"
  74. :scroll-with-animation="true"
  75. :scroll-into-view="scrollIntoFooter"
  76. >
  77. <block v-for="(item, index) in messageList" :key="item.datetime">
  78. <view class="status">
  79. <text>{{ item.datetime }}</text>
  80. </view>
  81. <block v-for="message in item.data" :key="message.id">
  82. <view v-if="message.message_type == 3" class="status">
  83. <text>{{ message.message }}</text>
  84. </view>
  85. <view class="message-item u-flex u-row-center u-col-center" :class="message.sender == 'me' ? 'message__right' : 'message__left'">
  86. <view class="head-img"><image class="head-img" v-if="message.sender == 'you'" :src="$IMG_URL + '/imgs/chat/sys_head.png'" mode=""></image></view>
  87. <view v-if="message.message_type != 3" class="bubble" :class="message.sender == 'me' ? 'me' : 'you'">
  88. <!-- 除了商品/订单卡片和图片,其他的都使用富文本 -->
  89. <u-parse
  90. @imgtap="message_img_preview"
  91. :tagStyle="{ img: 'width:50rpx;height:50rpx;'}"
  92. v-if="message.message_type == 0"
  93. :html="message.message"
  94. ></u-parse>
  95. <u-parse
  96. v-if="message.message_type == 2"
  97. :html="'<a target=_blank href=' + message.message + '>' + message.message + '</a>'"
  98. ></u-parse>
  99. <image @tap="preview_img(message.message)" v-if="message.message_type == 1" :src="message.message" mode="widthFix"></image>
  100. <view @tap="goDetail(message.message)" v-if="message.message_type == 4 || message.message_type == 5" class="project_item" style="margin: 0;">
  101. <image :src="message.message.logo"></image>
  102. <view class="project_item_body">
  103. <view>
  104. <view class="project_item_title u-ellipsis-2">{{ message.message.subject }}</view>
  105. <view v-if="message.message.note" style="width: 280rpx;margin-right: -20rpx;" class="project_item_note one-t">{{message.message.note}}</view>
  106. </view>
  107. <view class="project_item_price">
  108. <text class="price" v-if="message.message.price">{{ message.message.price }}</text>
  109. <!-- <text class="unit" v-if="message.message.number">x{{message.message.number}}</text> -->
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. <view class="head-img"><image class="head-img" v-if="message.sender == 'me'" :src="userInfo.avatar" mode=""></image></view>
  115. </view>
  116. </block>
  117. </block>
  118. <view id="wrapper_footer" style="height: 300rpx;"></view>
  119. </scroll-view>
  120. </view>
  121. <!-- 消息输入 -->
  122. <view class="write" :style="{ bottom: writeBottom + 'px' }">
  123. <label class="widget_textarea" v-if="!selectModel">
  124. <textarea
  125. :show-confirm-bar="false"
  126. :fixed="true"
  127. :focus="kefuMessageFocus"
  128. :auto-height="true"
  129. maxlength="-1"
  130. @blur="kefu_message_blur"
  131. @input="textarea_input"
  132. :cursor-spacing="14"
  133. @focus="textarea_focus"
  134. placeholder="请输入你要咨询的问题"
  135. placeholder-style="color:#999"
  136. v-model="kefuMessage"
  137. class="kefu_message"
  138. ></textarea>
  139. </label>
  140. <view class="write_right" :style="{ flex: showSendButton ? 3 : 2 }">
  141. <text
  142. v-if="config.toolbar && config.toolbar.expression"
  143. :style="{ background: 'url(' + config.toolbar.expression.icon_image + ') no-repeat', 'background-size': '100% 100%' }"
  144. class="toolbar_icon smiley"
  145. @tap="show_tool('smiley')"
  146. ></text>
  147. <button class="send_btn" @tap="send_message(kefuMessage, 0)" hover-class="send_btn_hover" v-if="showSendButton">发送</button>
  148. <text
  149. class="toolbar_icon attach"
  150. :style="{ background: 'url(' + attachBackground + ') no-repeat', 'background-size': '100% 100%' }"
  151. @tap="show_tool('more')"
  152. v-if="!showSendButton && attachBackground"
  153. ></text>
  154. </view>
  155. </view>
  156. <view v-if="showTool" class="footer_div">
  157. <!-- 表情 -->
  158. <block v-if="showTool == 'smiley'" v-for="(item, index) in expressionData" :key="item.src">
  159. <image :src="item.src" @tap="select_expression(item.title)"></image>
  160. </block>
  161. <!-- 表情end -->
  162. <!-- 更多 -->
  163. <view v-if="showTool == 'more'" class="toolbar">
  164. <view @tap="show_select_model('order')" v-if="config.toolbar && config.toolbar.order" class="toolbar_item">
  165. <image class="tool-img" :src="config.toolbar.order.icon_image"></image>
  166. <view>{{ config.toolbar.order.title }}</view>
  167. </view>
  168. <view @tap="show_select_model('goods')" v-if="config.toolbar && config.toolbar.goods" class="toolbar_item">
  169. <image class="tool-img" :src="config.toolbar.goods.icon_image"></image>
  170. <view>{{ config.toolbar.goods.title }}</view>
  171. </view>
  172. <view @tap="upload_file" v-if="config.toolbar && config.toolbar.file" class="toolbar_item">
  173. <image class="tool-img" :src="config.toolbar.file.icon_image"></image>
  174. <view>{{ config.toolbar.file.title }}</view>
  175. </view>
  176. </view>
  177. <!-- 更多end -->
  178. </view>
  179. </view>
  180. <!-- 订单和商品选择 -->
  181. <view v-if="selectModel" class="select_model">
  182. <view class="u-flex u-row-between u-col-center select_model--head">
  183. <view class="select-title-box">
  184. <view class="title-text">
  185. {{selectModelType[selectModel]}}
  186. </view>
  187. <text class="title-line"></text>
  188. </view>
  189. <view @tap="show_select_model(false)" class="close_select">
  190. <text class="u-iconfont uicon-close-circle-fill" style="#e0e0e0;font-size: 36rpx;"></text>
  191. </view>
  192. </view>
  193. <view class="project_list">
  194. <radio-group style="width: 100%;" v-if="selectModelData.length > 0" @change="select_done">
  195. <label v-for="(item, index) in selectModelData" :key="item.id" class="project_item">
  196. <image :src="item.logo"></image>
  197. <view class="project_item_body">
  198. <view>
  199. <view class="project_item_title u-ellipsis-2">{{ item.subject }}</view>
  200. <view v-if="item.note" style="width: 470rpx;" class="project_item_note u-ellipsis-1">{{ item.note }}</view>
  201. </view>
  202. <view class="project_item_price">
  203. <text class="price" v-if="item.price">{{ item.price }}</text>
  204. <!-- <text class="unit" v-if="item.number">x{{ item.number }}</text> -->
  205. </view>
  206. </view>
  207. <radio style="opacity: 0;width: 0;height: 0;" :value="index.toString()" :checked="false" hide ></radio>
  208. </label>
  209. </radio-group>
  210. <view class="select_model_no_data" v-if="selectModelData.length <= 0"><text>没有更多记录了...</text></view>
  211. </view>
  212. </view>
  213. </view>
  214. </view>
  215. </template>
  216. <script>
  217. import Config from './config.js'; // 本地配置数据
  218. let token = uni.getStorageSync('token'); // 用户身份标识
  219. let fixedCsr = ''; // 指定客服
  220. let innerAudioContext = null;
  221. import { mapMutations, mapActions, mapState,mapGetters } from 'vuex';
  222. import Auth from '@/shopro/permission/index.js';
  223. export default {
  224. components: {},
  225. data() {
  226. return {
  227. headTitle: '客服',
  228. leaveMessage: {
  229. name: '',
  230. contact: '',
  231. message: ''
  232. },
  233. attachBackground: '',
  234. showSendButton: false,
  235. showTool: false,
  236. showLeaveMessage: false,
  237. expressionData: [],
  238. scrollIntoFooter: '',
  239. config: [],
  240. tokenList: [],
  241. kefuMessage: '',
  242. wrapperHeight: 46,
  243. ws: {
  244. SocketTask: null,
  245. Timer: null, // 计时器
  246. ErrorMsg: [], // 发送失败的消息
  247. MaxRetryCount: 3, // 最大重连次数
  248. CurrentRetryCount: 0,
  249. socketOpen: false,
  250. pageHideCloseWs: true,
  251. unloadCloseWs: false // ws关闭状态码兼容性不好,手动标记页面卸载关闭ws链接
  252. },
  253. csr: '', // 当前用户的客服代表ID
  254. sessionId: 0, // 会话ID
  255. sessionUser: '', // 带身份标识的用户ID
  256. kefuMessageFocus: false,
  257. messageList: [],
  258. chatRecordPage: 1,
  259. errorTips: '链接中...',
  260. selectModel: false,
  261. selectModelType: {
  262. goods: '发送商品',
  263. order: '发送订单'
  264. },
  265. selectModelData: [],
  266. writeBottom: 0
  267. };
  268. },
  269. computed: {
  270. ...mapGetters(['userInfo']),
  271. },
  272. props: {
  273. options: null
  274. },
  275. created() {
  276. fixedCsr = this.options?.fixed_csr ? this.options?.fixed_csr : fixedCsr;
  277. this.load();
  278. },
  279. onShow() {
  280. if (!this.ws.pageHideCloseWs) {
  281. this.ws.pageHideCloseWs = true;
  282. }
  283. // #ifdef MP-WEIXIN
  284. this.load();
  285. // #endif
  286. },
  287. onHide() {
  288. // #ifdef MP-WEIXIN
  289. if (this.ws.SocketTask && this.ws.socketOpen && this.ws.pageHideCloseWs) {
  290. console.log('微信小程序页面hide主动关闭链接');
  291. uni.closeSocket();
  292. }
  293. // #endif
  294. uni.hideKeyboard();
  295. },
  296. beforeDestroy() {
  297. if (this.ws.SocketTask && this.ws.socketOpen) {
  298. console.log('页面卸载主动关闭链接');
  299. this.ws.unloadCloseWs = true;
  300. uni.closeSocket();
  301. }
  302. },
  303. methods: {
  304. // 路由跳转
  305. jump(path, parmas) {
  306. this.$Router.push({
  307. path: path,
  308. query: parmas
  309. });
  310. },
  311. // 跳转详情
  312. goDetail(msg) {
  313. msg.number ? this.jump('/pages/order/detail', { id: msg.id }) : this.jump('/pages/goods/detail', { id: msg.id });
  314. },
  315. // 关闭遮罩
  316. hideMask() {
  317. if (this.showTool) {
  318. this.showTool = false;
  319. }
  320. if (this.selectModel) {
  321. this.selectModel = false;
  322. }
  323. this.writeBottom = 0;
  324. },
  325. load: function() {
  326. var that = this;
  327. var kefu_tourists_token = '';
  328. // 初始化请求
  329. try {
  330. var kefu_tourists_token = uni.getStorageSync('kefu_tourists_token');
  331. if (!kefu_tourists_token) {
  332. kefu_tourists_token = '';
  333. }
  334. } catch (e) {
  335. console.error(e);
  336. }
  337. uni.request({
  338. url: that.build_url('initialize'),
  339. data: {
  340. token: uni.getStorageSync('token'),
  341. kefu_tourists_token: kefu_tourists_token,
  342. fixed_csr: fixedCsr
  343. },
  344. success: res => {
  345. if (res.data.code == 1) {
  346. // 保存游客token
  347. if (res.data.data.token_list.kefu_tourists_token) {
  348. try {
  349. uni.setStorageSync('kefu_tourists_token', res.data.data.token_list.kefu_tourists_token);
  350. } catch (e) {
  351. console.error(e);
  352. }
  353. }
  354. // 来信提示音初始化
  355. innerAudioContext = uni.createInnerAudioContext();
  356. innerAudioContext.src = that.build_url('message_prompt');
  357. // 公告
  358. var kefu_notice = '';
  359. try {
  360. kefu_notice = uni.getStorageSync('kefu_notice');
  361. } catch (e) {
  362. console.log(e);
  363. }
  364. if (kefu_notice == res.data.data.config.announcement) {
  365. res.data.data.config.announcement = '';
  366. }
  367. // 配置
  368. that.config = res.data.data.config;
  369. that.tokenList = res.data.data.token_list;
  370. // 新消息提示
  371. if (res.data.data.new_msg) {
  372. that.new_message_prompt();
  373. }
  374. // 初始化表情
  375. var protocol = Config.https_switch ? 'https://' : 'http://';
  376. var expression = {};
  377. for (let i in Config.expression) {
  378. expression[i] = {
  379. src: protocol + Config.baseURL + '/assets/addons/kefu/img' + Config.expression[i].src,
  380. title: Config.expression[i].title
  381. };
  382. }
  383. that.expressionData = expression;
  384. // 杂项资源
  385. that.attachBackground = that.build_url('res', '/img/more.png');
  386. // 链接ws
  387. that.connect_socket();
  388. } else {
  389. // uni.showModal({
  390. // content: res.data.msg,
  391. // showCancel: false,
  392. // success: res => {
  393. // if (res.confirm) {
  394. // uni.navigateBack({
  395. // delta: 1
  396. // });
  397. // }
  398. // }
  399. // });
  400. }
  401. },
  402. fail: res => {
  403. uni.showModal({
  404. title: '温馨提示',
  405. content: '在线客服初始化失败,请重试~',
  406. showCancel: false
  407. });
  408. that.errorTips = '初始化失败';
  409. }
  410. });
  411. },
  412. switch_show_tool: function(value) {
  413. if (!value) {
  414. this.showTool = false;
  415. this.writeBottom = 0;
  416. } else {
  417. this.showTool = value;
  418. this.writeBottom = 170;
  419. this.scroll_into_footer(200);
  420. }
  421. },
  422. close_notice: function() {
  423. uni.setStorageSync('kefu_notice', this.config.announcement);
  424. this.config.announcement = '';
  425. },
  426. select_done: function(e) {
  427. let index = e.detail.value;
  428. var message = '';
  429. for (let i in this.selectModelData[index]) {
  430. message += i + '=' + this.selectModelData[index][i] + '#';
  431. }
  432. this.send_message(message, this.selectModel == 'goods' ? 4 : 5);
  433. this.selectModel = false;
  434. this.switch_show_tool(false);
  435. },
  436. show_select_model: function(name) {
  437. this.selectModel = name;
  438. if (!name) {
  439. return;
  440. }
  441. uni.showLoading({
  442. title: '请稍后...'
  443. });
  444. var data_api_url = this.config.toolbar[name].data_api;
  445. var reg = new RegExp('(^https?:\/\/)', 'i');
  446. if (data_api_url.search(reg) === -1) {
  447. data_api_url = (Config.https_switch ? 'https://' : 'http://') + Config.baseURL + data_api_url;
  448. }
  449. this.selectModelData = [];
  450. uni.request({
  451. url: data_api_url,
  452. data: {
  453. token: uni.getStorageSync('token')
  454. },
  455. success: res => {
  456. if (res.data.code == 1) {
  457. this.selectModelData = res.data.data.data;
  458. } else {
  459. uni.showModal({
  460. title: '温馨提示',
  461. content: res.data.msg,
  462. showCancel: false
  463. });
  464. }
  465. },
  466. fail: res => {
  467. uni.showModal({
  468. title: '温馨提示',
  469. content: '网络请求失败,请重试!',
  470. showCancel: false
  471. });
  472. },
  473. complete: res => {
  474. uni.hideLoading();
  475. }
  476. });
  477. },
  478. parseUrl: function(data) {
  479. var reg = new RegExp('(https?:\/\/)([0-9a-z.]+)([\?0-9a-z&=]+)?(#[0-9-a-z]+)?', 'g');
  480. return data.replace(reg, '<a target="_blank" title="$&" class="link" href="$&">$&</a>');
  481. },
  482. message_img_preview: function(e) {
  483. this.ws.pageHideCloseWs = false; // 页面hide不关闭链接
  484. },
  485. preview_img: function(src) {
  486. this.ws.pageHideCloseWs = false; // 页面hide不关闭链接
  487. uni.previewImage({
  488. current: src,
  489. urls: [src]
  490. });
  491. },
  492. async upload_file() {
  493. let authState = await new Auth('writePhotosAlbum').check();
  494. if (authState) {
  495. // #ifdef APP-VUE
  496. // #endif
  497. var that = this;
  498. that.ws.pageHideCloseWs = false; // 页面hide不关闭链接
  499. uni.chooseImage({
  500. success: res => {
  501. const tempFilePaths = res.tempFilePaths;
  502. uni.showLoading({
  503. title: '正在上传...'
  504. });
  505. const uploadTask = uni.uploadFile({
  506. url: that.build_url('upload'),
  507. // #ifdef APP-PLUS || H5
  508. file: res.tempFiles[0],
  509. // #endif
  510. filePath: tempFilePaths[0],
  511. name: 'file',
  512. formData: {
  513. token: uni.getStorageSync('token')
  514. },
  515. success: res => {
  516. uni.hideLoading();
  517. that.ws.pageHideCloseWs = true;
  518. res = JSON.parse(res.data);
  519. if (res.code == 1) {
  520. that.send_message(res.data, 1);
  521. that.switch_show_tool(false);
  522. that.kefuMessageFocus = true;
  523. } else {
  524. uni.showModal({
  525. title: '温馨提示',
  526. content: res.msg,
  527. showCancel: false
  528. });
  529. }
  530. },
  531. complete: res => {
  532. uni.hideLoading();
  533. }
  534. });
  535. // #ifndef APP-PLUS
  536. uploadTask.onProgressUpdate(res => {
  537. uni.showLoading({
  538. title: res.progress + '%'
  539. });
  540. });
  541. // #endif
  542. }
  543. });
  544. }
  545. },
  546. connect_socket: function() {
  547. var that = this;
  548. if (this.ws.SocketTask && this.ws.socketOpen) {
  549. console.log('无需链接');
  550. return;
  551. }
  552. // 开始链接
  553. that.ws.SocketTask = uni.connectSocket({
  554. url: this.build_url('ws'),
  555. header: {
  556. 'content-type': 'application/json'
  557. },
  558. complete: res => {}
  559. });
  560. // 链接打开
  561. uni.onSocketOpen(function(res) {
  562. console.log('链接已打开');
  563. that.ws.socketOpen = true;
  564. that.ws.CurrentRetryCount = 0;
  565. // 重新发送所有出错的消息
  566. for (let i in that.ws.ErrorMsg) {
  567. that.ws_send(that.ws.ErrorMsg[i]);
  568. }
  569. that.ws.ErrorMsg = [];
  570. that.errorTips = '';
  571. if (that.ws.Timer != null) {
  572. clearInterval(that.ws.Timer);
  573. }
  574. that.ws.Timer = setInterval(that.ws_send, 28000); //定时发送心跳
  575. });
  576. // 收到消息
  577. uni.onSocketMessage(function(res) {
  578. let msg = JSON.parse(res.data);
  579. that.domsg(msg);
  580. });
  581. // 出错
  582. uni.onSocketError(function(res) {
  583. that.ws.socketOpen = false;
  584. that.errorTips = 'WebSocket 发生错误!';
  585. console.log('链接出错', res);
  586. });
  587. // 链接关闭
  588. uni.onSocketClose(function(res) {
  589. // 工具上是1000,真机上测试是10000
  590. console.log('链接已关闭', res);
  591. that.ws.socketOpen = false;
  592. if (res.code == 1000 || res.code == 10000 || that.ws.unloadCloseWs) {
  593. return;
  594. }
  595. if (that.ws.Timer != null) {
  596. clearInterval(that.ws.Timer);
  597. }
  598. that.ws.socketOpen = false;
  599. if (that.errorTips.indexOf('重连') === -1) {
  600. that.errorTips = '网络链接已断开!';
  601. }
  602. if (that.ws.MaxRetryCount) {
  603. that.ws.Timer = setInterval(that.retry_websocket, 3000); //每3秒重新连接一次
  604. }
  605. });
  606. },
  607. // 重连ws
  608. retry_websocket: function() {
  609. var that = this;
  610. if (that.ws.CurrentRetryCount < that.ws.MaxRetryCount) {
  611. that.ws.CurrentRetryCount++;
  612. that.connect_socket();
  613. that.errorTips = '重连WebSocket第' + that.ws.CurrentRetryCount + '次';
  614. } else {
  615. if (that.ws.Timer != null) {
  616. clearInterval(that.ws.Timer);
  617. }
  618. that.errorTips = '每隔10秒将再次尝试重连 WebSocket';
  619. that.ws.Timer = setInterval(that.connect_socket, 10000); //每10秒重新连接一次
  620. }
  621. },
  622. // 发送ws消息
  623. ws_send: function(message) {
  624. var that = this;
  625. if (!message) {
  626. message = {
  627. c: 'Message',
  628. a: 'ping'
  629. };
  630. }
  631. if (that.ws.SocketTask && that.ws.socketOpen) {
  632. uni.sendSocketMessage({
  633. data: JSON.stringify(message)
  634. });
  635. } else {
  636. console.log('消息发送出错', message, that.ws.SocketTask, that.ws.socketOpen);
  637. that.ws.ErrorMsg.push(message);
  638. }
  639. },
  640. send_message: function(message, message_type) {
  641. var that = this;
  642. if (message == '') {
  643. uni.showToast({
  644. title: '请输入消息内容',
  645. icon: 'none'
  646. });
  647. return;
  648. }
  649. // 检查 websocket 是否连接
  650. if (!that.ws.SocketTask || !that.ws.socketOpen) {
  651. uni.showToast({
  652. title: '网络链接异常,请稍后重试~',
  653. icon: 'none'
  654. });
  655. return;
  656. }
  657. if (!that.sessionId) {
  658. uni.showToast({
  659. title: '请选择一个会话~',
  660. icon: 'none'
  661. });
  662. return;
  663. }
  664. if (message_type == 0) {
  665. // 处理链接
  666. message = that.parseUrl(message);
  667. // 处理表情
  668. var reg = /\[(.+?)\]/g; // [] 中括号
  669. var reg_match = message.match(reg);
  670. if (reg_match) {
  671. for (let i in reg_match) {
  672. var emoji_item = that.find_emoji(reg_match[i]);
  673. message = message.replace(emoji_item.title, that.build_chat_img(emoji_item.src, '', 'emoji'));
  674. }
  675. }
  676. }
  677. var load_message = {
  678. c: 'Message',
  679. a: 'sendMessage',
  680. data: {
  681. message: message_type == 1 ? message.url : message,
  682. message_type: message_type,
  683. session_id: that.sessionId,
  684. modulename: 'index'
  685. }
  686. };
  687. that.ws_send(load_message);
  688. let message_data = that.messageList[that.messageList.length - 1].data;
  689. let message_id = message_data[message_data.length - 1].id + 1;
  690. var data = {
  691. id: message_id,
  692. sender: 'me',
  693. message: message_type == 1 ? message.fullurl : message,
  694. message_type: message_type
  695. };
  696. var messageListIndex = that.messageList.length - 1;
  697. if (that.messageList[messageListIndex] && that.messageList[messageListIndex].datetime == '刚刚') {
  698. that.messageList[messageListIndex].data = that.messageList[messageListIndex].data.concat(that.format_message([data]));
  699. } else {
  700. that.messageList = that.messageList.concat({
  701. datetime: '刚刚',
  702. data: that.format_message([data])
  703. });
  704. }
  705. that.kefuMessage = '';
  706. that.kefu_message_change();
  707. that.scroll_into_footer(300);
  708. that.wrapperHeight = 46;
  709. },
  710. find_emoji: function(emoji_title) {
  711. for (let i in this.expressionData) {
  712. if (this.expressionData[i].title == emoji_title) {
  713. return this.expressionData[i];
  714. }
  715. }
  716. return false;
  717. },
  718. build_chat_img: function(filename, facename, class_name = 'emoji') {
  719. var protocol = Config.https_switch ? 'https://' : 'http://';
  720. if (class_name == 'emoji') {
  721. return '<img class="emoji" src="' + filename + '" />';
  722. } else {
  723. return '<img class="' + class_name + '" src="' + filename + '" />';
  724. }
  725. },
  726. // 记录用户填写的留言数据,方便后续清空输入等处理
  727. leave_message: function(e) {
  728. if (e.currentTarget.id == 'c-name') {
  729. this.leaveMessage.name = e.detail.value;
  730. } else if (e.currentTarget.id == 'c-contact') {
  731. this.leaveMessage.contact = e.detail.value;
  732. } else if (e.currentTarget.id == 'c-message') {
  733. this.leaveMessage.message = e.detail.value;
  734. }
  735. },
  736. post_leave_message: function() {
  737. if (!this.leaveMessage.contact) {
  738. uni.showToast({
  739. title: '联系方式不能为空哦~',
  740. icon: 'none'
  741. });
  742. return false;
  743. }
  744. var leave_message = {
  745. c: 'Message',
  746. a: 'leaveMessage',
  747. data: this.leaveMessage
  748. };
  749. this.ws_send(leave_message);
  750. },
  751. domsg: function(msg) {
  752. var that = this;
  753. if (msg.msgtype == 'initialize') {
  754. if (msg.data.new_msg) {
  755. that.new_message_prompt();
  756. }
  757. // 分配/获取客服->获取聊天记录
  758. var user_initialize = {
  759. c: 'Message',
  760. a: 'userInitialize',
  761. data: {
  762. fixed_csr: that.fixedCsr
  763. }
  764. };
  765. that.ws_send(user_initialize);
  766. } else if (msg.msgtype == 'user_initialize') {
  767. // 用户客服分配结束
  768. if (msg.code == 1) {
  769. if (msg.data.session.user_tourists) {
  770. that.send_message = function() {
  771. uni.showToast({
  772. title: '为保护您的隐私请,请登录后发送消息~',
  773. icon: 'none'
  774. });
  775. };
  776. }
  777. that.csr = msg.data.session.csr;
  778. that.sessionId = msg.data.session.id;
  779. that.showLeaveMessage = false;
  780. that.headTitle = '客服 ' + msg.data.session.nickname + ' 为您服务';
  781. } else if (msg.code == 302) {
  782. if (!that.csr) {
  783. // 打开留言板
  784. that.csr = 'none';
  785. that.showLeaveMessage = true;
  786. that.headTitle = '当前无客服在线哦~';
  787. } else {
  788. uni.showToast({
  789. title: '当前客服暂时离开,您可以直接发送离线消息~',
  790. icon: 'none'
  791. });
  792. }
  793. }
  794. } else if (msg.msgtype == 'show_msg') {
  795. uni.showToast({
  796. title: msg.msg,
  797. icon: 'none'
  798. });
  799. } else if (msg.msgtype == 'leave_message') {
  800. uni.showToast({
  801. title: msg.msg,
  802. icon: 'none'
  803. });
  804. this.leaveMessage = {
  805. name: '',
  806. contact: '',
  807. message: ''
  808. };
  809. } else if (msg.msgtype == 'clear') {
  810. if (msg.msg) {
  811. uni.showToast({
  812. title: msg.msg,
  813. icon: 'none'
  814. });
  815. }
  816. var clear = {
  817. c: 'Message',
  818. a: 'clear'
  819. };
  820. that.ws_send(clear);
  821. that.retry_webSocket = function() {
  822. clearInterval(that.ws.Timer);
  823. };
  824. } else if (msg.msgtype == 'offline') {
  825. if (msg.user_id == that.csr) {
  826. this.errorTips = '客服离线~';
  827. }
  828. } else if (msg.msgtype == 'online') {
  829. // 来自 admin 的用户上线
  830. if (msg.modulename == 'admin') {
  831. if (msg.user_id == that.csr) {
  832. this.errorTips = '';
  833. } else if (that.csr == 'none') {
  834. // 重新为用户分配客服代表
  835. var user_initialize = {
  836. c: 'Message',
  837. a: 'userInitialize'
  838. };
  839. that.ws_send(user_initialize);
  840. }
  841. }
  842. } else if (msg.msgtype == 'csr_change_status') {
  843. if (that.csr == msg.data.csr) {
  844. if (msg.data.csr_status != 3) {
  845. that.errorTips = '客服' + that.get_csr_status(msg.data.csr_status) + '~';
  846. } else {
  847. that.errorTips = '';
  848. }
  849. }
  850. } else if (msg.msgtype == 'transfer_done') {
  851. that.csr = msg.data.csr;
  852. that.headTitle = '客服 ' + msg.data.nickname + ' 为您服务';
  853. } else if (msg.msgtype == 'new_message') {
  854. that.new_message_prompt();
  855. if (msg.data.session_id == that.sessionId) {
  856. var messageListIndex = that.messageList.length - 1;
  857. if (that.messageList[messageListIndex].datetime == '刚刚') {
  858. that.messageList[messageListIndex].data = that.messageList[messageListIndex].data.concat(that.format_message([msg.data]));
  859. } else {
  860. that.messageList = that.messageList.concat({
  861. datetime: '刚刚',
  862. data: that.format_message([msg.data])
  863. });
  864. }
  865. var load_message = {
  866. c: 'Message',
  867. a: 'readMessage',
  868. data: {
  869. record_id: msg.data.record_id
  870. }
  871. };
  872. that.ws_send(load_message);
  873. that.scroll_into_footer(800);
  874. }
  875. } else if (msg.msgtype == 'chat_record') {
  876. // 下一页
  877. that.chatRecordPage = msg.data.next_page;
  878. for (let i in msg.data.chat_record) {
  879. msg.data.chat_record[i].data = that.format_message(msg.data.chat_record[i].data);
  880. }
  881. if (msg.data.page == 1) {
  882. that.messageList = msg.data.chat_record;
  883. // 滑动到最后一条消息
  884. that.scroll_into_footer(800);
  885. } else {
  886. for (let i = msg.data.chat_record.length - 1; i >= 0; i--) {
  887. msg.data.chat_record[i].data.reverse();
  888. that.messageList.unshift(msg.data.chat_record[i]);
  889. }
  890. }
  891. }
  892. },
  893. get_csr_status: function(status) {
  894. switch (parseInt(status)) {
  895. case 0:
  896. status = '离线';
  897. break;
  898. case 1:
  899. status = '繁忙';
  900. break;
  901. case 2:
  902. status = '离开';
  903. break;
  904. case 3:
  905. status = '在线';
  906. break;
  907. case 99:
  908. status = '断链';
  909. break;
  910. default:
  911. status = '未知';
  912. break;
  913. }
  914. return status;
  915. },
  916. build_url: function(type = 'ws', res_path) {
  917. var that = this;
  918. var protocol = Config.https_switch ? 'https://' : 'http://';
  919. switch (type) {
  920. //websocket聊天
  921. case 'ws':
  922. let tokenStr = '&token=' + (that.tokenList.kefu_token ? that.tokenList.kefu_token : '');
  923. let kefu_user = '&kefu_tourists_token=' + (that.tokenList.kefu_tourists_token ? that.tokenList.kefu_tourists_token : '');
  924. let baseUrl = Config.baseURL.split(':')[0];
  925. protocol = parseInt(that.config.wss_switch) == 1 ? 'wss://' : 'ws://';
  926. return (protocol + baseUrl + ':' + that.config.websocket_port + '/?modulename=index' + tokenStr + kefu_user).replace(/\|/g, '~');
  927. break;
  928. //初始化
  929. case 'initialize':
  930. return protocol + Config.baseURL + '/addons/kefu/index/initialize?modulename=index';
  931. break;
  932. //上传图片
  933. case 'upload':
  934. return protocol + Config.baseURL + '/addons/shopro/index/upload';
  935. break;
  936. //发送消息
  937. case 'message_prompt':
  938. if (that.config.__CDN__) {
  939. return that.config.__CDN__ + '/assets/addons/kefu/audio/message_prompt.wav';
  940. }
  941. return protocol + Config.baseURL + '/assets/addons/kefu/audio/message_prompt.wav';
  942. break;
  943. case 'res':
  944. if (that.config.__CDN__) {
  945. return that.config.__CDN__ + '/assets/addons/kefu' + res_path;
  946. }
  947. return protocol + Config.baseURL + '/assets/addons/kefu' + res_path;
  948. break;
  949. }
  950. },
  951. new_message_prompt: function() {
  952. if (innerAudioContext) {
  953. innerAudioContext.play();
  954. setTimeout(function() {
  955. innerAudioContext.stop();
  956. }, 1000);
  957. } else {
  958. console.error('来信提示音播放失败!');
  959. }
  960. },
  961. scroll_into_footer: function(timeout = 0) {
  962. var that = this;
  963. setTimeout(function() {
  964. that.scrollIntoFooter = 'wrapper_footer';
  965. }, timeout);
  966. that.scrollIntoFooter = '';
  967. },
  968. wrapper_scrolltoupper: function() {
  969. if (!this.sessionId || this.chatRecordPage == 'done') {
  970. return;
  971. }
  972. // 加载历史聊天记录
  973. var load_message = {
  974. c: 'Message',
  975. a: 'chatRecord',
  976. data: {
  977. session_id: this.sessionId,
  978. page: this.chatRecordPage
  979. }
  980. };
  981. this.ws_send(load_message);
  982. },
  983. tap_scroll_view: function() {
  984. this.switch_show_tool(false);
  985. },
  986. show_tool: function(name = 'smiley') {
  987. if (this.showTool == name) {
  988. this.switch_show_tool(false);
  989. } else {
  990. this.switch_show_tool(name);
  991. }
  992. if (this.showTool) {
  993. this.scroll_into_footer();
  994. }
  995. },
  996. // 输入框聚焦
  997. textarea_focus: function(e) {
  998. var that = this;
  999. this.showTool = false;
  1000. // that.writeBottom = e.detail.height ? e.detail.height : 0;
  1001. },
  1002. // 输入框输入
  1003. textarea_input: function(e) {
  1004. // this.kefuMessage = e.detail.value;
  1005. this.kefu_message_change();
  1006. },
  1007. // 显示/隐藏发送按钮-调整消息记录框高度
  1008. kefu_message_change: function() {
  1009. this.showSendButton = this.kefuMessage == '' ? false : true;
  1010. let write = uni
  1011. .createSelectorQuery()
  1012. .in(this)
  1013. .select('.write');
  1014. write
  1015. .fields(
  1016. {
  1017. size: true
  1018. },
  1019. data => {
  1020. if (data.height != this.wrapperHeight) {
  1021. this.wrapperHeight = data.height;
  1022. }
  1023. }
  1024. )
  1025. .exec();
  1026. },
  1027. // 消息框焦点
  1028. kefu_message_blur: function() {
  1029. this.kefuMessageFocus = false;
  1030. if (!this.showTool) {
  1031. this.writeBottom = 0;
  1032. }
  1033. },
  1034. select_expression: function(title) {
  1035. this.kefuMessage = this.kefuMessage + title;
  1036. this.kefu_message_change();
  1037. },
  1038. format_message: function(message) {
  1039. for (let i in message) {
  1040. if (message[i].message_type == 4 || message[i].message_type == 5) {
  1041. var message_arr = message[i].message.split('#');
  1042. var message_obj = {};
  1043. for (let y in message_arr) {
  1044. let message_temp = message_arr[y].split('=');
  1045. if (typeof message_temp[1] != 'undefined') {
  1046. message_obj[message_temp[0]] = message_temp[1];
  1047. }
  1048. }
  1049. message[i].message = message_obj;
  1050. }
  1051. }
  1052. return message;
  1053. }
  1054. }
  1055. };
  1056. </script>
  1057. <style lang="scss">
  1058. * {
  1059. padding: 0;
  1060. margin: 0;
  1061. }
  1062. page {
  1063. overflow: hidden;
  1064. }
  1065. .kefu_container {
  1066. height: calc(100vh - var(--window-top));
  1067. height: 100%;
  1068. overflow: hidden;
  1069. background-color: #f8fbfb;
  1070. }
  1071. .error_tips {
  1072. // position: fixed;
  1073. // top: var(--window-top);
  1074. // top: 80rpx;
  1075. width: 100%;
  1076. height: 80rpx;
  1077. font-size: 30rpx;
  1078. line-height: 80rpx;
  1079. background: rgba(231, 76, 60, 0.7);
  1080. z-index: 999;
  1081. color: #ffffff;
  1082. text-align: center;
  1083. }
  1084. .notice {
  1085. // position: fixed;
  1086. // top: var(--window-top);
  1087. // top: 80rpx;
  1088. width: 100%;
  1089. font-size: 26rpx;
  1090. font-weight: 400;
  1091. color: rgba(204, 149, 59, 1);
  1092. line-height: 40rpx;
  1093. padding: 16rpx;
  1094. box-sizing: border-box;
  1095. background: rgba(252, 248, 227, 0.7);
  1096. color: #c09853;
  1097. z-index: 999;
  1098. }
  1099. .close_notice {
  1100. width: 100rpx;
  1101. font-size: 40rpx;
  1102. }
  1103. // 选择商品
  1104. .mask {
  1105. position: fixed;
  1106. width: 100%;
  1107. height: 100%;
  1108. background: rgba(#000, 0.3);
  1109. z-index: 11;
  1110. }
  1111. .select_model {
  1112. background-color: #f2f2f2;
  1113. position: fixed;
  1114. bottom: 0rpx;
  1115. z-index: 998;
  1116. width: 100%;
  1117. border-top-left-radius: 20rpx;
  1118. border-top-right-radius: 20rpx;
  1119. .select_model--head {
  1120. background-color: #fff;
  1121. height: 82rpx;
  1122. padding: 0 26rpx;
  1123. border-radius: 20rpx 20rpx 0 0;
  1124. .select-title-box {
  1125. line-height: 82rpx;
  1126. .title-text {
  1127. font-size: 30rpx;
  1128. font-family: PingFang SC;
  1129. font-weight: 500;
  1130. color: rgba(51, 51, 51, 1);
  1131. line-height: 76rpx;
  1132. }
  1133. .title-line {
  1134. width: 120rpx;
  1135. height: 6rpx;
  1136. background: rgba(230, 184, 115, 1);
  1137. }
  1138. }
  1139. }
  1140. }
  1141. .close_select {
  1142. font-size: 40rpx;
  1143. padding: 20rpx 0;
  1144. color: #e0e0e0;
  1145. }
  1146. .project_list {
  1147. flex: 1;
  1148. overflow-x: hidden;
  1149. height: 440rpx;
  1150. padding: 20rpx 0;
  1151. }
  1152. .project_item {
  1153. background-color: #ffffff;
  1154. display: flex;
  1155. align-items: center;
  1156. padding: 16rpx 8rpx 16rpx 16rpx;
  1157. margin: 10rpx 20rpx;
  1158. border-radius: 20rpx;
  1159. }
  1160. .project_item:last-child {
  1161. margin-bottom: 0;
  1162. }
  1163. .project_item image {
  1164. width: 160rpx;
  1165. height: 160rpx;
  1166. min-width: 160rpx;
  1167. }
  1168. .project_item_body {
  1169. min-height: 170rpx;
  1170. width: 100%;
  1171. margin: 0 16rpx;
  1172. align-items: flex-start;
  1173. }
  1174. .project_item_title {
  1175. font-size: 26rpx;
  1176. line-height: 32rpx;
  1177. color: #333333;
  1178. }
  1179. .project_item_note {
  1180. font-size: 26rpx;
  1181. color: #999999;
  1182. line-height: 32rpx;
  1183. margin-top: 6rpx;
  1184. // width: 250rpx;
  1185. }
  1186. .project_item_price {
  1187. .price {
  1188. color: #e1212b;
  1189. font-size: 28rpx;
  1190. &::before {
  1191. content: '¥';
  1192. font-size: 20rpx;
  1193. }
  1194. }
  1195. .unit {
  1196. color: #999999;
  1197. font-size: 22rpx;
  1198. margin-left: 20rpx;
  1199. }
  1200. }
  1201. // .project_item_price text:last-child {
  1202. // margin-left: 16rpx;
  1203. // color: #999999;
  1204. // font-size: 26rpx;
  1205. // }
  1206. // .project_item_price text:first-child {
  1207. // margin-left: -6rpx;
  1208. // font-size: 34rpx;
  1209. // color: rgba(231, 76, 60, 1);
  1210. // }
  1211. .select_model_no_data {
  1212. font-size: 30rpx;
  1213. height: 100%;
  1214. background: #ffffff;
  1215. color: #999999;
  1216. display: flex;
  1217. align-items: center;
  1218. justify-content: center;
  1219. }
  1220. .content_wrapper {
  1221. }
  1222. .chat_wrapper {
  1223. background-color: #f8fbfb;
  1224. width: 100%;
  1225. box-sizing: border-box;
  1226. color: #181818;
  1227. }
  1228. .chat_wrapper scroll-view {
  1229. height: 100%;
  1230. }
  1231. .chat_wrapper .status {
  1232. // position: relative;
  1233. // float: right;
  1234. width: 100%;
  1235. margin: 20rpx;
  1236. text-align: center;
  1237. height: 60rpx;
  1238. line-height: 60rpx;
  1239. }
  1240. .chat_wrapper .status text {
  1241. font-size: 24rpx;
  1242. // display: inline-block;
  1243. background: #ccc;
  1244. color: #fff;
  1245. border-radius: 17rpx;
  1246. padding: 6rpx 20rpx;
  1247. line-height: 24rpx;
  1248. }
  1249. // 消息列表
  1250. .message-item {
  1251. align-items: flex-start;
  1252. margin: 20rpx;
  1253. .head-img {
  1254. width: 70rpx;
  1255. height: 70rpx;
  1256. border-radius: 50%;
  1257. }
  1258. }
  1259. .message__left {
  1260. justify-content: flex-start;
  1261. }
  1262. .message__right {
  1263. justify-content: flex-end;
  1264. }
  1265. .chat_wrapper .bubble {
  1266. font-size: 26rpx;
  1267. position: relative;
  1268. display: inline-block;
  1269. // clear: both;
  1270. margin-bottom: 16rpx;
  1271. padding: 20rpx;
  1272. // vertical-align: top;
  1273. border-radius: 10rpx;
  1274. // width: 260px;
  1275. }
  1276. .chat_wrapper .bubble.me {
  1277. // float: right;
  1278. margin-right: 28rpx;
  1279. // margin-left: 20rpx;
  1280. color: #fff;
  1281. background-color: #e6b873;
  1282. word-wrap: break-word;
  1283. word-break: break-all;
  1284. }
  1285. .chat_wrapper .bubble.you {
  1286. // float: left;
  1287. // margin-right: 20rpx;
  1288. margin-left: 28rpx;
  1289. color: #181818;
  1290. background-color: #fff;
  1291. word-wrap: break-word;
  1292. word-break: break-all;
  1293. }
  1294. .chat_wrapper .bubble:before {
  1295. position: absolute;
  1296. top: 38rpx;
  1297. display: block;
  1298. width: 16rpx;
  1299. height: 12rpx;
  1300. content: '\00a0';
  1301. -webkit-transform: rotate(29deg) skew(-35deg);
  1302. transform: rotate(29deg) skew(-35deg);
  1303. }
  1304. .chat_wrapper .bubble.you:before {
  1305. left: -6rpx;
  1306. background-color: #fff;
  1307. }
  1308. .chat_wrapper .bubble.me:before {
  1309. right: -6rpx;
  1310. background-color: #e6b873;
  1311. }
  1312. .chat_wrapper .bubble image {
  1313. // max-height: 400rpx !important;
  1314. display: block;
  1315. width: 200rpx;
  1316. vertical-align: bottom;
  1317. }
  1318. .chat_wrapper .bubble .emoji {
  1319. display: inline-block;
  1320. width: 120rpx;
  1321. min-height: 50rpx;
  1322. }
  1323. // 消息输入
  1324. .content_wrapper .write {
  1325. box-sizing: border-box;
  1326. background-color: #f2f2f2;
  1327. box-shadow: 0 -2rpx 0 #e5e5e5;
  1328. width: 100%;
  1329. padding: 20rpx;
  1330. display: flex;
  1331. align-items: center;
  1332. position: fixed;
  1333. bottom: 0rpx;
  1334. z-index: 22;
  1335. }
  1336. #wrapper_footer {
  1337. display: block;
  1338. clear: both;
  1339. height: 200rpx;
  1340. width: 100%;
  1341. }
  1342. .write_right {
  1343. flex: 2;
  1344. display: flex;
  1345. align-items: center;
  1346. justify-content: center;
  1347. }
  1348. .widget_textarea {
  1349. flex: 7;
  1350. background-color: #ffffff;
  1351. border-radius: 20rpx;
  1352. // overflow-y: auto;
  1353. display: flex;
  1354. justify-content: center;
  1355. align-items: center;
  1356. // max-height: 200rpx;
  1357. padding: 20rpx;
  1358. }
  1359. .content_wrapper .toolbar_icon {
  1360. display: inline-block;
  1361. cursor: pointer;
  1362. vertical-align: middle;
  1363. width: 56rpx;
  1364. height: 56rpx;
  1365. content: '';
  1366. margin-left: 16rpx;
  1367. }
  1368. .kefu_message {
  1369. width: 100%;
  1370. outline: none;
  1371. border: none;
  1372. resize: none;
  1373. -webkit-user-select: text !important;
  1374. -moz-user-select: text !important;
  1375. -ms-user-select: text !important;
  1376. user-select: text !important;
  1377. line-height: 36rpx;
  1378. font-size: 28rpx;
  1379. color: #333;
  1380. }
  1381. .kefu_message::-webkit-scrollbar {
  1382. width: 4rpx;
  1383. }
  1384. .kefu_message::-webkit-scrollbar-track {
  1385. background-color: #fff;
  1386. -webkit-border-radius: 2em;
  1387. -moz-border-radius: 2em;
  1388. border-radius: 2em;
  1389. }
  1390. .kefu_message::-webkit-scrollbar-thumb {
  1391. background-color: #e6e6e6;
  1392. -webkit-border-radius: 2em;
  1393. -moz-border-radius: 2em;
  1394. border-radius: 2em;
  1395. }
  1396. .footer_div {
  1397. position: fixed;
  1398. bottom: 0rpx;
  1399. z-index: 22;
  1400. background-color: #fff;
  1401. box-shadow: 0 8rpx 10rpx rgba(0, 0, 0, 0.1);
  1402. width: 100%;
  1403. animation: show_footer_div 0.1s;
  1404. animation-fill-mode: forwards;
  1405. padding-top: 12rpx;
  1406. box-sizing: border-box;
  1407. height: 170px;
  1408. overflow-y: auto;
  1409. overflow-x: hidden;
  1410. }
  1411. @keyframes show_footer_div {
  1412. from {
  1413. height: 0;
  1414. }
  1415. to {
  1416. height: 170px;
  1417. }
  1418. }
  1419. .footer_div image {
  1420. height: 51rpx;
  1421. width: 51rpx;
  1422. padding: 12rpx;
  1423. }
  1424. .send_btn {
  1425. margin-left: 28rpx;
  1426. background: #00b0ff;
  1427. color: #fff;
  1428. border-color: #00b0ff;
  1429. outline: none;
  1430. padding: 10rpx 20rpx;
  1431. font-size: 24rpx;
  1432. line-height: 1.5;
  1433. border-radius: 6rpx;
  1434. }
  1435. .send_btn::after {
  1436. border: none;
  1437. }
  1438. .send_btn_hover {
  1439. background-color: #19baff;
  1440. }
  1441. .toolbar {
  1442. display: flex;
  1443. flex-wrap: wrap;
  1444. }
  1445. .toolbar_item {
  1446. margin-top: 20rpx;
  1447. width: 25%;
  1448. display: flex;
  1449. flex-wrap: wrap;
  1450. align-items: center;
  1451. justify-content: center;
  1452. .tool-img {
  1453. width: 100rpx;
  1454. height: 100rpx;
  1455. }
  1456. }
  1457. .toolbar_item view {
  1458. display: block;
  1459. width: 100%;
  1460. font-size: 26rpx;
  1461. line-height: 34rpx;
  1462. text-align: center;
  1463. color: #333;
  1464. }
  1465. // 留言板
  1466. .leave_message {
  1467. padding: 0 20rpx 50rpx;
  1468. background-color: #fff;
  1469. border-top: 1rpx solid rgba(#dfdfdf, 0.5);
  1470. position: relative;
  1471. .form-group {
  1472. .label-title {
  1473. font-size: 28rpx;
  1474. font-family: PingFang SC;
  1475. font-weight: bold;
  1476. color: rgba(51, 51, 51, 1);
  1477. line-height: 100rpx;
  1478. }
  1479. .form-control {
  1480. width: 660rpx;
  1481. height: 84rpx;
  1482. background: rgba(249, 250, 251, 1);
  1483. border-radius: 20rpx;
  1484. padding: 12rpx 24rpx;
  1485. color: #555;
  1486. font-size: 26rpx;
  1487. }
  1488. }
  1489. }
  1490. .leave_success {
  1491. width: 600rpx;
  1492. height: 74rpx;
  1493. line-height: 74rpx;
  1494. margin: 200rpx auto 0;
  1495. background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
  1496. border-radius: 37rpx;
  1497. font-size: 28rpx;
  1498. font-family: PingFang SC;
  1499. font-weight: 400;
  1500. color: rgba(255, 255, 255, 1);
  1501. }
  1502. </style>