| xqd
@@ -1,2136 +0,0 @@
|
|
|
-<template>
|
|
|
- <!-- <view style="padding-bottom: 248rpx;"> -->
|
|
|
- <view style="">
|
|
|
- <!-- #ifdef H5 -->
|
|
|
- <view style="color: #000;">
|
|
|
- <tn-nav-bar backgroundColor="#fff">GPT</tn-nav-bar>
|
|
|
- <view :style="{ height: tobheight + 'px' }"></view>
|
|
|
- </view>
|
|
|
- <!-- #endif -->
|
|
|
-
|
|
|
- <view class="content" @touchmove="touchmove">
|
|
|
-
|
|
|
- <view class="msg-list">
|
|
|
-
|
|
|
- <view v-if="!paintingmode" class="row">
|
|
|
- <block>
|
|
|
- <view class="other">
|
|
|
- <view class="left" v-if="appInfo.is_show_gpt_avatar_nickname == 1"
|
|
|
- @click="switchmodel = true">
|
|
|
- <u-image :src="
|
|
|
- homeTemplate.mode && homeTemplate.mode.length>0 && homeTemplate.mode[0].img_file.path
|
|
|
- ? homeTemplate.mode[0].img_file.path
|
|
|
- : '/static/images/head.jpg'
|
|
|
- " mode="widthFix" radius="5" width="40" height="40"></u-image>
|
|
|
- </view>
|
|
|
- <view class="right">
|
|
|
- <view class="username">
|
|
|
- <view class="name"></view>
|
|
|
- <view class="time">{{ homeTemplate.mode && homeTemplate.mode.length>0 && homeTemplate.mode[0].name
|
|
|
- ?homeTemplate.mode[0].name :'ai问答机器人' }}</view>
|
|
|
- </view>
|
|
|
- <view class="bubble">
|
|
|
- <view class="content">
|
|
|
- <view style="font-size: 32rpx;">您可以点击下方案例直接提问......</view>
|
|
|
- <block v-for="(item, index) in homeTemplate.hot" :key="index">
|
|
|
- <view class="ask" @click="send(item.text)">{{ item.text }}</view>
|
|
|
- </block>
|
|
|
-
|
|
|
- <view @click="commontemplate" class="tn-flex align-center"
|
|
|
- style="justify-content: flex-end;margin-top: 15rpx;margin-bottom: 15rpx;">
|
|
|
- <view style="color: #9e9e9e;margin-right: 10rpx;">换一换</view>
|
|
|
- <u-icon name="reload" color="#9e9e9e" size="18"></u-icon>
|
|
|
- </view>
|
|
|
- <u-button size="small" @click="switchmodel = true" type="primary"
|
|
|
- text="切换模型"></u-button>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </block>
|
|
|
- </view>
|
|
|
- <block v-for="(row, index) in paintingmode?paintinglist:talkList" :key="index" :id="'msg' + row.id">
|
|
|
- <view class="row">
|
|
|
- <block>
|
|
|
- <view class="my" v-if="row.fromid == userInfo.id">
|
|
|
- <view class="left">
|
|
|
- <view class="username">
|
|
|
- <view class="name">{{ row.nickname }}</view>
|
|
|
- </view>
|
|
|
- <u-icon v-if="row.content !='该问题已被隐藏!'" @click="copyText(index)" name="file-text"
|
|
|
- color="#9e9e9e82" size="22"></u-icon>
|
|
|
- <view v-if="row.type == 1" class="bubble" style="color: #fff;margin-left: 15rpx;">
|
|
|
- <rich-text :nodes="row.content" @longtap="copy" :data-text="row.content"
|
|
|
- selectable="true"></rich-text>
|
|
|
- <!-- <zero-markdown-view
|
|
|
-
|
|
|
- :themeColor="themeColor" :markdown="row.content"></zero-markdown-view> -->
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- <view class="right">
|
|
|
- <!-- <u-avatar :src="row.avatar ? row.avatar : '/static/images/head.jpg'" size="40"
|
|
|
- shape="square" mode="aspectFill"></u-avatar> -->
|
|
|
- <u-image :src="row.avatar ? row.avatar : '/static/images/head.jpg'" mode="widthFix"
|
|
|
- radius="5" width="42" height="42"></u-image>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- <!-- GPT -->
|
|
|
- <view class="other" v-if="row.fromid != userInfo.id">
|
|
|
- <view class="left" v-if="appInfo.is_show_gpt_avatar_nickname == 1"
|
|
|
- @click="switchmodel = paintingmode?false:true">
|
|
|
- <u-image :src="row.avatar" mode="widthFix" radius="5" width="42"
|
|
|
- height="42"></u-image>
|
|
|
- </view>
|
|
|
- <view class="right">
|
|
|
- <view class="username" v-if="appInfo.is_show_gpt_avatar_nickname == 1">
|
|
|
- <view class="name"></view>
|
|
|
- <view class="time">{{ row.nickname }}</view>
|
|
|
- </view>
|
|
|
-
|
|
|
- <view v-if="row.type == 1" class="bubble"
|
|
|
- style="display: block;position: relative;">
|
|
|
- <view>
|
|
|
- <!-- <mp-html :content="row.content" markdown/> -->
|
|
|
- <zero-markdown-view
|
|
|
- v-if="(row.done && row.content.indexOf('```') != -1) || (row.done && row.content.indexOf('/*') != -1 || row.content.indexOf('---') != -1)"
|
|
|
- :themeColor="themeColor" :markdown="row.content"></zero-markdown-view>
|
|
|
- <text v-else @longtap="copy"
|
|
|
- :data-text="row.content">{{ row.content.replace(/^\s+|\s+$/g, '') }}</text>
|
|
|
- <text v-if="row.content == '正在思考中...'">{{ second }}s</text>
|
|
|
-
|
|
|
- <text class="flash" v-if="row.show_flash">│</text>
|
|
|
-
|
|
|
- <!-- <view class="u-flex align-center flex-wrap">
|
|
|
- <zero-markdown-view
|
|
|
-
|
|
|
- :themeColor="themeColor" :markdown="row.content"></zero-markdown-view>
|
|
|
- <text v-if="row.content == '正在思考中...'">{{ second }}s</text>
|
|
|
- <view style="margin-left: 20rpx;">
|
|
|
- <u-loading-icon v-if="row.show_flash" size="17"></u-loading-icon>
|
|
|
- </view>
|
|
|
-
|
|
|
- </view> -->
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- <view v-if="row.type == 2" class="bubble"
|
|
|
- style="display: block;position: relative;">
|
|
|
- <view class="u-flex align-center">
|
|
|
- <text style="margin-right: 20rpx;">{{row.content}}</text>
|
|
|
- <u-loading-icon size="17"></u-loading-icon>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- <view v-if="row.type == 3" class="bubbleimg">
|
|
|
- <image @click="preview(index)" :src="row.img" mode="aspectFill"></image>
|
|
|
- </view>
|
|
|
- <view v-if="row.done && !row.donec"
|
|
|
- class="tn-flex align-center justify-between operate">
|
|
|
- <view @click="copyText(index)" hover-class="hoversubmit"
|
|
|
- class="tn-flex align-center">
|
|
|
- <u-icon name="file-text" top="1" color="#68d7bb" size="20"></u-icon>
|
|
|
- <view class="duplicate">复制回答</view>
|
|
|
- </view>
|
|
|
- <!-- <view style="width: 50rpx;"></view> -->
|
|
|
- <view @click="createPoster(index)" hover-class="hoversubmit"
|
|
|
- class="tn-flex align-center">
|
|
|
- <u-icon name="share-square" top="1" color="#68d7bb" size="20"></u-icon>
|
|
|
- <view class="share">分享对话</view>
|
|
|
- </view>
|
|
|
-
|
|
|
- <view v-if="appInfo.is_vop&&appInfo.is_vop == 1" class="eliseaudio">
|
|
|
- <elise-audio @aittsjob="aittsjob" :audioId="'audioId'+index"
|
|
|
- :url="row.audiolink" audioColor="#68d7bb" :durationS="5"
|
|
|
- :content="row.content" :index="index" :cancel="cancel"></elise-audio>
|
|
|
- </view>
|
|
|
-
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </block>
|
|
|
- </view>
|
|
|
- </block>
|
|
|
- </view>
|
|
|
- <view class="bottomheight"></view>
|
|
|
- <view class="env"></view>
|
|
|
- </view>
|
|
|
- <view class="box-2">
|
|
|
- <view class="flex_col">
|
|
|
- <view class="flex_grow">
|
|
|
- <u--textarea height="45" @blur="blurinput" @focus="focusinput" fixed :showConfirmBar="false"
|
|
|
- v-model="content" :placeholder="paintingmode?'请输入您想绘制的图片内容...':'请输入您的问题...'"
|
|
|
- :maxlength="paintingmode?500:-1" border="none" :cursorSpacing="80"></u--textarea>
|
|
|
- </view>
|
|
|
- <u-icon v-if="appInfo.is_vop&&appInfo.is_vop == 1" @click="openmicrophone" name="mic" color="#ff9800"
|
|
|
- size="30"></u-icon>
|
|
|
- <button class="send"
|
|
|
- @click.prevent="paintingmode?sendpainting(content):send(content)">{{paintingmode?'绘制':'发送'}}</button>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- <u-popup :show="showexpand" zIndex="1" mode="bottom" bgColor="transparent" :overlay="false"
|
|
|
- @close="showexpand = false">
|
|
|
- <scroll-view class="scroll-view_H" scroll-x="true">
|
|
|
- <view class="expand u-flex">
|
|
|
- <block v-if="appInfo.number_member">
|
|
|
- <navigator @click="getroute"
|
|
|
- :url="isLogin ?'/pages/user/member/member?id=1':'/pages/user/signin'"
|
|
|
- class="surplus u-flex align-center" v-if="appInfo.number_member == 1">
|
|
|
- <u-icon name="question-circle-fill" color="#ff9800" size="18" top="1"></u-icon>
|
|
|
- <view class="item">
|
|
|
- {{appInfo.number_alias?appInfo.number_alias+':':'点数:'}}{{ userData.coin ? userData.coin : 0 }}
|
|
|
- </view>
|
|
|
- </navigator>
|
|
|
- </block>
|
|
|
- <block v-else>
|
|
|
- <navigator @click="getroute"
|
|
|
- :url="isLogin ?'/pages/user/member/member?id=1':'/pages/user/signin'"
|
|
|
- class="surplus u-flex align-center">
|
|
|
- <u-icon name="question-circle-fill" color="#ff9800" size="18" top="1"></u-icon>
|
|
|
- <view class="item">
|
|
|
- {{appInfo.number_alias?appInfo.number_alias+':':'点数:'}}{{ userData.coin ? userData.coin : 0 }}
|
|
|
- </view>
|
|
|
- </navigator>
|
|
|
- </block>
|
|
|
- <blcok v-if="!paintingmode">
|
|
|
- <navigator @click="getroute"
|
|
|
- :url="isLogin ?'/pages/user/member/member?id=2':'/pages/user/signin'"
|
|
|
- class="surplus u-flex align-center" v-if="appInfo.time_member && appInfo.time_member == 1">
|
|
|
- <u-icon name="clock-fill" color="#607d8b" size="18" top="1"></u-icon>
|
|
|
- <view class="item">
|
|
|
- 会员时长:{{ userData.is_validity == 1 ? Math.round((userData.vip_time - Date.parse(new Date()) / 1000) / (3600 * 24)) : 0 }}天
|
|
|
- </view>
|
|
|
- </navigator>
|
|
|
- </blcok>
|
|
|
-
|
|
|
- <!-- <view class="surplus">分享好友赚佣金</view> -->
|
|
|
- <view v-if="appInfo.is_aipainting&&appInfo.is_aipainting == 1" @click="switcmode"
|
|
|
- class="surplus u-flex align-center">
|
|
|
- <u-icon :name="paintingmode?'chat-fill':'edit-pen-fill'" color="#f44336" size="18"
|
|
|
- top="1"></u-icon>
|
|
|
- <view class="item">{{paintingmode?'聊天模式':'Ai绘画'}}</view>
|
|
|
- </view>
|
|
|
- <navigator @click="getroute" :url="isLogin ?'/pages/user/member/member?id=3':'/pages/user/signin'"
|
|
|
- class="surplus u-flex align-center">
|
|
|
- <u-icon name="more-circle-fill" color="#2979ff" size="18" top="1"></u-icon>
|
|
|
- <view class="item">免费领{{appInfo.number_alias?appInfo.number_alias:'点数'}}</view>
|
|
|
- </navigator>
|
|
|
- <view class="surplus u-flex align-center" style="background: #fff0;padding: 1rpx;">
|
|
|
-
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </scroll-view>
|
|
|
- </u-popup>
|
|
|
-
|
|
|
- <wike-skeleton count="4" type="user" v-if="homeTemplate.length === 0"></wike-skeleton>
|
|
|
-
|
|
|
-
|
|
|
- <u-no-network></u-no-network>
|
|
|
- <!-- <navigator v-if="is_commission == 1" class="neckBtn_view" url="/pages/user/commission/index">
|
|
|
- <text class="free_view">分享</text>
|
|
|
- 赚佣金
|
|
|
- </navigator> -->
|
|
|
- <u-popup :show="showPoster" mode="bottom" :round="10" safeAreaInsetTop @close="showPoster = false">
|
|
|
- <view class="poster">
|
|
|
- <wike-painter :board="posterObj" @success="posterSuccess" ref="painter"></wike-painter>
|
|
|
- <view class="footer-btn">
|
|
|
- <view class="" @click="showPoster = false">退出</view>
|
|
|
- <view class="save" @click="toSave">保存/分享</view>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </u-popup>
|
|
|
- <u-popup :show="soundrecording" mode="bottom" :round="20" safeAreaInsetTop @close="soundrecording = false">
|
|
|
-
|
|
|
- <view class="soundrecording u-flex justify-center">
|
|
|
- <view v-if="showlongpress" class="waveform">
|
|
|
- <image :src="'https://s1.voicecloud.cn/activity/imeVoiceShare/img/yuyin.gif'" mode="aspectFill">
|
|
|
- </image>
|
|
|
- </view>
|
|
|
- <view class="operation u-flex">
|
|
|
- <!-- <view class="affirm">
|
|
|
- <image src="/static/tf-speech-recognizer/cancel.png"></image>
|
|
|
- </view> -->
|
|
|
-
|
|
|
- <view @touchstart="startrecording" @touchend="stoprecording" class="longpress"
|
|
|
- hover-class="hoversubmit">
|
|
|
- <!-- <image disabled src="/static/tf-speech-recognizer/recording.png"></image> -->
|
|
|
- <u-icon name="mic" color="#fff" size="35"></u-icon>
|
|
|
- </view>
|
|
|
- <!-- <view class="affirm">
|
|
|
- <image src="/static/tf-speech-recognizer/confirm.png"></image>
|
|
|
- </view> -->
|
|
|
-
|
|
|
- </view>
|
|
|
- <view class="discriminate">长按识别语音</view>
|
|
|
- </view>
|
|
|
- </u-popup>
|
|
|
-
|
|
|
-
|
|
|
- <wike-loading-page :isLoading="isLoading"></wike-loading-page>
|
|
|
- <!-- 生成的图片 -->
|
|
|
- <u-popup type="center" mode="center">
|
|
|
- <view class="poster-img">
|
|
|
- <text @click="closePopup"></text>
|
|
|
- <!-- <image :src="path" mode="" @click="previewImg"></image> -->
|
|
|
- <!-- #ifdef H5 -->
|
|
|
- <view class="">长按图片保存到手机</view>
|
|
|
- <!-- #endif -->
|
|
|
- <!-- #ifndef H5 -->
|
|
|
- <view class="">点击图片保存到手机</view>
|
|
|
- <!-- #endif -->
|
|
|
- </view>
|
|
|
- </u-popup>
|
|
|
- <u-popup :show="switchmodel" @close="switchmodel = false" :round="15" closeable>
|
|
|
- <view class="select u-flex justify-center"><text>选择模型</text></view>
|
|
|
-
|
|
|
- <scroll-view scroll-y="true" :style="{ height: homeTemplate.mode.length > 6 ? 700 + 'rpx' : 'auto' }">
|
|
|
- <block v-for="(item, index) in homeTemplate.mode" :key="index">
|
|
|
- <view class="u-flex justify-between model_view">
|
|
|
- <u-avatar :src="item.img_file.path" shape="square" mode="aspectFill" size="60"></u-avatar>
|
|
|
- <view class="modelname">
|
|
|
- <view class="name">{{ item.name }}</view>
|
|
|
- <view class="modeldetails">{{ item.intro }}</view>
|
|
|
- </view>
|
|
|
- <view @click="onselect(index)" class="modelselect"
|
|
|
- :style="{ background: selectornot == index ? '#9e9e9e' : '' }">
|
|
|
- {{ selectornot == index ? '已选择' : '选择' }}
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </block>
|
|
|
- <view style="height: 30rpx;"></view>
|
|
|
-
|
|
|
- </scroll-view>
|
|
|
-
|
|
|
-
|
|
|
- </u-popup>
|
|
|
-
|
|
|
-
|
|
|
- <!-- <wike-tabbar :onTabbar="true" :isShowAnimate="true"></wike-tabbar> -->
|
|
|
- </view>
|
|
|
-</template>
|
|
|
-
|
|
|
-<script>
|
|
|
- // import { indexOf } from 'core-js/js/array';
|
|
|
- import {
|
|
|
- Socket
|
|
|
- } from 'dgram';
|
|
|
- import {
|
|
|
- mapMutations,
|
|
|
- mapActions,
|
|
|
- mapState,
|
|
|
- mapGetters
|
|
|
- } from 'vuex';
|
|
|
- import {
|
|
|
- apiurl
|
|
|
- } from '@/common/request/request';
|
|
|
- import MumuRecorder from '@/uni_modules/mumu-recorder/components/mumu-recorder/mumu-recorder.vue';
|
|
|
- import eliseAudio from '@/components/elise-audio/elise-audio.vue';
|
|
|
- // #ifdef H5
|
|
|
- import Recorder from 'recorder-core';
|
|
|
- import 'recorder-core/src/engine/wav'
|
|
|
- // #endif
|
|
|
-
|
|
|
- let down, delay;
|
|
|
- let interstitialAd = null,
|
|
|
- timer,
|
|
|
- time2,
|
|
|
- timingr;
|
|
|
- // const innerAudioContext = uni.createInnerAudioContext();
|
|
|
- const recorderManager = uni.getRecorderManager();
|
|
|
- export default {
|
|
|
- components: {
|
|
|
- MumuRecorder,
|
|
|
- eliseAudio,
|
|
|
- // #ifdef H5
|
|
|
- Recorder
|
|
|
- // #endif
|
|
|
- },
|
|
|
- data() {
|
|
|
- return {
|
|
|
- gpt_mode_index: 0,
|
|
|
- talkList: [
|
|
|
- // {
|
|
|
- // content: '正在思考中...',
|
|
|
- // type: 1,
|
|
|
- // toid: 1,
|
|
|
- // fromid: 6,
|
|
|
- // avatar: 'https://dev.iduomi.cc/addons/wike_chatgpt/public/static/storage/presets/mode/1.png',
|
|
|
- // nickname: '我',
|
|
|
- // },
|
|
|
- // {
|
|
|
- // content: '正在思考中,请你耐心的等待不要走开...',
|
|
|
- // type: 1,
|
|
|
- // toid: 1,
|
|
|
- // fromid: -1,
|
|
|
- // avatar: 'https://dev.iduomi.cc/addons/wike_chatgpt/public/static/storage/presets/mode/1.png',
|
|
|
- // nickname: '小助手',
|
|
|
- // show_flash: false,
|
|
|
- // audioId: 'audio1',
|
|
|
- // audiolink: 'https://dev.iduomi.cc/addons/ins_faceai/public/static/mobile/music/bubble.mp3',
|
|
|
- // done: true,
|
|
|
- // playback: false,
|
|
|
- // },
|
|
|
- // {
|
|
|
- // content: '正在思考中...',
|
|
|
- // type: 1,
|
|
|
- // toid: 1,
|
|
|
- // fromid: 6,
|
|
|
- // avatar: 'https://dev.iduomi.cc/addons/wike_chatgpt/public/static/storage/presets/mode/1.png',
|
|
|
- // nickname: '我',
|
|
|
- // },
|
|
|
- // {
|
|
|
- // content: '是大家好好甘肃省',
|
|
|
- // type: 1,
|
|
|
- // toid: 1,
|
|
|
- // fromid: -1,
|
|
|
- // avatar: 'https://dev.iduomi.cc/addons/wike_chatgpt/public/static/storage/presets/mode/1.png',
|
|
|
- // nickname: '小助手',
|
|
|
- // audioId: 'audio2',
|
|
|
- // audiolink: 'https://dev.iduomi.cc/addons/ins_faceai/public/static/mobile/music/redbone.mp3',
|
|
|
- // show_flash: false,
|
|
|
- // done: true,
|
|
|
- // playback: false,
|
|
|
- // },
|
|
|
- ],
|
|
|
- content: '',
|
|
|
- thecontent: '',
|
|
|
- image: '',
|
|
|
- hot: [],
|
|
|
- scrollTop: 999999,
|
|
|
- scrollAnimation: false,
|
|
|
- text1: ['您好,ChatGPT为您服务', '长按对话即可复制'],
|
|
|
- tobheight: 45,
|
|
|
- zhuangtai: 'AI智能问答机器人',
|
|
|
- platform: this.$platform.get(),
|
|
|
- // isFlash:false,
|
|
|
- showPoster: false,
|
|
|
- posterObj: {},
|
|
|
- switchmodel: false,
|
|
|
- selectornot: 0,
|
|
|
- modeldata: [],
|
|
|
- qrcode: '',
|
|
|
- haddressurl: '',
|
|
|
- haddresssk: '',
|
|
|
- scrollToView: '',
|
|
|
- question_index: 0,
|
|
|
- answer_index: 0,
|
|
|
- themeColor: '#007AFF',
|
|
|
- codeBgColor: '#26B3A0',
|
|
|
- showexpand: false,
|
|
|
-
|
|
|
- second: 15,
|
|
|
- showanswer: false,
|
|
|
- h5question: '',
|
|
|
- followornot: true,
|
|
|
- eights: false,
|
|
|
- spmplatform: 0,
|
|
|
- is_commission: 0,
|
|
|
- timing: 30,
|
|
|
- showcontext: true,
|
|
|
- showfetch: true,
|
|
|
- showdirect: true,
|
|
|
- //通道
|
|
|
- thoroughfare: 0,
|
|
|
-
|
|
|
- //绘画输入框
|
|
|
- drawcontent: '',
|
|
|
- //绘画模式
|
|
|
- paintingmode: false,
|
|
|
- //是否在绘画
|
|
|
- showdraw: false,
|
|
|
- //绘画id
|
|
|
- uuid: '',
|
|
|
- //绘画列表
|
|
|
- paintinglist: [],
|
|
|
-
|
|
|
- //弹出录音
|
|
|
- soundrecording: false,
|
|
|
- //是否长按
|
|
|
- showlongpress: false,
|
|
|
- //音频
|
|
|
- innerAudioContextsrc: '',
|
|
|
- //取消音频加载
|
|
|
- cancel: false,
|
|
|
- //第一次录
|
|
|
- firstrecording: 0,
|
|
|
- isLoading: true
|
|
|
- };
|
|
|
- },
|
|
|
- computed: {
|
|
|
- ...mapGetters(['appInfo', 'isLogin', 'userInfo', 'homeTemplate', 'userData'])
|
|
|
- },
|
|
|
- mounted() {
|
|
|
-
|
|
|
- },
|
|
|
- onReady() {
|
|
|
- let that = this;
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- clearTimeout(timer);
|
|
|
- // 在适合的场景显示插屏广告
|
|
|
- timer = setTimeout(function() {
|
|
|
- // 在页面onLoad回调事件中创建插屏广告实例
|
|
|
- if (wx.createInterstitialAd && that.appInfo.interstitial_status == 1) {
|
|
|
- interstitialAd = wx.createInterstitialAd({
|
|
|
- adUnitId: that.appInfo.interstitial_id
|
|
|
- });
|
|
|
- interstitialAd.onLoad(() => {});
|
|
|
- interstitialAd.onError(err => {});
|
|
|
- interstitialAd.onClose(() => {
|
|
|
- if (that.appInfo.interstitial_infinite_status == 1) {
|
|
|
- that.showInterstitial();
|
|
|
- }
|
|
|
- });
|
|
|
- interstitialAd.show().catch(err => {});
|
|
|
- }
|
|
|
- }, 4000);
|
|
|
- // #endif
|
|
|
- },
|
|
|
-
|
|
|
- onLoad() {
|
|
|
- var that = this;
|
|
|
- if (that.platform == 'wxMiniProgram') {
|
|
|
- var menumtop = uni.getMenuButtonBoundingClientRect().top - uni.getSystemInfoSync().statusBarHeight;
|
|
|
- var paddingtop = uni.getSystemInfoSync().statusBarHeight + menumtop;
|
|
|
- that.tobheight = menumtop + paddingtop + uni.getMenuButtonBoundingClientRect().height;
|
|
|
- }
|
|
|
- if (that.$Route.query.draw) {
|
|
|
- that.paintingmode = true
|
|
|
- let pai = {
|
|
|
- type: 1,
|
|
|
- toid: 1,
|
|
|
- fromid: -1,
|
|
|
- avatar: that.appInfo.aipainting_avatar_path ? that.appInfo.aipainting_avatar_path :
|
|
|
- 'https://img0.baidu.com/it/u=2119417517,3891184201&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
|
|
|
- nickname: that.appInfo.aipainting_name ? that.appInfo.aipainting_name : 'Ai绘画',
|
|
|
- content: that.appInfo.aipainting_greetings ? that.appInfo.aipainting_greetings : '欢迎来的Ai绘画的世界',
|
|
|
- show_flash: false,
|
|
|
- done: true,
|
|
|
- donec: true
|
|
|
- };
|
|
|
- that.paintinglist.push(pai)
|
|
|
- }
|
|
|
- if (this.$Route.query.question) {
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- this.send(this.$Route.query.question);
|
|
|
- // #endif
|
|
|
- // #ifdef H5
|
|
|
- this.h5question = this.$Route.query.question;
|
|
|
- this.aigetAddress();
|
|
|
- // #endif
|
|
|
- }
|
|
|
- this.spmplatform = ['H5', 'wxOfficialAccount', 'wxMiniProgram', 'App'].indexOf(this.platform) + 1;
|
|
|
- this.followornot = true;
|
|
|
- // #ifdef H5
|
|
|
- this.toaigetAddress();
|
|
|
- // #endif
|
|
|
- this.isLoading = false
|
|
|
- this.initGpt();
|
|
|
- this.getCommissionSetting()
|
|
|
- this.onmessage();
|
|
|
- uni.onSocketError(function(res) {});
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- let self = this;
|
|
|
- recorderManager.onStop(function(res) {
|
|
|
- self.aiaudiocheck(res.tempFilePath)
|
|
|
- });
|
|
|
- // #endif
|
|
|
- },
|
|
|
- onShow: function() {
|
|
|
- if (this.isLogin) {
|
|
|
- this.getUserData();
|
|
|
- }
|
|
|
- },
|
|
|
- onUnload() {
|
|
|
- this.followornot = false;
|
|
|
- clearInterval(time2);
|
|
|
- clearTimeout(timingr);
|
|
|
- uni.$emit('stop')
|
|
|
- if (this.$ws.socketStatus()) {
|
|
|
- this.$ws.completeClose();
|
|
|
- }
|
|
|
- },
|
|
|
- onHide() {
|
|
|
- if (this.$ws.socketStatus()) {
|
|
|
- this.$ws.completeClose();
|
|
|
- }
|
|
|
- },
|
|
|
- onReachBottom() {},
|
|
|
- methods: {
|
|
|
- ...mapActions(['getUserInfo', 'showAuthModal', 'getUserData']),
|
|
|
- switcmode() {
|
|
|
- this.paintingmode = !this.paintingmode
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- this.zhuangtai = this.paintingmode ? 'Ai绘画' : (this.appInfo.site_name ? this.appInfo.site_name :
|
|
|
- 'Ai问答机器人');
|
|
|
- // #endif
|
|
|
- // #ifdef H5
|
|
|
- uni.setNavigationBarTitle({
|
|
|
- title: this.appInfo.site_name ? this.appInfo.site_name : 'Ai问答机器人'
|
|
|
- });
|
|
|
- this.zhuangtai = this.paintingmode ? 'Ai绘画' : (this.homeTemplate.mode.length ? this.homeTemplate.mode[this
|
|
|
- .selectornot].name : 'Ai问答机器人');
|
|
|
- // #endif
|
|
|
- if (this.paintinglist.length == 0) {
|
|
|
- let pai = {
|
|
|
- type: 1,
|
|
|
- toid: 1,
|
|
|
- fromid: -1,
|
|
|
- avatar: this.appInfo.aipainting_avatar_path ? this.appInfo.aipainting_avatar_path :
|
|
|
- 'https://img0.baidu.com/it/u=2119417517,3891184201&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
|
|
|
- nickname: this.appInfo.aipainting_name ? this.appInfo.aipainting_name : 'Ai绘画',
|
|
|
- content: this.appInfo.aipainting_greetings ? this.appInfo.aipainting_greetings : '欢迎来的Ai绘画的世界',
|
|
|
- show_flash: false,
|
|
|
- done: true,
|
|
|
- donec: true
|
|
|
- };
|
|
|
- this.paintinglist.push(pai)
|
|
|
- }
|
|
|
- this.Audio()
|
|
|
- this.$nextTick(() => {
|
|
|
- // 清空内容框中的内容
|
|
|
- this.content = '';
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 300
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
- //开始录音的方法
|
|
|
- uploadRecord() {
|
|
|
- // 开始录音
|
|
|
- if (!this.rec) {
|
|
|
- // console.log('未打开录音权限');
|
|
|
- uni.showToast({
|
|
|
- title: '未打开录音权限'
|
|
|
- })
|
|
|
- return;
|
|
|
- }
|
|
|
- this.rec.start();
|
|
|
- this.showlongpress = true
|
|
|
- },
|
|
|
- //结束录音的方法
|
|
|
- h5btn_sub_stop() {
|
|
|
- // console.log(123123)
|
|
|
- var This = this;
|
|
|
- var rec = This.rec;
|
|
|
- This.rec = null;
|
|
|
- if (!rec) {
|
|
|
- // This.reclog("未打开录音", 1);
|
|
|
- uni.showToast({
|
|
|
- title: '未打开录音'
|
|
|
- })
|
|
|
- return;
|
|
|
- }
|
|
|
- rec.stop(function(blob, duration) {
|
|
|
- var reader = new FileReader();
|
|
|
- reader.addEventListener("load", function() {
|
|
|
- // console.log(reader)
|
|
|
- if (reader.result.length > 100) {
|
|
|
- This.he_show = true
|
|
|
- }
|
|
|
- }, false);
|
|
|
- reader.readAsDataURL(blob);
|
|
|
- // console.log(blob,duration,'blob')
|
|
|
- let blobURL = window.URL.createObjectURL(blob)
|
|
|
- console.log(blobURL, '--------')
|
|
|
- This.aiaudiocheck(blobURL)
|
|
|
- }, function(s) {
|
|
|
- // This.reclog("结束出错:" + s, 1);
|
|
|
- // uni.showToast({
|
|
|
- // title: '录音失败',
|
|
|
- // icon: 'none'
|
|
|
- // })
|
|
|
- This.showlongpress = false
|
|
|
- }, true); //自动close
|
|
|
- },
|
|
|
-
|
|
|
- getroute() {
|
|
|
- if (!this.isLogin) {
|
|
|
- uni.setStorageSync('route', '/pages/chat/chat');
|
|
|
- }
|
|
|
- this.Audio()
|
|
|
- },
|
|
|
- Audio() {
|
|
|
- uni.$emit('stop')
|
|
|
- },
|
|
|
- aiaudiocheck(e) {
|
|
|
- var that = this;
|
|
|
- // console.log(e, '5');
|
|
|
- uni.showLoading({
|
|
|
- title: '识别中'
|
|
|
- })
|
|
|
- uni.uploadFile({
|
|
|
- url: apiurl('ai/recognizer'),
|
|
|
- filePath: e,
|
|
|
- name: 'speech',
|
|
|
- header: {
|
|
|
- platform: that.platform
|
|
|
- },
|
|
|
- success: res2 => {
|
|
|
- // console.log(res2.data);
|
|
|
- uni.hideLoading();
|
|
|
- let a = JSON.parse(res2.data);
|
|
|
- // console.log(a);
|
|
|
- if (a.code == 0) {
|
|
|
- uni.showToast({
|
|
|
- title: '识别成功',
|
|
|
- })
|
|
|
- // console.log(a.data.result[0]);
|
|
|
-
|
|
|
- this.content += a.data.result[0]
|
|
|
- this.thecontent += a.data.result[0]
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: '识别失败',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- openmicrophone() {
|
|
|
- var that = this;
|
|
|
- this.Audio()
|
|
|
- this.cancel = true
|
|
|
- if (!this.isLogin) {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages/user/signin'
|
|
|
- });
|
|
|
- uni.setStorageSync('route', '/pages/chat/chat');
|
|
|
- return;
|
|
|
- }
|
|
|
- // #ifdef H5
|
|
|
-
|
|
|
- let This = this;
|
|
|
- let rec = This.rec = Recorder({
|
|
|
- type: "wav", // wav格式, 需要使用的type类型,需提前把格式支持文件加载进来
|
|
|
- bitRate: 16, // 比特率kbps,越大音质越好
|
|
|
- sampleRate: 16000, // 采样率hz,每秒音波震动次数,越大细节越丰富
|
|
|
- onProcess: function(buffers, powerLevel, duration, sampleRate) {
|
|
|
- if (duration > 60000) {
|
|
|
- This.h5btn_sub_stop()
|
|
|
- This.showlongpress = false
|
|
|
- This.soundrecording = false
|
|
|
- }
|
|
|
- } //录音实时回调,大约1秒调用12次回调
|
|
|
- });
|
|
|
- rec.open(function() {
|
|
|
- // console.log('打开成功:');
|
|
|
- // 渲染音频波形图
|
|
|
- This.soundrecording = true
|
|
|
- }, function(msg, isUserNotAllow) {
|
|
|
- uni.showToast({
|
|
|
- title: '麦克风已拒绝打开',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- // 浏览器不支持录音、用户拒绝麦克风权限、或者非安全环境(非https、file等
|
|
|
- console.log((isUserNotAllow ? "UserNotAllow," : "") + "无法录音:" + msg);
|
|
|
- });
|
|
|
-
|
|
|
- // #endif
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- uni.getSetting({
|
|
|
- success: (res) => {
|
|
|
- if (res.authSetting['scope.record'] == false) {
|
|
|
- uni.showModal({
|
|
|
- confirmText: '去打开',
|
|
|
- content: '请先开启麦克风授权',
|
|
|
- title: '提示',
|
|
|
- confirmColor: '#26B3A0',
|
|
|
- success(res) {
|
|
|
- // console.log(res);
|
|
|
- if (res.confirm) {
|
|
|
- uni.openSetting({
|
|
|
- success: function(ress) {
|
|
|
- console.log(ress);
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- return false
|
|
|
- } else {
|
|
|
- uni.authorize({
|
|
|
- scope: 'scope.record',
|
|
|
- success: (res) => {
|
|
|
- that.soundrecording = true
|
|
|
- },
|
|
|
- fail: (res) => {
|
|
|
- uni.showToast({
|
|
|
- title: '麦克风打开失败',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- },
|
|
|
- })
|
|
|
- // #endif
|
|
|
-
|
|
|
- },
|
|
|
- startrecording() {
|
|
|
- console.log('开始录音');
|
|
|
- // #ifdef H5
|
|
|
-
|
|
|
- // this.$refs.recorder.start()
|
|
|
- this.uploadRecord()
|
|
|
- // #endif
|
|
|
-
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- recorderManager.start({
|
|
|
- sampleRate: 16000,
|
|
|
- numberOfChannels: 1,
|
|
|
- format: 'aac',
|
|
|
- duration: 60000
|
|
|
- })
|
|
|
- this.showlongpress = true
|
|
|
- // #endif
|
|
|
-
|
|
|
- },
|
|
|
- stoprecording() {
|
|
|
- console.log('停止录音');
|
|
|
- // #ifdef H5
|
|
|
- // this.$refs.recorder.stop()
|
|
|
- this.h5btn_sub_stop()
|
|
|
- // #endif
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
-
|
|
|
-
|
|
|
- recorderManager.stop();
|
|
|
- // #endif
|
|
|
- this.showlongpress = false
|
|
|
- this.soundrecording = false
|
|
|
- },
|
|
|
- aittsjob(res) {
|
|
|
- // console.log(res);
|
|
|
- this.talkList[res.index].audiolink = res.speech_url
|
|
|
- // console.log(this.talkList);
|
|
|
- // this.context = uni.createInnerAudioContext();
|
|
|
- // this.context.src = res.speech_url;
|
|
|
- // this.context.play()
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- sendpainting(e) {
|
|
|
- if (!this.isLogin) {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages/user/signin'
|
|
|
- });
|
|
|
- uni.setStorageSync('route', '/pages/chat/chat');
|
|
|
- return;
|
|
|
- }
|
|
|
- if (this.showdraw) {
|
|
|
- uni.showToast({
|
|
|
- title: '正在绘制中,请等待绘制完成',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!e) {
|
|
|
- uni.showToast({
|
|
|
- title: '请输入文本',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return;
|
|
|
- }
|
|
|
- uni.showLoading({})
|
|
|
- this.$http('ai.painting', {
|
|
|
- prompt: e
|
|
|
- }).then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- uni.hideLoading();
|
|
|
- this.uuid = res.data.Uuid
|
|
|
- this.showdraw = true
|
|
|
- this.showTask()
|
|
|
-
|
|
|
- let data = {
|
|
|
- id: new Date().getTime(),
|
|
|
- content: e,
|
|
|
- type: 1,
|
|
|
- toid: this.toid,
|
|
|
- fromid: this.userInfo.id,
|
|
|
- avatar: this.userInfo.avatar,
|
|
|
- nickname: this.userInfo.nickname,
|
|
|
- done: true
|
|
|
- };
|
|
|
- this.paintinglist.push(data);
|
|
|
- let chat_data = {
|
|
|
- id: new Date().getTime(),
|
|
|
- content: '正在绘制中,请等待...',
|
|
|
- type: 2,
|
|
|
- toid: this.toid,
|
|
|
- fromid: -1,
|
|
|
- avatar: this.appInfo.aipainting_avatar_path ? this.appInfo
|
|
|
- .aipainting_avatar_path :
|
|
|
- 'https://img0.baidu.com/it/u=2119417517,3891184201&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
|
|
|
- nickname: this.appInfo.aipainting_name ? this.appInfo
|
|
|
- .aipainting_name : 'Ai绘画',
|
|
|
- };
|
|
|
- this.paintinglist.push(chat_data);
|
|
|
- this.getUserData();
|
|
|
- this.$nextTick(() => {
|
|
|
- // 清空内容框中的内容
|
|
|
- this.content = '';
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 300
|
|
|
- });
|
|
|
- });
|
|
|
- } else {
|
|
|
- this.uuid = ''
|
|
|
- this.showdraw = false
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- showTask() {
|
|
|
- this.$http('ai.showTask', {
|
|
|
- uuid: this.uuid
|
|
|
- }).then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- if (res.data == 'wait') {
|
|
|
- setTimeout(() => {
|
|
|
- this.showTask()
|
|
|
- }, 1500);
|
|
|
- return;
|
|
|
- }
|
|
|
- uni.showToast({
|
|
|
- title: '绘制完成'
|
|
|
- })
|
|
|
- this.paintinglist.pop();
|
|
|
- let chat_data = {
|
|
|
- id: new Date().getTime(),
|
|
|
- img: res.data,
|
|
|
- type: 3,
|
|
|
- toid: this.toid,
|
|
|
- fromid: -1,
|
|
|
- avatar: this.appInfo.aipainting_avatar_path ? this.appInfo
|
|
|
- .aipainting_avatar_path :
|
|
|
- 'https://img0.baidu.com/it/u=2119417517,3891184201&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
|
|
|
- nickname: this.appInfo.aipainting_name ? this.appInfo
|
|
|
- .aipainting_name : 'Ai绘画',
|
|
|
- };
|
|
|
- this.paintinglist.push(chat_data);
|
|
|
- this.showdraw = false
|
|
|
- this.$nextTick(() => {
|
|
|
- // 清空内容框中的内容
|
|
|
- this.content = '';
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 300
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- } else {
|
|
|
- this.uuid = ''
|
|
|
- this.showdraw = false
|
|
|
- this.paintinglist.pop();
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- initGpt() {
|
|
|
- // console.log(this.homeTemplate.mode);
|
|
|
-
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- this.zhuangtai = this.paintingmode ? 'Ai绘画' : (this.appInfo.site_name ? this.appInfo
|
|
|
- .site_name :
|
|
|
- 'Ai问答机器人');
|
|
|
-
|
|
|
- // #endif
|
|
|
- // #ifdef H5
|
|
|
- uni.setNavigationBarTitle({
|
|
|
- title: this.appInfo.site_name ? this.appInfo.site_name : 'Ai问答机器人'
|
|
|
- });
|
|
|
- this.zhuangtai = this.paintingmode ? 'Ai绘画' : (this.homeTemplate.mode.length ? this
|
|
|
- .homeTemplate.mode[this
|
|
|
- .selectornot].name : 'Ai问答机器人');
|
|
|
- // #endif
|
|
|
-
|
|
|
- this.commonqrcodePath();
|
|
|
-
|
|
|
- //
|
|
|
- // this.onmessage();
|
|
|
- },
|
|
|
- touchmove() {
|
|
|
- this.followornot = false;
|
|
|
-
|
|
|
- },
|
|
|
- getCommissionSetting() {
|
|
|
- this.$http('conf.getGroupConf', {
|
|
|
- group: 'system.commission'
|
|
|
- }).then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- this.is_commission = res.data.is_commission
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- //wss返回数据
|
|
|
- onmessage() {
|
|
|
- let that = this,
|
|
|
- message = '';
|
|
|
- uni.onSocketMessage(function(res) {
|
|
|
- that.showanswer = true;
|
|
|
- let a = res.data;
|
|
|
- if (a.indexOf('wike_err:') != -1) {
|
|
|
- uni.showToast({
|
|
|
- title: '报错:' + a,
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- that.talkList[that.question_index].show_flash = false;
|
|
|
- that.talkList[that.question_index].content = '报错:' + a;
|
|
|
- that.talkList[that.question_index].done = true;
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!that.$ws.socketStatus()) {
|
|
|
- uni.showToast({
|
|
|
- title: '连接错误',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- that.talkList[that.question_index].show_flash = false;
|
|
|
- that.talkList[that.question_index].content = '报错';
|
|
|
- return;
|
|
|
- }
|
|
|
- if (a.indexOf('[DONE]') != -1) {
|
|
|
- that.$nextTick(() => {
|
|
|
- that.timing = that.appInfo.text_expire_time ? Number(that
|
|
|
- .appInfo
|
|
|
- .text_expire_time) : 30;
|
|
|
- that.showcontext = true;
|
|
|
- that.getcontext()
|
|
|
- that.talkList[that.question_index].show_flash = false;
|
|
|
- that.talkList[that.question_index].done = true;
|
|
|
- that.record(that.talkList[that.answer_index].content, message);
|
|
|
- message = '';
|
|
|
- if (that.$ws.socketStatus()) {
|
|
|
- that.$ws.completeClose();
|
|
|
- }
|
|
|
- that.$nextTick(() => {
|
|
|
- if (that.followornot) {
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 0
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- });
|
|
|
- } else {
|
|
|
-
|
|
|
-
|
|
|
- var b = a.split('data:').filter(w => !!w.trim() && w.trim() !== '[DONE]');
|
|
|
- var c = '';
|
|
|
- b.map(w => JSON.parse(w))
|
|
|
- .map(w => (c = w.choices[0].delta.content))
|
|
|
- .join('');
|
|
|
-
|
|
|
-
|
|
|
- if (that.followornot) {
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 0
|
|
|
- });
|
|
|
- }
|
|
|
- // });
|
|
|
- if (c != undefined) {
|
|
|
- message += c;
|
|
|
- }
|
|
|
-
|
|
|
- if (that.thoroughfare == 1) {
|
|
|
- that.talkList[that.question_index].content = message;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- },
|
|
|
- getcontext() {
|
|
|
- var that = this;
|
|
|
- that.timing--;
|
|
|
- // console.log(that.timing);
|
|
|
- if (that.timing == 0) {
|
|
|
- // console.log('关闭上下文定时器');
|
|
|
- clearTimeout(timingr);
|
|
|
- that.timing = that.appInfo.text_expire_time ? Number(that.appInfo.text_expire_time) :
|
|
|
- 30;
|
|
|
- // console.log('取消下文关联');
|
|
|
- that.showcontext = false
|
|
|
- return;
|
|
|
- }
|
|
|
- timingr = setTimeout(() => {
|
|
|
- that.getcontext();
|
|
|
- }, 1000);
|
|
|
- },
|
|
|
- waitWss() {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- uni.onSocketOpen(function(res) {
|
|
|
-
|
|
|
- // console.log('WebSocket连接已打开!');
|
|
|
- resolve(1);
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
- waitClose() {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- uni.onSocketClose(function(res) {
|
|
|
- // console.log('WebSocket 已关闭!');
|
|
|
- resolve(1);
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
- aigetAddress() {
|
|
|
- var that = this;
|
|
|
- that.$http('ai.getAddress').then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- that.haddressurl = res.data.url;
|
|
|
- that.haddresssk = res.data.sk;
|
|
|
- // that.hAddress = res.data
|
|
|
- that.send(that.h5question);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- toaigetAddress() {
|
|
|
- var that = this;
|
|
|
- that.$http('ai.getAddress').then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- that.haddressurl = res.data.url;
|
|
|
- that.haddresssk = res.data.sk;
|
|
|
- // that.hAddress = res.data
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- commonqrcodePath() {
|
|
|
- let spm = this.userInfo.id + '.1.0.' + this.spmplatform + '.1';
|
|
|
- this.$http('common.qrcodePath', {
|
|
|
- spm: spm
|
|
|
- }).then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- this.qrcode = res.data;
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- getImage() {
|
|
|
- uni.switchTab({
|
|
|
- url: '/pages/user/user'
|
|
|
- });
|
|
|
- },
|
|
|
- copy(e) {
|
|
|
- var that = this;
|
|
|
- var text = e.currentTarget.dataset.text;
|
|
|
- uni.setClipboardData({
|
|
|
- data: text,
|
|
|
- success(res) {
|
|
|
- uni.getClipboardData({
|
|
|
- success(res) {}
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- changeinput(e) {},
|
|
|
- focusinput() {
|
|
|
- this.showexpand = false;
|
|
|
- this.$nextTick(() => {
|
|
|
-
|
|
|
-
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 300
|
|
|
- });
|
|
|
- });
|
|
|
- if (!this.isLogin) {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages/user/signin'
|
|
|
- });
|
|
|
- uni.setStorageSync('route', '/pages/chat/chat');
|
|
|
- return;
|
|
|
- }
|
|
|
- },
|
|
|
- blurinput() {
|
|
|
- // this.showexpand = true;
|
|
|
- },
|
|
|
- commontemplate() {
|
|
|
- this.$store.dispatch('getTemplate');
|
|
|
- },
|
|
|
- //敏感词过滤检测
|
|
|
- getcheckText() {
|
|
|
- var that = this;
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- that.$http('ai.checkText', {
|
|
|
- prompt: that.thecontent
|
|
|
- }).then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- resolve(1);
|
|
|
- } else {
|
|
|
- let data = {
|
|
|
- id: new Date().getTime(),
|
|
|
- content: '该问题已被隐藏!',
|
|
|
- type: 1,
|
|
|
- toid: that.toid,
|
|
|
- fromid: that.userInfo.id,
|
|
|
- avatar: that.userInfo.avatar,
|
|
|
- nickname: that.userInfo.nickname,
|
|
|
- done: true
|
|
|
- };
|
|
|
- that.talkList.push(data);
|
|
|
- let chat_data = {
|
|
|
- id: new Date().getTime(),
|
|
|
- content: res.msg,
|
|
|
- type: 1,
|
|
|
- toid: this.toid,
|
|
|
- fromid: -1,
|
|
|
- avatar: this.homeTemplate.mode[this.selectornot]
|
|
|
- .img_file.path,
|
|
|
- nickname: this.homeTemplate.mode[this.selectornot]
|
|
|
- .name,
|
|
|
- show_flash: false,
|
|
|
- done: true,
|
|
|
- donec: true
|
|
|
- };
|
|
|
- this.talkList.push(chat_data);
|
|
|
- this.$nextTick(() => {
|
|
|
- // 清空内容框中的内容
|
|
|
- this.content = '';
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 300
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- })
|
|
|
- });
|
|
|
- },
|
|
|
- // 发送信息
|
|
|
- async send(e) {
|
|
|
- let that = this;
|
|
|
- // console.log('1');
|
|
|
- if (!this.isLogin) {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages/user/signin'
|
|
|
- });
|
|
|
- uni.setStorageSync('route', '/pages/chat/chat');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (that.appInfo.time_member && that.appInfo.time_member == 1) {
|
|
|
- if (that.userData.is_validity == 0) {
|
|
|
- if (that.userData.coin <= 0) {
|
|
|
- var alias = that.appInfo.number_alias ? that.appInfo.number_alias : '点数';
|
|
|
- uni.showModal({
|
|
|
- confirmText: '立即获取',
|
|
|
- confirmColor: '#26B3A0',
|
|
|
- content: '您的提问' + alias + '/会员时长不足',
|
|
|
- title: '提示',
|
|
|
- success(res) {
|
|
|
- if (res.confirm) {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages/user/member/member'
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (that.userData.coin <= 0) {
|
|
|
- var alias = that.appInfo.number_alias ? that.appInfo.number_alias : '点数';
|
|
|
- uni.showModal({
|
|
|
- confirmText: '立即获取',
|
|
|
- confirmColor: '#26B3A0',
|
|
|
- content: '您的提问' + alias + '/会员时长不足',
|
|
|
- title: '提示',
|
|
|
- success(res) {
|
|
|
- if (res.confirm) {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages/user/member/member'
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!this.appInfo.sk && this.appInfo.connect_lines && this.appInfo.connect_lines ==
|
|
|
- 2) {
|
|
|
- uni.showToast({
|
|
|
- title: '未正确配置key',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (that.talkList.length > 1 && !that.talkList[that.talkList.length - 1].done) {
|
|
|
- uni.showToast({
|
|
|
- title: '正在输入回答,请等待输入完成',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!e) {
|
|
|
- uni.showToast({
|
|
|
- title: '请输入有效的内容',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- this.thecontent = e;
|
|
|
- // console.log('提问内容检测');
|
|
|
- uni.showLoading({})
|
|
|
- // #ifdef H5
|
|
|
- let check = this.appInfo.is_h5_filter && this.appInfo.is_h5_filter == 1 ? await this
|
|
|
- .getcheckText() :
|
|
|
- 1;
|
|
|
- // #endif
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- let check = await this.getcheckText();
|
|
|
- // #endif
|
|
|
- if (check == 1) {
|
|
|
- uni.hideLoading();
|
|
|
- // 将当前发送信息 添加到消息列表。
|
|
|
- let data = {
|
|
|
- id: new Date().getTime(),
|
|
|
- content: e,
|
|
|
- type: 1,
|
|
|
- toid: this.toid,
|
|
|
- fromid: this.userInfo.id,
|
|
|
- avatar: this.userInfo.avatar,
|
|
|
- nickname: this.userInfo.nickname,
|
|
|
- done: true
|
|
|
- };
|
|
|
- this.talkList.push(data);
|
|
|
-
|
|
|
- let chat_data = {
|
|
|
- id: new Date().getTime(),
|
|
|
- content: '正在思考中...',
|
|
|
- type: 1,
|
|
|
- toid: this.toid,
|
|
|
- fromid: -1,
|
|
|
- avatar: this.homeTemplate.mode[this.selectornot].img_file.path,
|
|
|
- nickname: this.homeTemplate.mode[this.selectornot].name,
|
|
|
- show_flash: true,
|
|
|
- done: false
|
|
|
- };
|
|
|
- this.talkList.push(chat_data);
|
|
|
- this.$nextTick(() => {
|
|
|
- // 清空内容框中的内容
|
|
|
- this.content = '';
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 99999,
|
|
|
- duration: 300
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- // 重置是否来数据的判断
|
|
|
- this.showanswer = false;
|
|
|
- // this.show_flash = true;
|
|
|
- // 允许跟随到最底部
|
|
|
- this.followornot = true;
|
|
|
- // 关闭重置上下文的30秒倒计时
|
|
|
- clearTimeout(timingr);
|
|
|
- this.timing = 30;
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- // 判断是否连接wss
|
|
|
- if (!this.$ws.socketStatus()) {
|
|
|
- // 重置倒计时15秒后的wss未返数据走直连模式
|
|
|
- this.showdirect = true;
|
|
|
- // 重置倒计时8秒后wss未返数据走fetch模式
|
|
|
- this.showfetch = true;
|
|
|
- // console.log('15秒倒计时开始');
|
|
|
- this.countdown();
|
|
|
- // console.log('重连wss');
|
|
|
- this.$ws.init();
|
|
|
- let re = await this.waitWss();
|
|
|
- if (re == 1) {
|
|
|
- // console.log('等待wss打开后执行');
|
|
|
- this.getChatGPT(e);
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- // 关闭wss
|
|
|
- if (this.$ws.socketStatus()) {
|
|
|
- that.$ws.completeClose();
|
|
|
- }
|
|
|
- // console.log('15秒倒计时开始');
|
|
|
- this.countdown();
|
|
|
- // #ifdef H5
|
|
|
- // console.log('倒计时8秒后不再走fetch模式');
|
|
|
- // that.showfetch = false;
|
|
|
- // console.log('走方案2');
|
|
|
- // that.fetchmodel(that.thecontent);
|
|
|
- // #endif
|
|
|
-
|
|
|
- let answer = '';
|
|
|
- if (that.talkList.length > 2 && that.showcontext) {
|
|
|
- // answer = that.talkList[that.talkList.length - 4].content + '\n' + that
|
|
|
- // .talkList[that
|
|
|
- // .talkList.length - 3].content;
|
|
|
- answer = that.talkList[that.talkList.length - 3].content;
|
|
|
- }
|
|
|
- // console.log(answer);
|
|
|
- // console.log('倒计时15秒后不再走直连模式');
|
|
|
- this.showdirect = false;
|
|
|
- this.directGpt(that.thecontent, answer);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // #endif
|
|
|
-
|
|
|
- // #ifdef H5
|
|
|
- // console.log('15秒倒计时开始');
|
|
|
- this.countdown();
|
|
|
- // console.log('倒计时8秒后不再走fetch模式');
|
|
|
- that.showfetch = false;
|
|
|
- // console.log('走方案2');
|
|
|
- that.fetchmodel(that.thecontent);
|
|
|
- // #endif
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- //定时器
|
|
|
- countdown() {
|
|
|
- var that = this;
|
|
|
- that.second--;
|
|
|
-
|
|
|
- if (that.second == 0) {
|
|
|
- // console.log('15秒定时结束');
|
|
|
- // console.log(that.question_index);
|
|
|
- if (!that.showanswer) {
|
|
|
- let answer = '';
|
|
|
- if (that.talkList.length > 2 && that.showcontext) {
|
|
|
- // answer = that.talkList[that.question_index - 3].content + '\n' + that.talkList[
|
|
|
- // that.talkList
|
|
|
- // .length - 3].content;
|
|
|
- answer = that.talkList[that.talkList.length - 3].content;
|
|
|
- // console.log(answer);
|
|
|
- }
|
|
|
- uni.showLoading({
|
|
|
- title: '加载中...'
|
|
|
- });
|
|
|
- // clearTimeout(down);
|
|
|
- // console.log('关闭定时器');
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- if (that.$ws.socketStatus()) {
|
|
|
- // console.log('关闭直连');
|
|
|
- that.$ws.completeClose();
|
|
|
- }
|
|
|
- // #endif
|
|
|
- if (that.showdirect) {
|
|
|
- setTimeout(() => {
|
|
|
- uni.hideLoading();
|
|
|
- that.second = 15;
|
|
|
- that.directGpt(that.thecontent, answer);
|
|
|
- }, 1500);
|
|
|
- } else {
|
|
|
- uni.hideLoading();
|
|
|
- that.second = 15;
|
|
|
- if (that.talkList[that.question_index].content == '正在思考中...') {
|
|
|
- that.talkList[that.question_index].content = '请等我几秒钟,正在输入回答...';
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- return;
|
|
|
- } else {
|
|
|
- that.second = 15;
|
|
|
- clearTimeout(down);
|
|
|
- // console.log('关闭定时器');
|
|
|
- }
|
|
|
- // clearTimeout(down);
|
|
|
- return;
|
|
|
- }
|
|
|
- // #ifdef H5
|
|
|
- if (that.second == 8 && that.showfetch) {
|
|
|
- // console.log('8秒定时结束');
|
|
|
- if (!that.showanswer) {
|
|
|
- if (that.$ws.socketStatus()) {
|
|
|
- that.$ws.completeClose();
|
|
|
- // console.log('关闭直连');
|
|
|
- }
|
|
|
- // if (that.showfetch) {
|
|
|
- that.fetchmodel(that.thecontent);
|
|
|
- // }
|
|
|
-
|
|
|
- } else {
|
|
|
- that.second = 15;
|
|
|
- clearTimeout(down);
|
|
|
- // console.log('关闭定时器');
|
|
|
- }
|
|
|
- }
|
|
|
- // #endif
|
|
|
-
|
|
|
- down = setTimeout(() => {
|
|
|
- // console.log(that.showanswer);
|
|
|
- if (that.showanswer) {
|
|
|
- clearTimeout(down);
|
|
|
- // console.log('关闭定时器');
|
|
|
- that.second = 15;
|
|
|
- return;
|
|
|
- }
|
|
|
- that.countdown();
|
|
|
- }, 1000);
|
|
|
- // console.log(second);
|
|
|
- },
|
|
|
- // sendrepeat(e) {
|
|
|
- // if (this.paintingmode) {
|
|
|
- // this.sendpainting(this.paintinglist[e].content)
|
|
|
- // return;
|
|
|
- // }
|
|
|
-
|
|
|
- // this.send(this.talkList[e].content)
|
|
|
- // },
|
|
|
- //wss模式
|
|
|
- getChatGPT(e) {
|
|
|
- var that = this;
|
|
|
- let i = 1,
|
|
|
- message = '';
|
|
|
- this.question_index = that.talkList.length - 1;
|
|
|
- this.answer_index = that.talkList.length - 2;
|
|
|
- // this.eights = false;
|
|
|
-
|
|
|
- // that.$http('ai.checkText', {
|
|
|
- // prompt: e
|
|
|
- // }).then(res => {
|
|
|
- // if (res.code == 0) {
|
|
|
- let answer = '';
|
|
|
- if (that.talkList.length > 2 && that.showcontext) {
|
|
|
- // answer = that.talkList[that.question_index - 3].content + '\n' + that.talkList[that
|
|
|
- // .question_index - 2]
|
|
|
- // .content;
|
|
|
- answer = that.talkList[that.question_index - 2].content;
|
|
|
- }
|
|
|
- // console.log(answer);
|
|
|
- var ty = {
|
|
|
- prompt: e,
|
|
|
- guide: that.homeTemplate.mode[that.selectornot].guide,
|
|
|
- answer: answer,
|
|
|
- key: that.appInfo.sk ? that.appInfo.sk : '',
|
|
|
- lines: that.appInfo.connect_lines ? this.appInfo.connect_lines : 1
|
|
|
- };
|
|
|
- var json = JSON.stringify(ty);
|
|
|
- // if (that.$ws.socketStatus()) {
|
|
|
- // console.log('走方案1');
|
|
|
- that.thoroughfare = 1
|
|
|
- that.$ws.send(json);
|
|
|
- // } else {
|
|
|
- // that.eights = true;
|
|
|
- // that.directGpt(e, answer);
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- // that.talkList[that.question_index].content = res.msg;
|
|
|
- // that.talkList[that.question_index - 1].content = '该问题已被隐藏!';
|
|
|
- // that.talkList[that.question_index].show_flash = false;
|
|
|
- // that.talkList[that.question_index].done = true;
|
|
|
- // }
|
|
|
- // });
|
|
|
-
|
|
|
- },
|
|
|
- //php模式
|
|
|
- directGpt(e, answer) {
|
|
|
- // console.log('走方案3');
|
|
|
- let that = this;
|
|
|
- // console.log(that.appInfo.sk);
|
|
|
- if (!that.appInfo.sk && this.appInfo.connect_lines && this.appInfo.connect_lines ==
|
|
|
- 2) {
|
|
|
- uni.showToast({
|
|
|
- title: '未正确配置key',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- this.question_index = that.talkList.length - 1;
|
|
|
- if (this.showdirect) {
|
|
|
- that.talkList[that.question_index].content = '请等我几秒钟,正在输入回答...';
|
|
|
- }
|
|
|
- // this.showdirect = false;
|
|
|
- that.showanswer = this.showdirect;
|
|
|
- that.thoroughfare = 3
|
|
|
- that.$http('ai.chat', {
|
|
|
- prompt: e,
|
|
|
- guide: that.homeTemplate.mode[that.selectornot].guide,
|
|
|
- answer: answer
|
|
|
- }).then(res => {
|
|
|
- if (that.thoroughfare == 3) {
|
|
|
- if (res.code == 0) {
|
|
|
- that.talkList[that.question_index].content = res.data.trim();
|
|
|
- that.talkList[that.question_index].show_flash = false;
|
|
|
- that.talkList[that.question_index].done = true;
|
|
|
- } else if (res.code == 3) {
|
|
|
- that.talkList[that.question_index].content = res.msg;
|
|
|
- that.talkList[that.question_index].show_flash = false;
|
|
|
- that.talkList[that.question_index].done = true;
|
|
|
- } else {
|
|
|
- that.talkList[that.question_index].content = res.msg;
|
|
|
- that.talkList[that.question_index - 1].content = '该问题已被隐藏!';
|
|
|
- that.talkList[that.question_index].show_flash = false;
|
|
|
- that.talkList[that.question_index].done = true;
|
|
|
- }
|
|
|
- that.showanswer = true;
|
|
|
- that.getUserData();
|
|
|
- that.timing = that.appInfo.text_expire_time ? Number(that.appInfo
|
|
|
- .text_expire_time) : 30;
|
|
|
- that.showcontext = true;
|
|
|
- that.getcontext();
|
|
|
- that.$nextTick(() => {
|
|
|
- // 清空内容框中的内容
|
|
|
- that.content = '';
|
|
|
- if (that.followornot) {
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 300
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- //fetch模式
|
|
|
- fetchmodel(e) {
|
|
|
- // console.log('走方案2');
|
|
|
- var that = this;
|
|
|
- let i = 1,
|
|
|
- message = '';
|
|
|
- let answer = '';
|
|
|
- that.thoroughfare = 2;
|
|
|
- this.question_index = that.talkList.length - 1;
|
|
|
- this.answer_index = that.talkList.length - 2;
|
|
|
- if (that.talkList.length > 2 && that.showcontext) {
|
|
|
- // answer = that.talkList[that.question_index - 3].content + '\n' + that.talkList[that
|
|
|
- // .question_index - 2]
|
|
|
- // .content;
|
|
|
- answer = that.talkList[that.question_index - 2].content;
|
|
|
- }
|
|
|
-
|
|
|
- let param = {
|
|
|
- max_tokens: 3000,
|
|
|
- model: 'gpt-3.5-turbo-0301',
|
|
|
- stream: true,
|
|
|
- messages: [{
|
|
|
- role: 'assistant',
|
|
|
- content: answer
|
|
|
- },
|
|
|
- {
|
|
|
- role: 'system',
|
|
|
- content: that.homeTemplate.mode[that.selectornot].guide
|
|
|
- },
|
|
|
- {
|
|
|
- role: 'user',
|
|
|
- content: e
|
|
|
- }
|
|
|
- ]
|
|
|
- };
|
|
|
- let headers = {};
|
|
|
- if (that.appInfo.connect_lines == 2) {
|
|
|
- headers = {
|
|
|
- 'Content-Type': 'application/json',
|
|
|
- Authorization: 'Bearer' + ' ' + that.haddresssk
|
|
|
- }
|
|
|
- }
|
|
|
- // console.log(that.haddressurl,headers,param,that.appInfo.connect_lines);
|
|
|
- fetch(that.haddressurl, {
|
|
|
- method: 'POST',
|
|
|
- body: JSON.stringify(param),
|
|
|
- headers: headers
|
|
|
- })
|
|
|
- .then(x => {
|
|
|
- if (x.status === 200) return x.body;
|
|
|
- throw x;
|
|
|
- })
|
|
|
- .then(x => {
|
|
|
- const k = x.getReader();
|
|
|
-
|
|
|
- return new ReadableStream({
|
|
|
- start(V) {
|
|
|
- function F() {
|
|
|
- k.read().then(({
|
|
|
- done: E,
|
|
|
- value: U
|
|
|
- }) => {
|
|
|
-
|
|
|
- that.showanswer = true;
|
|
|
- if (E) {
|
|
|
- // console.log('done', E)
|
|
|
- // , V.close();
|
|
|
- that.timing = that.appInfo
|
|
|
- .text_expire_time ? Number(that
|
|
|
- .appInfo.text_expire_time) : 30;
|
|
|
- that.showcontext = true;
|
|
|
- that.getcontext();
|
|
|
- that.record(that.talkList[that
|
|
|
- .answer_index].content,
|
|
|
- message);
|
|
|
- that.talkList[that.question_index]
|
|
|
- .show_flash = false;
|
|
|
- that.talkList[that.question_index].done =
|
|
|
- true;
|
|
|
- that.getUserData();
|
|
|
- if (that.followornot) {
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 300
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
- V.enqueue(U);
|
|
|
- const L = new TextDecoder().decode(U);
|
|
|
-
|
|
|
- try {
|
|
|
- const G = L.match(/data:\s/g),
|
|
|
- j = L.split('data:').filter(w => !!w
|
|
|
- .trim() && w
|
|
|
- .trim() !== '[DONE]');
|
|
|
- // console.log(j);
|
|
|
- // let N = null;
|
|
|
-
|
|
|
- let N = j
|
|
|
- .map(w => JSON.parse(w))
|
|
|
- .map(w => (N = w.choices[0].delta
|
|
|
- .content))
|
|
|
- .join('');
|
|
|
-
|
|
|
-
|
|
|
- if (N != undefined) {
|
|
|
- message += N;
|
|
|
- }
|
|
|
- if (that.thoroughfare == 2) {
|
|
|
- that.talkList[that.question_index]
|
|
|
- .content = message;
|
|
|
- }
|
|
|
- // let C = null;
|
|
|
- let C = j
|
|
|
- .map(w => JSON.parse(w))
|
|
|
- .map(w => (N = w.choices[0]
|
|
|
- .finish_reason))
|
|
|
- .join('');
|
|
|
- if (C == 'stop') {
|
|
|
- that.timing = that.appInfo
|
|
|
- .text_expire_time ? Number(
|
|
|
- that.appInfo.text_expire_time
|
|
|
- ) : 30;
|
|
|
- that.showcontext = true;
|
|
|
- that.getcontext();
|
|
|
- that.record(that.talkList[that
|
|
|
- .answer_index].content,
|
|
|
- message);
|
|
|
- that.talkList[that.question_index]
|
|
|
- .show_flash = false;
|
|
|
- that.talkList[that.question_index]
|
|
|
- .done = true;
|
|
|
- that.getUserData();
|
|
|
- // if (that.followornot) {
|
|
|
- // uni.pageScrollTo({
|
|
|
- // scrollTop: 9999,
|
|
|
- // duration: 300
|
|
|
- // });
|
|
|
- // }
|
|
|
- setTimeout(() => {
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 300
|
|
|
- });
|
|
|
- }, 100);
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
- // console.log(C,'1');
|
|
|
- if (that.followornot) {
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 0
|
|
|
- });
|
|
|
- }
|
|
|
- } catch (G) {
|
|
|
- // console.error(G,'1');
|
|
|
- }
|
|
|
- F();
|
|
|
- });
|
|
|
- }
|
|
|
- F();
|
|
|
- }
|
|
|
- });
|
|
|
- })
|
|
|
- .then(x =>
|
|
|
- new Response(x, {
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'text/html'
|
|
|
- }
|
|
|
- }).text()
|
|
|
- );
|
|
|
- },
|
|
|
- // 记录回答
|
|
|
- record(question, answer) {
|
|
|
- let that = this;
|
|
|
- this.$http('question.add', {
|
|
|
- question,
|
|
|
- answer
|
|
|
- }).then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- that.getUserData();
|
|
|
- // console.log(that.question_index);
|
|
|
- } else {
|
|
|
- that.talkList[that.question_index].content = res.msg;
|
|
|
- that.talkList[that.question_index - 1].content = '该问题已被隐藏!';
|
|
|
- that.talkList[that.question_index].show_flash = false;
|
|
|
- that.talkList[that.question_index].done = true;
|
|
|
- that.talkList[that.question_index].donec = true;
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- },
|
|
|
- // 复制文本
|
|
|
- copyText(e) {
|
|
|
- uni.setClipboardData({
|
|
|
- data: this.talkList[e].content,
|
|
|
- success: function() {
|
|
|
- // console.log('success');
|
|
|
- uni.showToast({
|
|
|
- title: '复制成功'
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- // 插屏广告显示时间
|
|
|
- showInterstitial() {
|
|
|
- time2 = setInterval(
|
|
|
- function() {
|
|
|
- interstitialAd.show().catch(err => {
|
|
|
- // console.error(err);
|
|
|
- });
|
|
|
- },
|
|
|
- this.appInfo.gap ? this.appInfo.gap * 1000 : 12000
|
|
|
- );
|
|
|
- },
|
|
|
- // 生成图片
|
|
|
- toSave() {
|
|
|
- uni.showLoading({
|
|
|
- title: '海报生成中'
|
|
|
- });
|
|
|
- this.$refs.painter.canvasToTempFilePathSync({
|
|
|
- // 在nvue里是jpeg
|
|
|
- fileType: 'jpg',
|
|
|
- quality: 1,
|
|
|
- success: res => {
|
|
|
- // this.path = res.tempFilePath;
|
|
|
- // this.$refs.posterImg.open();
|
|
|
- // this.show_poster = true;
|
|
|
-
|
|
|
- // console.log(res.tempFilePath);
|
|
|
- // 非H5 保存到相册
|
|
|
- // H5 提示用户长按图另存
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- // uni.saveImageToPhotosAlbum({
|
|
|
- // filePath: res.tempFilePath,
|
|
|
- // success: function() {
|
|
|
- // uni.showToast({
|
|
|
- // title: '保存成功'
|
|
|
- // });
|
|
|
- // that.showPoster = false;
|
|
|
- // }
|
|
|
- // });
|
|
|
-
|
|
|
- wx.showShareImageMenu({
|
|
|
- path: res.tempFilePath
|
|
|
- })
|
|
|
- this.showPoster = false;
|
|
|
- uni.hideLoading();
|
|
|
- // #endif
|
|
|
- // #ifdef H5
|
|
|
- this.showPoster = false;
|
|
|
- uni.hideLoading();
|
|
|
- uni.showModal({
|
|
|
- confirmColor: '#26B3A0',
|
|
|
- confirmText: '查看图片',
|
|
|
- title: '提示',
|
|
|
- content: '查看图片后长按图片即可保存或分享',
|
|
|
- success(src) {
|
|
|
- if (src.confirm) {
|
|
|
- uni.previewImage({
|
|
|
- urls: [res.tempFilePath]
|
|
|
- });
|
|
|
- } else if (src.cancel) {
|
|
|
- this.showPoster = true;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- // #endif
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- //预览图片
|
|
|
- preview(e) {
|
|
|
- uni.previewImage({
|
|
|
- urls: [this.paintinglist[e].img],
|
|
|
-
|
|
|
- });
|
|
|
- },
|
|
|
- //选择模型
|
|
|
- onselect(e) {
|
|
|
- if (this.selectornot != e) {
|
|
|
- let data = {
|
|
|
- content: uni.$u.trim(this.homeTemplate.mode[e].greetings),
|
|
|
- type: 1,
|
|
|
- toid: this.toid,
|
|
|
- fromid: -1,
|
|
|
- avatar: this.homeTemplate.mode[e].img_file.path,
|
|
|
- nickname: this.homeTemplate.mode[e].name,
|
|
|
- done: true,
|
|
|
- donec: true
|
|
|
- };
|
|
|
- this.talkList.push(data);
|
|
|
- this.$nextTick(() => {
|
|
|
- uni.pageScrollTo({
|
|
|
- scrollTop: 9999,
|
|
|
- duration: 300
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- this.showcontext = false
|
|
|
- this.switchmodel = this.selectornot == e ? true : false;
|
|
|
- this.selectornot = e;
|
|
|
- // #ifdef H5
|
|
|
- this.zhuangtai = this.homeTemplate.mode[e].name;
|
|
|
- // #endif
|
|
|
- },
|
|
|
- posterSuccess(e) {
|
|
|
- // console.log(e);
|
|
|
-
|
|
|
- },
|
|
|
- // 海报绘制
|
|
|
- createPoster(e) {
|
|
|
- let that = this;
|
|
|
- (this.posterObj = {
|
|
|
- width: '670rpx',
|
|
|
- background: '#fff',
|
|
|
- borderRadius: '16rpx',
|
|
|
- css: {
|
|
|
- // 根节点若无尺寸,自动获取父级节点
|
|
|
- width: '670rpx'
|
|
|
- },
|
|
|
- views: [{
|
|
|
- type: 'view',
|
|
|
- css: {
|
|
|
- marginTop: '20rpx',
|
|
|
- paddingLeft: '10rpx',
|
|
|
- display: 'flex'
|
|
|
- },
|
|
|
- views: [{
|
|
|
- type: 'image',
|
|
|
- src: this.userInfo.avatar ? this.userInfo.avatar :
|
|
|
- '/static/images/head.jpg',
|
|
|
- css: {
|
|
|
- marginTop: '10rpx',
|
|
|
- marginLeft: '10rpx',
|
|
|
- borderRadius: '16rpx',
|
|
|
- width: '80rpx',
|
|
|
- height: '80rpx',
|
|
|
- border: '2rpx solid #fff',
|
|
|
- objectFit: 'cover'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'view',
|
|
|
- css: {
|
|
|
- marginTop: '10rpx',
|
|
|
- marginLeft: '20rpx'
|
|
|
- // display:'flex',
|
|
|
- // flexDirection:'column'
|
|
|
- },
|
|
|
- views: [{
|
|
|
- type: 'view',
|
|
|
- views: [{
|
|
|
- type: 'text',
|
|
|
- text: this.userInfo.nickname ? this
|
|
|
- .userInfo
|
|
|
- .nickname : '提问者',
|
|
|
- css: {
|
|
|
- marginTop: '10rpx',
|
|
|
- fontSize: '28rpx',
|
|
|
- fontWeight: 'bold',
|
|
|
- color: '#1A2033',
|
|
|
- lineHeight: '28rpx'
|
|
|
- }
|
|
|
- }]
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'view',
|
|
|
- views: [{
|
|
|
- type: 'text',
|
|
|
- text: '我的提问',
|
|
|
- css: {
|
|
|
- marginTop: '15rpx',
|
|
|
- fontSize: '22rpx',
|
|
|
- // fontWeight: 'bold',
|
|
|
- color: '#999',
|
|
|
- lineHeight: '25rpx'
|
|
|
- }
|
|
|
- }]
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'view',
|
|
|
- css: {
|
|
|
- marginTop: '20rpx',
|
|
|
- width: '610rpx',
|
|
|
- padding: '10rpx',
|
|
|
- background: '#d2f8d3',
|
|
|
- borderRadius: '16rpx',
|
|
|
- marginLeft: '20rpx',
|
|
|
- marginRight: '10rpx'
|
|
|
- },
|
|
|
- views: [{
|
|
|
- type: 'text',
|
|
|
- text: that.talkList[e - 1].content,
|
|
|
- css: {
|
|
|
- fontSize: '28rpx',
|
|
|
- color: '#1A2033',
|
|
|
- lineHeight: '45rpx',
|
|
|
- lineClamp: 2,
|
|
|
- paddingLeft: '10rpx',
|
|
|
- paddingRight: '10rpx',
|
|
|
- width: '590rpx'
|
|
|
- // padding:'10rpx'
|
|
|
- }
|
|
|
- }]
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'view',
|
|
|
- css: {
|
|
|
- marginTop: '20rpx',
|
|
|
- paddingLeft: '10rpx',
|
|
|
- display: 'flex'
|
|
|
- },
|
|
|
- views: [{
|
|
|
- type: 'image',
|
|
|
- // src: this.homeTemplate.mode&&this.homeTemplate.mode[this.selectornot].img_file.path?this.homeTemplate.mode[this.selectornot].img_file.path:'/static/images/head.jpg',
|
|
|
- src: '/static/images/open.png',
|
|
|
- css: {
|
|
|
- marginTop: '10rpx',
|
|
|
- marginLeft: '10rpx',
|
|
|
- borderRadius: '16rpx',
|
|
|
- width: '80rpx',
|
|
|
- height: '80rpx',
|
|
|
- border: '2rpx solid #fff',
|
|
|
- objectFit: 'cover'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'view',
|
|
|
- css: {
|
|
|
- marginTop: '10rpx',
|
|
|
- marginLeft: '20rpx'
|
|
|
- // display:'flex',
|
|
|
- // flexDirection:'column'
|
|
|
- },
|
|
|
- views: [{
|
|
|
- type: 'view',
|
|
|
- views: [{
|
|
|
- type: 'text',
|
|
|
- text: this.appInfo.site_name ? this
|
|
|
- .appInfo
|
|
|
- .site_name : 'AI智能问答机器人',
|
|
|
- css: {
|
|
|
- marginTop: '10rpx',
|
|
|
- fontSize: '28rpx',
|
|
|
- fontWeight: 'bold',
|
|
|
- color: '#1A2033',
|
|
|
- lineHeight: '28rpx'
|
|
|
- }
|
|
|
- }]
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'view',
|
|
|
- views: [{
|
|
|
- type: 'text',
|
|
|
- text: '回答结果',
|
|
|
- css: {
|
|
|
- marginTop: '15rpx',
|
|
|
- fontSize: '22rpx',
|
|
|
- // fontWeight: 'bold',
|
|
|
- color: '#999',
|
|
|
- lineHeight: '25rpx'
|
|
|
- }
|
|
|
- }]
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'view',
|
|
|
- css: {
|
|
|
- marginTop: '20rpx',
|
|
|
- width: '610rpx',
|
|
|
- padding: '10rpx',
|
|
|
- background: '#f5f6f8',
|
|
|
- borderRadius: '16rpx',
|
|
|
- marginLeft: '20rpx',
|
|
|
- marginRight: '10rpx'
|
|
|
- },
|
|
|
- views: [{
|
|
|
- type: 'text',
|
|
|
- text: uni.$u.trim(that.talkList[e].content),
|
|
|
- css: {
|
|
|
- fontSize: '28rpx',
|
|
|
- color: '#1A2033',
|
|
|
- lineHeight: '45rpx',
|
|
|
- lineClamp: 11,
|
|
|
- width: '590rpx',
|
|
|
- // paddingLeft: '10rpx',
|
|
|
- // paddingTop: '10rpx',
|
|
|
- padding: '10rpx'
|
|
|
- }
|
|
|
- }]
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'view',
|
|
|
- css: {
|
|
|
- marginTop: '20rpx',
|
|
|
- width: '100%',
|
|
|
- textAlign: 'center'
|
|
|
- },
|
|
|
- // #ifdef H5
|
|
|
- views: [{
|
|
|
- type: 'qrcode',
|
|
|
- text: this.qrcode,
|
|
|
- css: {
|
|
|
- width: '200rpx',
|
|
|
- height: '200rpx'
|
|
|
- }
|
|
|
- }],
|
|
|
- // #endif
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
- views: [{
|
|
|
- type: 'image',
|
|
|
- src: this.qrcode,
|
|
|
- css: {
|
|
|
- width: '200rpx',
|
|
|
- height: '200rpx'
|
|
|
- }
|
|
|
- }]
|
|
|
- // #endif
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'text',
|
|
|
- text: '———— ' + '长按识别 | 欢迎使用' + ' ————',
|
|
|
- css: {
|
|
|
- marginTop: '20rpx',
|
|
|
- width: '100%',
|
|
|
- textAlign: 'center',
|
|
|
- fontSize: '24rpx',
|
|
|
- color: '#989FB3',
|
|
|
- lineHeight: '33rpx'
|
|
|
- }
|
|
|
- }
|
|
|
- ]
|
|
|
- }),
|
|
|
- (this.showPoster = true);
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
-</script>
|
|
|
-
|
|
|
-<style lang="scss" scoped>
|
|
|
- @import '@/pages/chat/global.scss';
|
|
|
- @import './chat.scss';
|
|
|
-</style>
|