index.vue 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. <template>
  2. <view class="content">
  3. <!-- <navigation-custom :config="config" :scrollTop="scrollTopNav" @customConduct="customConduct" :scrollMaxHeight="scrollMaxHeight" /> -->
  4. <scroll-view
  5. id="scrollview"
  6. class="chat-box"
  7. :style="{ height: style.contentViewHeight + 'px' }"
  8. scroll-y="true"
  9. :scroll-with-animation="false"
  10. :scroll-top="scrollTop"
  11. @scrolltoupper="lower()"
  12. >
  13. <view class="auth" v-if="!isAuth">
  14. <text>对不起,您还未登录!请</text>
  15. <button @click="goAuthPage">授权登录</button>
  16. </view>
  17. <!-- <view class="tips-box">
  18. {{nowTime}}
  19. </view> -->
  20. <!-- <view class="tips-box tips-title">
  21. 您好,智能投顾很高兴为您服务!
  22. </view> -->
  23. <!-- <view class="talk-box">
  24. <view class="talk-head-box">
  25. <image src="../../static/rabotHead.png" mode="" class="talk-head"></image>
  26. </view>
  27. <view class="talk-content">您好,欢迎您使用阿拉灯神丁。我可以给您提供股票投资建议,快来试试吧。</view>
  28. </view> -->
  29. <view v-for="chat in talkList" :key="chat.talkType" class="m-item">
  30. <view class="talk-box talk-box-end" v-show="chat.content">
  31. <view class="talk-reply">{{ chat.content }}</view>
  32. <view class="talk-head-box"><image :src="userHeadUrl" mode="" class="talk-head" @click.stop="goUserSelf"></image></view>
  33. </view>
  34. <view class="talk-box">
  35. <view class="talk-head-box"><image :src="rabotHeadImg" mode="" class="talk-head"></image></view>
  36. <view class="talk-content">
  37. {{ chat.reply }}
  38. <text class="goRechargeText" v-if="chat.isRecharge" @click.stop="goSharePage()">去分享</text>
  39. </view>
  40. </view>
  41. </view>
  42. </scroll-view>
  43. <view class="send-box" :style="{ 'padding-bottom': isShowKeyBoard + 'px' }">
  44. <image :src="[!isVoiceType ? '/static/icon/voice-icon.png' : '/static/icon/keyBoard-icon.png']" @click.stop="tabVoice()"></image>
  45. <view class="voice-mode" v-if="isVoiceType" @touchstart="longPressStart" @touchend="touchMoveEnd">按住说话</view>
  46. <!-- <view>{{arsRes}}</view> -->
  47. <!-- 语音识别 -->
  48. <!-- <wechat-asr ref="weixinAsr" @callback="asrResult" /> -->
  49. <input
  50. type="text"
  51. v-if="!isVoiceType"
  52. class="enter-box"
  53. v-model="inputInfo"
  54. :adjust-position="true"
  55. @focus="isNeedAuth()"
  56. :style="{ width: inputWidth }"
  57. confirm-hold="true"
  58. confirm-type="send"
  59. @confirm="sendInputInfo"
  60. />
  61. <!-- @input='isInputing' -->
  62. <!-- <button type="primary" class="submit-message" @click="sendInputInfo()" v-if='isShowSend'>发送</button> -->
  63. <image src="/static/setIcon.png" @click.stop="openModal()" v-if="isShowSetCenter"></image>
  64. </view>
  65. <view>
  66. <uni-popup ref="showCountsModal" type="center" :custom="true">
  67. <view class="uni-tip everyDay-box">
  68. <image src="/static/rabotHead.png" mode="aspectFit"></image>
  69. <view>恭喜你获取{{ everyDayCounts || 0}}次查询机会</view>
  70. <button type="default" @click.stop="addEveryDayCounts">我知道啦</button>
  71. </view>
  72. </uni-popup>
  73. </view>
  74. <view class="mask" v-show="isShowVoice">
  75. <view class="weixin-asr">
  76. <view class="title">语音识别</view>
  77. <!-- 动画 -->
  78. <view class="spinner">
  79. <view class="rect rect1"></view>
  80. <view class="rect rect2"></view>
  81. <view class="rect rect3"></view>
  82. <view class="rect rect4"></view>
  83. <view class="rect rect5"></view>
  84. </view>
  85. <view class="tip">说出股票代码</view>
  86. <!-- <view>{{resultText}}</view> -->
  87. <button class="btn" type="default" @click="recordStop">说完了</button>
  88. </view>
  89. </view>
  90. <uni-popup ref="popup" type="bottom">
  91. <view class="uni-share">
  92. <view class="uni-share-content">
  93. <view class="uni-share-content-box" @click.stop="goUserSelf">
  94. <view class="uni-share-content-image"><image src="/static/icon/userSetIcon.png" class="image" /></view>
  95. <view class="uni-share-content-text">个人中心</view>
  96. </view>
  97. <view class="uni-share-content-box" @click.stop="goSharePage">
  98. <view class="uni-share-content-image"><image src="/static/icon/share-icon1.png" class="image" /></view>
  99. <view class="uni-share-content-text">去分享</view>
  100. </view>
  101. <!-- <view class="uni-share-content-box" @click.stop='tabVoice' >
  102. <view class="uni-share-content-image">
  103. <image src="/static/icon/userSetIcon.png" class="image" />
  104. </view>
  105. <view class="uni-share-content-text">语音输入</view>
  106. </view> -->
  107. <view class="uni-share-content-box" @click.stop="cleanChatRecord()">
  108. <view class="uni-share-content-image"><image src="/static/icon/clean-icon.png" class="image" /></view>
  109. <view class="uni-share-content-text">清空</view>
  110. </view>
  111. <!-- <view class="uni-share-content-box" @click.stop='goRecharge' v-if="!isIos">
  112. <view class="uni-share-content-image">
  113. <image src="/static/icon/recharge.png" class="image" />
  114. </view>
  115. <view class="uni-share-content-text">去充值</view>
  116. </view> -->
  117. </view>
  118. <view class="uni-share-btn" @click="cancelModal()">取消</view>
  119. </view>
  120. </uni-popup>
  121. </view>
  122. </template>
  123. <script>
  124. import uniPopup from "@/components/uni-popup/uni-popup.vue"
  125. import WechatAsr from '../chat/chat.vue';
  126. var md5 = require("../../common/md5.js");
  127. var page = 1;
  128. const recorderManager = uni.getRecorderManager();
  129. const innerAudioContext = uni.createInnerAudioContext();
  130. const WechatSI = requirePlugin("WechatSI");
  131. const ASRManager = WechatSI.getRecordRecognitionManager();
  132. export default {
  133. data() {
  134. return {
  135. isShowVoice:false,
  136. isShowSend:false,
  137. isShowSetModal:false,
  138. isShowSetCenter:true,
  139. isShowRecharge:false,
  140. inputWidth:'70%',
  141. title: 'RABOT',
  142. nowTime: '',
  143. nowHeight: '622px',
  144. inputInfo: '',
  145. isShowKeyBoard:0,
  146. rabotHeadImg: "../../static/rabotHead.png",
  147. userHeadUrl: getApp().globalData.user_headUrl || '../../static/userDefault.png',
  148. talkList: [],
  149. scrollTopNav: 0, // 当linear为true的时候需要通过onpagescroll传递参数
  150. scrollMaxHeight: 200 ,//滑动的高度限制,超过这个高度即背景全部显示
  151. scrollTop:0,
  152. scrollRequestEnable: true,
  153. pageSize:10,
  154. isIos:Boolean,
  155. style: {
  156. pageHeight: 0,
  157. contentViewHeight: 0,
  158. footViewHeight: 90,
  159. mitemHeight: 0
  160. },
  161. isAuth:true,
  162. iv:'',
  163. session_key:'',
  164. encryptedData:'',
  165. //录音相关参数
  166. isVoiceType:false,
  167. RECORDER:uni.getRecorderManager(),
  168. isVoice:false,
  169. voiceTis:'按住 说话',
  170. recordTis:"手指上滑 取消发送",
  171. recording:false,
  172. willStop:false,
  173. initPoint:{identifier:0,Y:0},
  174. recordTimer:null,
  175. recordLength:0,
  176. //播放语音相关参数
  177. AUDIO:uni.createInnerAudioContext(),
  178. playMsgid:null,
  179. VoiceTimer:null,
  180. voicePath: '',
  181. arsRes: '',
  182. inviteId:'',
  183. everyDayCounts:''
  184. }
  185. },
  186. components: {
  187. uniPopup,
  188. WechatAsr
  189. },
  190. onPageScroll(e) {
  191. this.scrollTopNav = e.scrollTop;
  192. },
  193. onReady () {
  194. // 录音开启成功回调
  195. ASRManager.onStart = function (res) {
  196. _this.isShowVoice = true;
  197. }
  198. const _this = this;
  199. // 识别错误事件
  200. ASRManager.onError = (res) => {
  201. _this.isShowVoice = false;
  202. // uni.showToast({
  203. // title:'请再试一次',
  204. // icon:'none',
  205. // duration:2000
  206. // })
  207. }
  208. // 录音停止回调
  209. ASRManager.onStop = function (res) {
  210. if (res && res.result) {
  211. // _this.resultText = res.result;
  212. // _this.$emit('callback', res.result);
  213. res = (res.result).substring(0,res.result.length-1)
  214. console.log(res)
  215. page = 1;
  216. _this.sendMsgRequest(res)
  217. } else {
  218. uni.showToast({
  219. icon: 'none',
  220. title: '抱歉,没听到您的声音哦'
  221. })
  222. }
  223. }
  224. },
  225. onShareAppMessage(){
  226. return {
  227. title: '阿拉灯神丁',
  228. path: '/pages/index/index?inviteId=' + getApp().globalData.user_id
  229. }
  230. },
  231. onLoad(options) {
  232. if(options.inviteId){
  233. page = 1;
  234. this.inviteId = options.inviteId;
  235. getApp().globalData.inviteId = options.inviteId;
  236. console.log('inviteId:',getApp().globalData.inviteId)
  237. }
  238. this.userLogin();
  239. this.getEquipmentHeight();
  240. },
  241. onShow() {
  242. //this.getNowTime();
  243. this.userHeadUrl = getApp().globalData.user_headUrl || '../../static/userDefault.png',
  244. getApp().globalData.isAuth ? this.isAuth = true : this.isAuth = false ;
  245. getApp().globalData.user_id ? this.getUserStorage(): this.title = 'RABOT' ;
  246. getApp().globalData.user_id ? this.isShowRecharge ? this.getHistory('show') : this.getHistory() : this.title = 'RABOT' ;
  247. },
  248. methods: {
  249. userLogin(){
  250. uni.showLoading({})
  251. uni.login({
  252. success: (res) => {
  253. this.getCodeRabot(res)
  254. }
  255. });
  256. },
  257. // 获取用户信息
  258. getUserInfo(e) {
  259. console.log(e);
  260. if (e.detail.errMsg == "getUserInfo:ok") {
  261. this.iv = e.detail.iv;
  262. this.encryptedData = e.detail.encryptedData;
  263. this.loginUserInfo()
  264. } else {
  265. console.log("用户信息授权失败");
  266. this.isShowAuthBtn = true;
  267. }
  268. },
  269. loginUserInfo(){
  270. let that = this;
  271. uni.request({
  272. url:getApp().globalData.shareUrl, //需要设置为全局
  273. method: 'POST',
  274. header: {
  275. 'content-type': 'application/x-www-form-urlencoded'
  276. },
  277. data: {
  278. method: 'auth',
  279. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  280. //uid:getApp().globalData.user_id,
  281. sign: md5('auth' + getApp().globalData.globalTimestamp),
  282. //nickname:getApp().globalData.user_name,
  283. //headimg:getApp().globalData.user_headUrl,
  284. iv:that.iv,
  285. session_key:that.session_key,
  286. encryptedData:that.encryptedData,
  287. invited:that.inviteId
  288. },
  289. success: res => {
  290. that.isAuth = true;
  291. getApp().globalData.user_id = res.data.msg.id;
  292. getApp().globalData.open_id = res.data.msg.openid;
  293. getApp().globalData.isAuth = that.isAuth;
  294. getApp().globalData.times = res.data.msg.times;
  295. getApp().globalData.total_times = res.data.msg.total_times;
  296. getApp().globalData.user_headUrl = res.data.msg.headimg;
  297. getApp().globalData.user_name = res.data.msg.name;
  298. that.userHeadUrl = res.data.msg.headimg || '../../static/userDefault.png';
  299. that.getUserStorage();
  300. that.getHistory();
  301. }
  302. });
  303. },
  304. getCodeRabot(res){
  305. let that = this;
  306. uni.request({
  307. url:getApp().globalData.shareUrl, //需要设置为全局
  308. method: 'POST',
  309. header: {
  310. 'content-type': 'application/x-www-form-urlencoded'
  311. },
  312. data: {
  313. method: 'login',
  314. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  315. code: res.code,
  316. sign: md5('login' + getApp().globalData.globalTimestamp),
  317. },
  318. success: res => {
  319. var isAuth = res.data.msg.isauth === 1;
  320. that.session_key = res.data.msg.session_key;
  321. if(isAuth){
  322. this.isAuth = true;
  323. getApp().globalData.user_id = res.data.msg.id;
  324. getApp().globalData.open_id = res.data.msg.openid;
  325. getApp().globalData.isAuth = true;
  326. getApp().globalData.times = res.data.msg.times;
  327. getApp().globalData.total_times = res.data.msg.total_times;
  328. getApp().globalData.user_headUrl = res.data.msg.headimg;
  329. getApp().globalData.user_name = res.data.msg.name;
  330. that.userHeadUrl = res.data.msg.headimg || '../../static/userDefault.png';
  331. that.getUserStorage();
  332. that.getHistory();
  333. }else{
  334. getApp().globalData.session_key = res.data.msg.session_key;
  335. that.isAuth = isAuth;
  336. getApp().globalData.isAuth = isAuth;
  337. wx.hideLoading();
  338. }
  339. }
  340. });
  341. },
  342. getNowTime() {
  343. let time = new Date();
  344. let y = time.getFullYear();
  345. let m = time.getMonth() + 1;
  346. let d = time.getDate();
  347. let h = time.getHours();
  348. let i = time.getMinutes();
  349. i = i > 10 ? i : '0' + i;
  350. this.nowTime = y + "年" + m + "月" + d + "日" + " " + h + ":" + i
  351. },
  352. getUserStorage(){
  353. let that = this
  354. uni.getStorage({
  355. key: 'getTime',
  356. success: function (res) {
  357. let nowTime = Date.now();
  358. let lastTime = res.data;
  359. if(nowTime - lastTime >= 86400000){
  360. that.getEveryDayCounts()
  361. }else {
  362. return false
  363. }
  364. },
  365. fail:function () {
  366. that.getEveryDayCounts()
  367. }
  368. });
  369. },
  370. getEveryDayCounts(){
  371. let that = this;
  372. uni.request({
  373. url: getApp().globalData.shareUrl, //需要设置为全局
  374. method: 'POST',
  375. header: {
  376. 'content-type': 'application/x-www-form-urlencoded'
  377. },
  378. data: {
  379. method: 'add_freegive_times',
  380. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  381. uid: getApp().globalData.user_id,
  382. sign: md5('add_freegive_times' + getApp().globalData.globalTimestamp),
  383. },
  384. success: res => {
  385. if(res.data.code === 200){
  386. that.everyDayCounts = res.data.msg.times;
  387. that.$refs.showCountsModal.open();
  388. uni.setStorage({
  389. key: 'getTime',
  390. data:Date.now(),
  391. success: function () {
  392. console.log('success');
  393. //that.$refs.showCountsModal.close()
  394. }
  395. });
  396. }
  397. else {
  398. // uni.showToast({
  399. // title:res.data.msg,
  400. // icon:'none',
  401. // duration:1500
  402. // })
  403. return false
  404. }
  405. }
  406. });
  407. },
  408. addEveryDayCounts(){
  409. console.log('已领取');
  410. this.$refs.showCountsModal.close()
  411. },
  412. getEquipmentHeight() {
  413. const height = uni.getSystemInfoSync().windowHeight;
  414. this.nowHeight = height + 'px';
  415. getApp().globalData.glbalHeight = this.nowHeight;
  416. this.style.pageHeight = height;
  417. this.style.contentViewHeight = height - uni.getSystemInfoSync().screenWidth / 750 * (100) -7; //像素 因为给出的是像素高度 然后我们用的是upx 所以换算一下
  418. },
  419. scrollToBottom() {
  420. let that = this;
  421. let query = uni.createSelectorQuery();
  422. query.selectAll('.m-item').boundingClientRect();
  423. query.select('#scrollview').boundingClientRect();
  424. query.exec((res) => {
  425. that.style.mitemHeight = 0;
  426. res[0].forEach((rect) => that.style.mitemHeight = that.style.mitemHeight + rect.height + 40) //获取所有内部子元素的高度
  427. // 因为vue的虚拟DOM 每次生成的新消息都是之前的,所以采用异步setTimeout 主要就是添加了这红字
  428. that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight
  429. // setTimeout(() => {
  430. // if (that.style.mitemHeight > (that.style.contentViewHeight - 100)) { //判断子元素高度是否大于显示高度
  431. // that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight //用子元素的高度减去显示的高度就获益获得序言滚动的高度
  432. // }
  433. // }, 100)
  434. })
  435. },
  436. getHistory(isShow) {
  437. // if(getApp.globalData.isAuth){this.isAuth = true}
  438. let that = this;
  439. uni.request({
  440. url: getApp().globalData.shareUrl, //需要设置为全局
  441. method: 'POST',
  442. header: {
  443. 'content-type': 'application/x-www-form-urlencoded'
  444. },
  445. data: {
  446. method: 'question_list',
  447. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  448. uid: getApp().globalData.user_id,
  449. sign: md5('question_list' + getApp().globalData.globalTimestamp),
  450. page: page || 1,
  451. pageSize: 10,
  452. },
  453. success: res => {
  454. uni.hideLoading()
  455. that.isIos = getApp().globalData.isIos;
  456. if(isShow){
  457. res.data.msg[0].isRecharge = 1
  458. }
  459. if(page === 1){
  460. that.scrollRequestEnable = true;
  461. that.talkList = ((res.data.msg).reverse());
  462. setTimeout(()=>{
  463. that.scrollToBottom()
  464. },100)
  465. }else if (page > 1 && res.data.msg.length === that.pageSize) {
  466. that.scrollRequestEnable = true;
  467. that.talkList.unshift(...((res.data.msg).reverse()));
  468. }else if (page > 1 && (res.data.msg.length > 0) && (res.data.msg.length < that.pageSize)){
  469. that.scrollRequestEnable = true;
  470. that.talkList.unshift(...((res.data.msg).reverse()));
  471. }else if (page > 1 && res.data.msg.length == 0){
  472. that.scrollRequestEnable = false;
  473. }
  474. }
  475. });
  476. },
  477. goUserSelf() {
  478. this.$refs.popup.close()
  479. uni.navigateTo({
  480. url: '../selfInfo/selfInfo'
  481. })
  482. },
  483. goRecharge() {
  484. this.$refs.popup.close()
  485. uni.navigateTo({
  486. url: '../selfInfo/payList/payList'
  487. })
  488. },
  489. sendMsgRequest(msg) {
  490. if(getApp().globalData.user_id=='') return false;
  491. let that = this;
  492. uni.request({
  493. url: getApp().globalData.shareUrl, //需要设置为全局
  494. method: 'POST',
  495. header: {
  496. 'content-type': 'application/x-www-form-urlencoded'
  497. },
  498. data: {
  499. method: 'question',
  500. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  501. uid: getApp().globalData.user_id,
  502. sign: md5('question' + getApp().globalData.globalTimestamp),
  503. content: msg
  504. },
  505. success: res => {
  506. if(res.data.code === 100){
  507. that.isShowRecharge = true;
  508. that.inputInfo = '';
  509. that.getHistory('show');
  510. }else {
  511. that.inputInfo = '';
  512. that.getHistory();
  513. that.isShowRecharge = false
  514. }
  515. }
  516. });
  517. },
  518. sendInputInfo() {
  519. // this.inputWidth = '80%';
  520. // this.isShowSend = false;
  521. // this.isShowSetCenter = true;
  522. if (!this.inputInfo) {
  523. uni.showToast({
  524. title: '请输入股票代码',
  525. icon: 'none'
  526. });
  527. } else {
  528. page = 1;
  529. this.sendMsgRequest(this.inputInfo)
  530. }
  531. },
  532. isInputing(){
  533. if (this.inputInfo) {
  534. this.inputWidth = '72%';
  535. this.isShowSend = true;
  536. this.isShowSetCenter = false;
  537. } else {
  538. this.inputWidth = '80%';
  539. this.isShowSend = false;
  540. this.isShowSetCenter = true;
  541. }
  542. },
  543. isNeedAuth(){
  544. if(!this.isAuth){
  545. setTimeout(()=>{
  546. uni.navigateTo({
  547. url: '../auth/index',
  548. success: res => {},
  549. fail: () => {},
  550. complete: () => {}
  551. });
  552. },500)
  553. }
  554. },
  555. // 滚动至底部触发的事件
  556. lower() {
  557. if (this.scrollRequestEnable) {
  558. // 允许滚动时,触底page加一,重新请求数据
  559. console.log(666)
  560. page++;
  561. this.getHistory();
  562. } else {
  563. // 不允许滚动时,只显示"到底了"提示
  564. // this.showBottem = true
  565. console.log('noData')
  566. }
  567. },
  568. getInputFocus(e){
  569. //this.isShowKeyBoard = e.detail.height
  570. },
  571. getInputBlur(){
  572. //this.isShowKeyBoard = 0
  573. },
  574. goSharePage(){
  575. uni.navigateTo({
  576. url: '../share/sharePage',
  577. success: res => {},
  578. fail: () => {},
  579. complete: () => {}
  580. });
  581. },
  582. tabVoice(){
  583. this.isVoiceType = !this.isVoiceType;
  584. },
  585. clearChat(){
  586. },
  587. goAuthPage(){
  588. uni.navigateTo({
  589. url: '../auth/index',
  590. success: res => {},
  591. fail: () => {},
  592. complete: () => {}
  593. });
  594. },
  595. openModal(){
  596. // 需要在 popup 组件,指定 ref 为 popup
  597. if(!this.isAuth){
  598. uni.navigateTo({
  599. url: '../auth/index',
  600. success: res => {},
  601. fail: () => {},
  602. complete: () => {}
  603. });
  604. }else {
  605. this.$refs.popup.open();
  606. }
  607. },
  608. cancelModal(){
  609. // 需要在 popup 组件,指定 ref 为 popup
  610. this.$refs.popup.close();
  611. },
  612. //情况聊天记录
  613. cleanChatRecord(){
  614. if(getApp().globalData.user_id=='') return false;
  615. let that = this;
  616. uni.request({
  617. url: getApp().globalData.shareUrl, //需要设置为全局
  618. method: 'POST',
  619. header: {
  620. 'content-type': 'application/x-www-form-urlencoded'
  621. },
  622. data: {
  623. method: 'clear_question',
  624. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  625. uid: getApp().globalData.user_id,
  626. sign: md5('clear_question' + getApp().globalData.globalTimestamp),
  627. },
  628. success: res => {
  629. console.log(res)
  630. if(res.data.code === 200){
  631. uni.showToast({
  632. title: '清除成功',
  633. icon:'none',
  634. duration:1500
  635. });
  636. that.$refs.popup.close();
  637. page = 1;
  638. that.getHistory();
  639. }else{
  640. uni.showToast({
  641. title: res.data.msg,
  642. icon:'none',
  643. duration:1500
  644. });
  645. }
  646. }
  647. });
  648. },
  649. // 语音识别
  650. show() {
  651. const _this = this;
  652. // 获取是否授权信息
  653. uni.getSetting({
  654. success(res) {
  655. if (res && res.authSetting && res.authSetting.hasOwnProperty('scope.record')) {
  656. if (res.authSetting['scope.record']) {
  657. start();
  658. } else { // 拒绝授权,打开授权设置
  659. uni.showModal({
  660. title: '麦克风授权',
  661. content: '点击确定重新获取授权。',
  662. success: function(res) {
  663. if (res.confirm) {
  664. uni.openSetting({
  665. success: res => {
  666. console.log('授权成功');
  667. }
  668. });
  669. }
  670. }
  671. });
  672. }
  673. } else {
  674. start();
  675. }
  676. }
  677. })
  678. function start () {
  679. ASRManager.start({
  680. lang: "zh_CN"
  681. });
  682. }
  683. },
  684. // 录音停止
  685. recordStop () {
  686. this.isShowVoice = false;
  687. ASRManager.stop();
  688. },
  689. // asrStart () {
  690. // let that = this;
  691. // this.$jiuaiDebounce.canDoFunction({
  692. // key:"asrStart",//基于此值判断是否可以操作,如两个方法传入了同样的key,则会混淆,建议传入调用此事件的方法名,简单好梳理
  693. // time:3000,//如果传入time字段,则为定时器后,自动解除锁定状态,单位(毫秒)
  694. // success:()=>{//成功中调用应该操作的方法,被锁定状态不会执行此代码块内的方法
  695. // this.isShowVoice = true;
  696. // this.show();
  697. // console.log(666)
  698. // }
  699. // })
  700. // },
  701. longPressStart(){
  702. this.show();
  703. },
  704. touchMoveEnd(){
  705. this.recordStop()
  706. },
  707. asrResult (res) {
  708. //this.arsRes = res;
  709. res = res.substring(0,res.length-1)
  710. page = 1;
  711. this.sendMsgRequest(res)
  712. }
  713. },
  714. onShareAppMessage(){
  715. }
  716. }
  717. </script>
  718. <style lang="scss">
  719. .content {
  720. text-align: center;
  721. }
  722. .chat-box {
  723. background: #f4f5f7;
  724. padding-top: 3%;
  725. /* padding-bottom: 100upx; */
  726. }
  727. .tips-box {
  728. background: #d5d5da;
  729. font-size: 28upx;
  730. color: #fff;
  731. border-radius: 30upx;
  732. width: 50%;
  733. margin: 0 auto;
  734. height: 50rpx;
  735. line-height: 50rpx;
  736. }
  737. .tips-title {
  738. width: 70%;
  739. margin-top: 5%;
  740. font-size: 30rpx;
  741. height: 70rpx;
  742. line-height: 70rpx;
  743. }
  744. .send-box {
  745. width: 100%;
  746. height: 90rpx;
  747. position: fixed;
  748. bottom: 0;
  749. background: #f4f0ed;
  750. display: flex;
  751. align-items: center;
  752. padding: 2upx;
  753. }
  754. .talk-box {
  755. display: flex;
  756. justify-content: flex-start;
  757. align-items: center;
  758. margin-top: 3%;
  759. }
  760. .talk-box-end {
  761. justify-content: flex-end;
  762. }
  763. .talk-head-box {
  764. width: 80rpx;
  765. height: 80rpx;
  766. border-radius: 30rpx;
  767. margin-left: 2%;
  768. margin-right: 2%;
  769. }
  770. .talk-head {
  771. width: 100%;
  772. height: 100%;
  773. border-radius: 50%;
  774. }
  775. .talk-content {
  776. padding: 2%;
  777. background: #fff;
  778. font-size: 28rpx;
  779. border-top-right-radius: 20rpx;
  780. border-bottom-left-radius: 20rpx;
  781. border-bottom-right-radius: 20rpx;
  782. text-align: left;
  783. max-width: 70%;
  784. }
  785. .talk-reply {
  786. padding: 2%;
  787. background: #9eea6a;
  788. font-size: 28rpx;
  789. border-top-left-radius: 20rpx;
  790. border-bottom-left-radius: 20rpx;
  791. border-bottom-right-radius: 20rpx;
  792. text-align: left;
  793. max-width: 70%;
  794. }
  795. .goRechargeText {
  796. color: #0a98d5;
  797. }
  798. .enter-box {
  799. height: 70rpx;
  800. background: #fff;
  801. border-radius: 1%;
  802. text-align: left;
  803. margin: 8px;
  804. margin-bottom: 10px;
  805. padding-left: 8px;
  806. }
  807. .send-box image {
  808. width: 60rpx;
  809. height: 60rpx;
  810. margin-right: 10upx;
  811. margin-left: 10upx;
  812. }
  813. .submit-message {
  814. width: 18%;
  815. margin-right: 20upx;
  816. height: 70rpx;
  817. font-size: 28rpx;
  818. line-height: 70rpx;
  819. color: #fff;
  820. background-color: #0a98d5 !important;
  821. }
  822. .logo {
  823. height: 200upx;
  824. width: 200upx;
  825. margin-top: 200upx;
  826. margin-left: auto;
  827. margin-right: auto;
  828. margin-bottom: 50upx;
  829. }
  830. .text-area {
  831. display: flex;
  832. justify-content: center;
  833. }
  834. .title {
  835. font-size: 36upx;
  836. color: #8f8f94;
  837. }
  838. .uniFab {
  839. width: 98px;
  840. height: 36px;
  841. background: rgba(231, 247, 236, 1);
  842. box-shadow: -6px 5px 74px 0px rgba(60, 188, 99, 0.08);
  843. border-radius: 100px 0px 0px 100px;
  844. right: 0upx;
  845. position: fixed;
  846. z-index: 9999;
  847. top: 50%;
  848. display: flex;
  849. justify-content: center;
  850. align-items: center;
  851. }
  852. .uniFab text {
  853. width: 64px;
  854. font-size: 16px;
  855. font-family: PingFangSC;
  856. font-weight: 600;
  857. color: rgba(60, 188, 99, 1);
  858. text-shadow: 0px 1px 2px rgba(12, 39, 20, 0.2);
  859. }
  860. .uni-share-content {
  861. display: flex;
  862. flex-wrap: wrap;
  863. padding: 15px;
  864. /* justify-content: center */
  865. }
  866. .uni-share-content-box {
  867. display: flex;
  868. flex-direction: column;
  869. align-items: center;
  870. width: 25%;
  871. box-sizing: border-box;
  872. }
  873. .uni-share-content-image {
  874. display: flex;
  875. justify-content: center;
  876. align-items: center;
  877. width: 60upx;
  878. height: 60upx;
  879. overflow: hidden;
  880. border-radius: 10upx;
  881. }
  882. .uni-share-content-image .image {
  883. width: 100%;
  884. height: 100%;
  885. }
  886. .uni-share-content-text {
  887. font-size: 26upx;
  888. color: #333;
  889. padding-top: 5px;
  890. padding-bottom: 10px;
  891. }
  892. .uni-share-btn {
  893. height: 90upx;
  894. line-height: 90upx;
  895. border-top: 1px #f5f5f5 solid;
  896. text-align: center;
  897. color: #666;
  898. font-size: 30rpx;
  899. }
  900. /* .placeHolder {
  901. padding:2px
  902. } */
  903. .auth {
  904. display: flex;
  905. flex-direction: row;
  906. font-size: 14px;
  907. justify-content: center;
  908. align-items: center;
  909. background-color: #eee;
  910. }
  911. .auth button {
  912. font-size: 14px;
  913. padding: 0px;
  914. margin: 0px;
  915. color: #007aff;
  916. background-color: #eee;
  917. }
  918. .auth button:after {
  919. border: 0px;
  920. }
  921. .voice-mode {
  922. width: 70%;
  923. height: 70rpx;
  924. background: #fff;
  925. border-radius: 1%;
  926. text-align: left;
  927. margin: 8px;
  928. margin-bottom: 10px;
  929. padding-left: 8px;
  930. text-align: center;
  931. line-height: 70upx;
  932. font-size: 30upx;
  933. }
  934. .icon {
  935. font-family: 'HMfont-home' !important;
  936. font-size: 56upx;
  937. font-style: normal;
  938. color: #333;
  939. }
  940. .hidden {
  941. display: none !important;
  942. }
  943. .record {
  944. width: 40vw;
  945. height: 40vw;
  946. position: fixed;
  947. top: 55%;
  948. left: 30%;
  949. background-color: rgba(0, 0, 0, 0.6);
  950. border-radius: 20upx;
  951. }
  952. .ing {
  953. width: 100%;
  954. height: 30vw;
  955. display: flex;
  956. justify-content: center;
  957. align-items: center;
  958. // 模拟录音音效动画
  959. }
  960. @keyframes volatility {
  961. 0% {
  962. background-position: 0% 130%;
  963. }
  964. 20% {
  965. background-position: 0% 150%;
  966. }
  967. 30% {
  968. background-position: 0% 155%;
  969. }
  970. 40% {
  971. background-position: 0% 150%;
  972. }
  973. 50% {
  974. background-position: 0% 145%;
  975. }
  976. 70% {
  977. background-position: 0% 150%;
  978. }
  979. 80% {
  980. background-position: 0% 155%;
  981. }
  982. 90% {
  983. background-position: 0% 140%;
  984. }
  985. 100% {
  986. background-position: 0% 135%;
  987. }
  988. }
  989. .cancel {
  990. width: 100%;
  991. height: 30vw;
  992. display: flex;
  993. justify-content: center;
  994. align-items: center;
  995. }
  996. .icon {
  997. background-image: linear-gradient(to bottom, #f09b37, #fff 50%);
  998. background-size: 100% 200%;
  999. animation: volatility 1.5s ease-in-out -1.5s infinite alternate;
  1000. -webkit-background-clip: text;
  1001. -webkit-text-fill-color: transparent;
  1002. font-size: 150upx;
  1003. color: #f09b37;
  1004. }
  1005. .tis {
  1006. width: 100%;
  1007. height: 10vw;
  1008. display: flex;
  1009. justify-content: center;
  1010. font-size: 28upx;
  1011. color: #fff;
  1012. }
  1013. .change {
  1014. color: #f09b37;
  1015. }
  1016. .everyDay-box {
  1017. background: #fff;
  1018. padding: 20px;
  1019. border-radius: 5%;
  1020. }
  1021. .everyDay-box image {
  1022. width: 240rpx;
  1023. height: 240rpx;
  1024. }
  1025. .everyDay-box view {
  1026. font-size: 28rpx;
  1027. }
  1028. .everyDay-box button {
  1029. font-size: 28rpx;
  1030. margin-top: 5%;
  1031. color: #fff;
  1032. background: #00bfff;
  1033. }
  1034. .mask {
  1035. position: fixed;
  1036. top: 0;
  1037. left: 0;
  1038. z-index: 300;
  1039. width: 100%;
  1040. height: 100%;
  1041. background: rgba(0, 0, 0, .54);
  1042. }
  1043. .weixin-asr {
  1044. position: absolute;
  1045. top: calc(50% - #{477upx / 2});
  1046. left: 0;
  1047. right: 0;
  1048. margin: 0 auto;
  1049. width: 560upx;
  1050. height: 477upx;
  1051. background: #fff;
  1052. text-align: center;
  1053. transform: .5s ease-out .5s;
  1054. .title {
  1055. margin-top: 42upx;
  1056. color: #000;
  1057. font-size: 34upx;
  1058. font-weight: 500;
  1059. }
  1060. .spinner {
  1061. margin: 50upx;
  1062. height: 100upx;
  1063. }
  1064. .tip {
  1065. color: #787878;
  1066. }
  1067. .btn {
  1068. margin-top: 28upx;
  1069. width: 225upx;
  1070. height: 82upx;
  1071. background: #27BCEF;
  1072. color: #fff;
  1073. font-size: 34upx;
  1074. line-height: 82upx;
  1075. border-radius: 82upx;
  1076. }
  1077. }
  1078. .spinner {
  1079. text-align: center;
  1080. }
  1081. .spinner > .rect {
  1082. background-color: #EDAA35;
  1083. height: 100%;
  1084. border-radius: 13upx;
  1085. width: 13upx;
  1086. display: inline-block;
  1087. -webkit-animation: stretchdelay 1.2s infinite ease-in-out;
  1088. animation: stretchdelay 1.2s infinite ease-in-out;
  1089. & + .rect {
  1090. margin-left: 15upx;
  1091. }
  1092. }
  1093. .spinner .rect2 {
  1094. -webkit-animation-delay: -1.1s;
  1095. animation-delay: -1.1s;
  1096. }
  1097. .spinner .rect3 {
  1098. -webkit-animation-delay: -1.0s;
  1099. animation-delay: -1.0s;
  1100. }
  1101. .spinner .rect4 {
  1102. -webkit-animation-delay: -0.9s;
  1103. animation-delay: -0.9s;
  1104. }
  1105. .spinner .rect5 {
  1106. -webkit-animation-delay: -0.8s;
  1107. animation-delay: -0.8s;
  1108. }
  1109. @-webkit-keyframes stretchdelay {
  1110. 0%, 40%, 100% { -webkit-transform: scaleY(0.4) }
  1111. 20% { -webkit-transform: scaleY(1.0) }
  1112. }
  1113. @keyframes stretchdelay {
  1114. 0%, 40%, 100% {
  1115. transform: scaleY(0.4);
  1116. -webkit-transform: scaleY(0.4);
  1117. } 20% {
  1118. transform: scaleY(1.0);
  1119. -webkit-transform: scaleY(1.0);
  1120. }
  1121. }
  1122. </style>