Browse Source

字数限制

master
HolyKnightIX 2 years ago
parent
commit
22544bb0a5
3 changed files with 29 additions and 4 deletions
  1. +26
    -1
      miniprogram/pages/chat/chat.js
  2. +1
    -1
      miniprogram/pages/chat/chat.wxml
  3. +2
    -2
      miniprogram/utils/request.js

+ 26
- 1
miniprogram/pages/chat/chat.js View File

@@ -1,3 +1,5 @@
const app = getApp()
import request from '../../utils/request'
import { scrollToID } from '../../utils/util' import { scrollToID } from '../../utils/util'
Page({ Page({


@@ -6,6 +8,7 @@ Page({
*/ */
data: { data: {
chatList: [], chatList: [],
saysContentLength: 50,
message: "", message: "",
waitingMessage: "", waitingMessage: "",
isResponing: false, isResponing: false,
@@ -23,11 +26,33 @@ Page({
*/ */
onLoad() { onLoad() {
this.socketLink() this.socketLink()
this.chatLimit()
},

chatLimit() {
request.get({
url: '/api/chat/limit',
}).then(res => {
console.log(res, 'chatLimit');
this.setData({
saysContentLength: res.data.saysContentLength * 1
})
}).catch(err => {
console.log(err, 'err');
})
}, },


input(e) { input(e) {
const msg = e.detail.value
const limit = this.data.saysContentLength
if (msg.length > limit) {
wx.showToast({
title: `单条最长可输入字数为${limit}字!`,
icon: 'none'
})
}
this.setData({ this.setData({
message: e.detail.value
message: msg
}) })
}, },




+ 1
- 1
miniprogram/pages/chat/chat.wxml View File

@@ -38,7 +38,7 @@


<view class="chatBox"> <view class="chatBox">
<view class="boxOutside"> <view class="boxOutside">
<input class="inputBox" type="text" bindinput="input" value="{{message}}" />
<input class="inputBox" type="text" bindinput="input" value="{{message}}" placeholder="单次最多可输入{{saysContentLength}}字" />
<button class="sendBtn" type="primary" bindtap="send">发送</button> <button class="sendBtn" type="primary" bindtap="send">发送</button>
</view> </view>
</view> </view>

+ 2
- 2
miniprogram/utils/request.js View File

@@ -1,5 +1,5 @@
const url = 'https://gpttest.malls.iformall.com/C'
// const url = 'https://gpt.malls.iformall.com/C'
// const url = 'https://gpttest.malls.iformall.com/C'
const url = 'https://gpt.malls.iformall.com/C'


class request { class request {
constructor(address) { constructor(address) {


Loading…
Cancel
Save