index.vue 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  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.openSetting({
  660. success() {
  661. start();
  662. }
  663. })
  664. }
  665. } else {
  666. start();
  667. }
  668. }
  669. })
  670. function start () {
  671. ASRManager.start({
  672. lang: "zh_CN"
  673. });
  674. }
  675. },
  676. // 录音停止
  677. recordStop () {
  678. this.isShowVoice = false;
  679. ASRManager.stop();
  680. },
  681. // asrStart () {
  682. // let that = this;
  683. // this.$jiuaiDebounce.canDoFunction({
  684. // key:"asrStart",//基于此值判断是否可以操作,如两个方法传入了同样的key,则会混淆,建议传入调用此事件的方法名,简单好梳理
  685. // time:3000,//如果传入time字段,则为定时器后,自动解除锁定状态,单位(毫秒)
  686. // success:()=>{//成功中调用应该操作的方法,被锁定状态不会执行此代码块内的方法
  687. // this.isShowVoice = true;
  688. // this.show();
  689. // console.log(666)
  690. // }
  691. // })
  692. // },
  693. longPressStart(){
  694. this.isShowVoice = true;
  695. this.show();
  696. },
  697. touchMoveEnd(){
  698. this.recordStop()
  699. },
  700. asrResult (res) {
  701. //this.arsRes = res;
  702. res = res.substring(0,res.length-1)
  703. page = 1;
  704. this.sendMsgRequest(res)
  705. }
  706. },
  707. onShareAppMessage(){
  708. }
  709. }
  710. </script>
  711. <style lang="scss">
  712. .content {
  713. text-align: center;
  714. }
  715. .chat-box {
  716. background: #f4f5f7;
  717. padding-top: 3%;
  718. /* padding-bottom: 100upx; */
  719. }
  720. .tips-box {
  721. background: #d5d5da;
  722. font-size: 28upx;
  723. color: #fff;
  724. border-radius: 30upx;
  725. width: 50%;
  726. margin: 0 auto;
  727. height: 50rpx;
  728. line-height: 50rpx;
  729. }
  730. .tips-title {
  731. width: 70%;
  732. margin-top: 5%;
  733. font-size: 30rpx;
  734. height: 70rpx;
  735. line-height: 70rpx;
  736. }
  737. .send-box {
  738. width: 100%;
  739. height: 90rpx;
  740. position: fixed;
  741. bottom: 0;
  742. background: #f4f0ed;
  743. display: flex;
  744. align-items: center;
  745. padding: 2upx;
  746. }
  747. .talk-box {
  748. display: flex;
  749. justify-content: flex-start;
  750. align-items: center;
  751. margin-top: 3%;
  752. }
  753. .talk-box-end {
  754. justify-content: flex-end;
  755. }
  756. .talk-head-box {
  757. width: 80rpx;
  758. height: 80rpx;
  759. border-radius: 30rpx;
  760. margin-left: 2%;
  761. margin-right: 2%;
  762. }
  763. .talk-head {
  764. width: 100%;
  765. height: 100%;
  766. border-radius: 50%;
  767. }
  768. .talk-content {
  769. padding: 2%;
  770. background: #fff;
  771. font-size: 28rpx;
  772. border-top-right-radius: 20rpx;
  773. border-bottom-left-radius: 20rpx;
  774. border-bottom-right-radius: 20rpx;
  775. text-align: left;
  776. max-width: 70%;
  777. }
  778. .talk-reply {
  779. padding: 2%;
  780. background: #9eea6a;
  781. font-size: 28rpx;
  782. border-top-left-radius: 20rpx;
  783. border-bottom-left-radius: 20rpx;
  784. border-bottom-right-radius: 20rpx;
  785. text-align: left;
  786. max-width: 70%;
  787. }
  788. .goRechargeText {
  789. color: #0a98d5;
  790. }
  791. .enter-box {
  792. height: 70rpx;
  793. background: #fff;
  794. border-radius: 1%;
  795. text-align: left;
  796. margin: 8px;
  797. margin-bottom: 10px;
  798. padding-left: 8px;
  799. }
  800. .send-box image {
  801. width: 60rpx;
  802. height: 60rpx;
  803. margin-right: 10upx;
  804. margin-left: 10upx;
  805. }
  806. .submit-message {
  807. width: 18%;
  808. margin-right: 20upx;
  809. height: 70rpx;
  810. font-size: 28rpx;
  811. line-height: 70rpx;
  812. color: #fff;
  813. background-color: #0a98d5 !important;
  814. }
  815. .logo {
  816. height: 200upx;
  817. width: 200upx;
  818. margin-top: 200upx;
  819. margin-left: auto;
  820. margin-right: auto;
  821. margin-bottom: 50upx;
  822. }
  823. .text-area {
  824. display: flex;
  825. justify-content: center;
  826. }
  827. .title {
  828. font-size: 36upx;
  829. color: #8f8f94;
  830. }
  831. .uniFab {
  832. width: 98px;
  833. height: 36px;
  834. background: rgba(231, 247, 236, 1);
  835. box-shadow: -6px 5px 74px 0px rgba(60, 188, 99, 0.08);
  836. border-radius: 100px 0px 0px 100px;
  837. right: 0upx;
  838. position: fixed;
  839. z-index: 9999;
  840. top: 50%;
  841. display: flex;
  842. justify-content: center;
  843. align-items: center;
  844. }
  845. .uniFab text {
  846. width: 64px;
  847. font-size: 16px;
  848. font-family: PingFangSC;
  849. font-weight: 600;
  850. color: rgba(60, 188, 99, 1);
  851. text-shadow: 0px 1px 2px rgba(12, 39, 20, 0.2);
  852. }
  853. .uni-share-content {
  854. display: flex;
  855. flex-wrap: wrap;
  856. padding: 15px;
  857. /* justify-content: center */
  858. }
  859. .uni-share-content-box {
  860. display: flex;
  861. flex-direction: column;
  862. align-items: center;
  863. width: 25%;
  864. box-sizing: border-box;
  865. }
  866. .uni-share-content-image {
  867. display: flex;
  868. justify-content: center;
  869. align-items: center;
  870. width: 60upx;
  871. height: 60upx;
  872. overflow: hidden;
  873. border-radius: 10upx;
  874. }
  875. .uni-share-content-image .image {
  876. width: 100%;
  877. height: 100%;
  878. }
  879. .uni-share-content-text {
  880. font-size: 26upx;
  881. color: #333;
  882. padding-top: 5px;
  883. padding-bottom: 10px;
  884. }
  885. .uni-share-btn {
  886. height: 90upx;
  887. line-height: 90upx;
  888. border-top: 1px #f5f5f5 solid;
  889. text-align: center;
  890. color: #666;
  891. font-size: 30rpx;
  892. }
  893. /* .placeHolder {
  894. padding:2px
  895. } */
  896. .auth {
  897. display: flex;
  898. flex-direction: row;
  899. font-size: 14px;
  900. justify-content: center;
  901. align-items: center;
  902. background-color: #eee;
  903. }
  904. .auth button {
  905. font-size: 14px;
  906. padding: 0px;
  907. margin: 0px;
  908. color: #007aff;
  909. background-color: #eee;
  910. }
  911. .auth button:after {
  912. border: 0px;
  913. }
  914. .voice-mode {
  915. width: 70%;
  916. height: 70rpx;
  917. background: #fff;
  918. border-radius: 1%;
  919. text-align: left;
  920. margin: 8px;
  921. margin-bottom: 10px;
  922. padding-left: 8px;
  923. text-align: center;
  924. line-height: 70upx;
  925. font-size: 30upx;
  926. }
  927. .icon {
  928. font-family: 'HMfont-home' !important;
  929. font-size: 56upx;
  930. font-style: normal;
  931. color: #333;
  932. }
  933. .hidden {
  934. display: none !important;
  935. }
  936. .record {
  937. width: 40vw;
  938. height: 40vw;
  939. position: fixed;
  940. top: 55%;
  941. left: 30%;
  942. background-color: rgba(0, 0, 0, 0.6);
  943. border-radius: 20upx;
  944. }
  945. .ing {
  946. width: 100%;
  947. height: 30vw;
  948. display: flex;
  949. justify-content: center;
  950. align-items: center;
  951. // 模拟录音音效动画
  952. }
  953. @keyframes volatility {
  954. 0% {
  955. background-position: 0% 130%;
  956. }
  957. 20% {
  958. background-position: 0% 150%;
  959. }
  960. 30% {
  961. background-position: 0% 155%;
  962. }
  963. 40% {
  964. background-position: 0% 150%;
  965. }
  966. 50% {
  967. background-position: 0% 145%;
  968. }
  969. 70% {
  970. background-position: 0% 150%;
  971. }
  972. 80% {
  973. background-position: 0% 155%;
  974. }
  975. 90% {
  976. background-position: 0% 140%;
  977. }
  978. 100% {
  979. background-position: 0% 135%;
  980. }
  981. }
  982. .cancel {
  983. width: 100%;
  984. height: 30vw;
  985. display: flex;
  986. justify-content: center;
  987. align-items: center;
  988. }
  989. .icon {
  990. background-image: linear-gradient(to bottom, #f09b37, #fff 50%);
  991. background-size: 100% 200%;
  992. animation: volatility 1.5s ease-in-out -1.5s infinite alternate;
  993. -webkit-background-clip: text;
  994. -webkit-text-fill-color: transparent;
  995. font-size: 150upx;
  996. color: #f09b37;
  997. }
  998. .tis {
  999. width: 100%;
  1000. height: 10vw;
  1001. display: flex;
  1002. justify-content: center;
  1003. font-size: 28upx;
  1004. color: #fff;
  1005. }
  1006. .change {
  1007. color: #f09b37;
  1008. }
  1009. .everyDay-box {
  1010. background: #fff;
  1011. padding: 20px;
  1012. border-radius: 5%;
  1013. }
  1014. .everyDay-box image {
  1015. width: 240rpx;
  1016. height: 240rpx;
  1017. }
  1018. .everyDay-box view {
  1019. font-size: 28rpx;
  1020. }
  1021. .everyDay-box button {
  1022. font-size: 28rpx;
  1023. margin-top: 5%;
  1024. color: #fff;
  1025. background: #00bfff;
  1026. }
  1027. .mask {
  1028. position: fixed;
  1029. top: 0;
  1030. left: 0;
  1031. z-index: 300;
  1032. width: 100%;
  1033. height: 100%;
  1034. background: rgba(0, 0, 0, .54);
  1035. }
  1036. .weixin-asr {
  1037. position: absolute;
  1038. top: calc(50% - #{477upx / 2});
  1039. left: 0;
  1040. right: 0;
  1041. margin: 0 auto;
  1042. width: 560upx;
  1043. height: 477upx;
  1044. background: #fff;
  1045. text-align: center;
  1046. transform: .5s ease-out .5s;
  1047. .title {
  1048. margin-top: 42upx;
  1049. color: #000;
  1050. font-size: 34upx;
  1051. font-weight: 500;
  1052. }
  1053. .spinner {
  1054. margin: 50upx;
  1055. height: 100upx;
  1056. }
  1057. .tip {
  1058. color: #787878;
  1059. }
  1060. .btn {
  1061. margin-top: 28upx;
  1062. width: 225upx;
  1063. height: 82upx;
  1064. background: #27BCEF;
  1065. color: #fff;
  1066. font-size: 34upx;
  1067. line-height: 82upx;
  1068. border-radius: 82upx;
  1069. }
  1070. }
  1071. .spinner {
  1072. text-align: center;
  1073. }
  1074. .spinner > .rect {
  1075. background-color: #EDAA35;
  1076. height: 100%;
  1077. border-radius: 13upx;
  1078. width: 13upx;
  1079. display: inline-block;
  1080. -webkit-animation: stretchdelay 1.2s infinite ease-in-out;
  1081. animation: stretchdelay 1.2s infinite ease-in-out;
  1082. & + .rect {
  1083. margin-left: 15upx;
  1084. }
  1085. }
  1086. .spinner .rect2 {
  1087. -webkit-animation-delay: -1.1s;
  1088. animation-delay: -1.1s;
  1089. }
  1090. .spinner .rect3 {
  1091. -webkit-animation-delay: -1.0s;
  1092. animation-delay: -1.0s;
  1093. }
  1094. .spinner .rect4 {
  1095. -webkit-animation-delay: -0.9s;
  1096. animation-delay: -0.9s;
  1097. }
  1098. .spinner .rect5 {
  1099. -webkit-animation-delay: -0.8s;
  1100. animation-delay: -0.8s;
  1101. }
  1102. @-webkit-keyframes stretchdelay {
  1103. 0%, 40%, 100% { -webkit-transform: scaleY(0.4) }
  1104. 20% { -webkit-transform: scaleY(1.0) }
  1105. }
  1106. @keyframes stretchdelay {
  1107. 0%, 40%, 100% {
  1108. transform: scaleY(0.4);
  1109. -webkit-transform: scaleY(0.4);
  1110. } 20% {
  1111. transform: scaleY(1.0);
  1112. -webkit-transform: scaleY(1.0);
  1113. }
  1114. }
  1115. </style>