jhlive.nvue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <view class="container-jhlive" data-type="jhlive">
  3. <JhliveApp class="liveView" ref="liveView" :sdkAppID="sdkAppID" :userSig="userSig" :userid="userId" :roomid="roomId"
  4. :isAuthor="isAuthor" :linkMic="linkMic" @onError="onError" @onRemoteUserEnterRoom="onRemoteUserEnterRoom"
  5. @onRemoteUserLeaveRoom="onRemoteUserLeaveRoom" />
  6. <view class="top_left_box">
  7. <image class="top_left_box_img" :src="avatar" mode="aspectFill"></image>
  8. <view class="top_left_box_text">
  9. <text class="top_left_box_text1">{{title}}</text>
  10. <text class="top_left_box_text2">{{subtitle}}</text>
  11. </view>
  12. <view v-if="showFav" class="top_left_box_collect" @click="onLiveFav">
  13. <text class="top_left_box_collect_text">{{isFav?textFav:textNotFav}}</text>
  14. </view>
  15. <!-- <image v-if="showFav" class="top_left_box_collect" :src="isFav?collect:notCollect" @click="$emit('onFav', isFav)"></image> -->
  16. </view>
  17. <view class="bottom-message">
  18. <!-- 对话信息 -->
  19. <!-- <view class="jhim-message-box"> -->
  20. <scroll-view :scroll-top="imScrollTop" scroll-y="true" v-if="showIm" class="jhim-message-box">
  21. <view ref="imScrollContent">
  22. <view class="jhim-message" v-for="(item, index) in imMsgs" :key="index">
  23. <view class="jhim-message-show" >
  24. <!-- <text class="jhim-message-text2">{{item.name}}:</text> -->
  25. <text class="jhim-message-text">{{item.name}}:{{item.text}}</text>
  26. </view>
  27. <view class="jhim-message-none"></view>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. <!-- </view> -->
  32. <!-- 下方功能 -->
  33. <view v-if="showIm||btns.length" class="bottom-box">
  34. <view v-if="showIm&&!imStatus" class="jhim-input-box">
  35. <image class="jhim-icon" :src="imgs.chat"/>
  36. <input
  37. class="jhim-input"
  38. placeholder="请输入"
  39. placeholder-style="color:#fff;font-size: 14px;"
  40. v-model="imInput"
  41. confirm-type="send" @confirm="$emit('onImSend', imInput)" />
  42. </view>
  43. <view v-if="showIm&&imStatus" class="jhim-logining"><text class="jhim-logining-text">{{imStatus}}</text></view>
  44. <view v-if="!showIm" class="jhim-logining"></view>
  45. <!-- 按钮 -->
  46. <view class="bottom-box-btns">
  47. <!-- <view class="" v-if="isAuthor && showBeauty" @click="btnBeautify"> -->
  48. <view v-if="isAuthor&&showBeauty" class="bottom-box-btns-arr" @click="btnBeautify">
  49. <image class="btns-icon" :src="imgs.beauty"/>
  50. </view>
  51. <!-- <view class="" v-if="isAuthor && showSwitch" @click="btnChangeCamera"> -->
  52. <view v-if="isAuthor&&showSwitch" class="bottom-box-btns-arr" @click="btnChangeCamera">
  53. <image class="btns-icon" :src="imgs.switch"/>
  54. </view>
  55. <view class="bottom-box-btns-arr" v-for="(item,index) in btns" :key="index" @click="clickBtns(index, item)">
  56. <image class="btns-icon" :src="item.picture"/>
  57. <text v-if="item.title" class="btns-text">{{item.title}}</text>
  58. </view>
  59. <view v-if="showLike" class="bottom-box-btns-arr" @click="btnLike">
  60. <image class="btns-icon" :src="imgs.like"/>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import imgs from './res.js'
  69. import LibGenerateTestUserSig from "./lib-generate-test-usersig-es.min";
  70. // #ifdef MP-WEIXIN
  71. import JhliveApp from './live-wechat';
  72. //#endif
  73. // #ifdef APP-PLUS
  74. const dom = uni.requireNativePlugin('dom');
  75. //#endif
  76. const LOGTAG = '--JHLIVE--:';
  77. const EXPIRETIME = 604800;
  78. export default {
  79. name: 'jhlive',
  80. // #ifdef MP-WEIXIN
  81. components: {
  82. JhliveApp
  83. },
  84. //#endif
  85. data() {
  86. return {
  87. imScrollTop: 0,
  88. imgs,
  89. imInput: '',
  90. userSig: '',
  91. beautifyLevel: false,
  92. };
  93. },
  94. props: {
  95. sdkAppID: Number,
  96. secretKey: String,
  97. userId: String,
  98. roomId: String,
  99. isAuthor: Boolean,
  100. linkMic: Boolean,
  101. title: String,
  102. avatar: String,
  103. subtitle: String,
  104. isFav: {default: false,type: Boolean}, // 是否显示收藏
  105. showFav: {default: false,type: Boolean}, // 是否显示收藏
  106. textFav: {default: '已关注',type: String},
  107. textNotFav: {default: '关注',type: String},
  108. showBeauty: {default: false,type: Boolean}, // 是否显示美颜
  109. showSwitch: {default: false,type: Boolean}, // 是否显示切换摄像头
  110. showLike: {default: false,type: Boolean},
  111. showIm: {default: false,type: Boolean},
  112. btns:{
  113. default: [],
  114. type: Array
  115. }, // 按钮数组
  116. imMsgs:{
  117. default: [],
  118. type: Array
  119. },
  120. imStatus:{
  121. default: '',
  122. type: String
  123. }
  124. },
  125. mounted() {
  126. this.init();
  127. },
  128. unmounted() {
  129. this.destroy();
  130. },
  131. watch: {
  132. imMsgs() {
  133. // #ifdef APP-PLUS
  134. setTimeout(() => {
  135. const el = this.$refs.imScrollContent;
  136. dom.getComponentRect(el, (e)=>{
  137. if(e.size.height>200) this.imScrollTop = (e.size.height - 200);
  138. // el&&dom.scrollToElement(el, {offset: -100})
  139. })
  140. },50);
  141. //#endif
  142. // #ifndef APP-PLUS
  143. this.imScrollTop = 10000+ this.imMsgs.length
  144. //#endif
  145. }
  146. },
  147. methods: {
  148. init() {
  149. console.log(LOGTAG + 'init');
  150. this.remoteUsers = [];
  151. uni.setKeepScreenOn({
  152. keepScreenOn: true
  153. });
  154. },
  155. destroy() {
  156. console.log(LOGTAG + 'destroy');
  157. uni.setKeepScreenOn({
  158. keepScreenOn: false
  159. });
  160. this.exitRoom()
  161. },
  162. enterRoom() {
  163. if (!this.$refs.liveView||!this.$refs.liveView.enterRoom) {
  164. console.log(LOGTAG + 'no jhlive');
  165. uni.showToast({
  166. title: '直播组件初始化失败',
  167. duration: 2000
  168. });
  169. return;
  170. }
  171. console.log(LOGTAG + 'enterRoom', this.isAuthor, this.linkMic, this.sdkAppID, this.secretKey, this.userId, this.roomId);
  172. const generator = new LibGenerateTestUserSig(this.sdkAppID, this.secretKey, EXPIRETIME);
  173. this.userSig = generator.genTestUserSig(String(this.userId));
  174. this.$nextTick(() => this.$refs.liveView && this.$refs.liveView.enterRoom && this.$refs.liveView.enterRoom());
  175. },
  176. exitRoom() {
  177. console.log(LOGTAG + 'exitRoom');
  178. this.$refs.liveView.exitRoom();
  179. },
  180. cleanImInput() {
  181. this.imInput = '';
  182. },
  183. btnChangeCamera() {
  184. console.log(LOGTAG + 'btnChangeCamera');
  185. this.$refs.liveView.switchCarema();
  186. },
  187. btnBeautify() {
  188. console.log(LOGTAG + 'btnBeautify', this.beautifyLevel);
  189. // blv - 美颜级别取值范围0 - 9; 0表示关闭,1 - 9值越大
  190. // wlv - 亮度级别取值范围0 - 9; 0表示关闭,1 - 9值越大
  191. // beautyStyle 美颜风格.三种美颜风格:0 :光滑 1:自然 2:朦胧
  192. this.beautifyLevel = !this.beautifyLevel;
  193. this.$refs.liveView.setBeauty(
  194. this.beautifyLevel ? 9 : 0,
  195. this.beautifyLevel ? 9 : 0,
  196. this.beautifyLevel ? 0 : 0,
  197. );
  198. },
  199. onError(e) {
  200. console.log(LOGTAG + 'onError', e);
  201. uni.showToast({
  202. title: e.detail,
  203. duration: 2000
  204. });
  205. this.$emit('onError', e.detail);
  206. },
  207. onRemoteUserEnterRoom(e) {
  208. console.log(LOGTAG + 'onRemoteUserEnterRoom', e);
  209. if (!this.remoteUsers.find(v => v == e.detail)) {
  210. this.remoteUsers.push(e.detail);
  211. }
  212. this.$emit('onRemoteUser', this.remoteUsers);
  213. },
  214. onRemoteUserLeaveRoom(e) {
  215. console.log(LOGTAG + 'onRemoteUserLeaveRoom', e);
  216. this.remoteUsers = this.remoteUsers.filter(v => v != e.detail);
  217. this.$emit('onRemoteUser', this.remoteUsers);
  218. },
  219. clickBtns(index, item) {
  220. this.$emit("onBtnClick", index, item);
  221. },
  222. // 关注点击事件
  223. onLiveFav() {
  224. this.$emit("onLiveFav", this.isFav);
  225. }
  226. }
  227. };
  228. </script>
  229. <style scoped>
  230. .container-jhlive {
  231. position: relative;
  232. /* #ifndef APP-NVUE */
  233. display: flex;
  234. /* #endif */
  235. flex-direction: column;
  236. align-items: stretch;
  237. background-color: black;
  238. width: 100%;
  239. height: 100%;
  240. }
  241. .liveView {
  242. flex: 1;
  243. /* z-index: -1; */
  244. }
  245. .top_left_box {
  246. left: 0;
  247. top: 0;
  248. margin-left: 10px;
  249. margin-top: 10px;
  250. position: absolute;
  251. z-index: 100;
  252. background-color: rgba(115, 111, 117, 0.4);
  253. border-radius: 1000px;
  254. /* #ifndef APP-NVUE */
  255. display: flex;
  256. /* #endif */
  257. flex-direction: row;
  258. padding: 5px;
  259. justify-content: center;
  260. align-items: center;
  261. }
  262. .top_left_box_img {
  263. width: 80rpx;
  264. height: 80rpx;
  265. border-radius: 1000px;
  266. background-color: white;
  267. }
  268. .top_left_box_collect {
  269. /* width: 26px;
  270. height: 26px; */
  271. border-radius: 1000px;
  272. padding: 3px 5px;
  273. background-color: green;
  274. }
  275. .top_left_box_collect_text {
  276. color: white;
  277. font-size: 20rpx;
  278. }
  279. .top_left_box_text {
  280. margin-left: 10px;
  281. margin-right: 10px;
  282. }
  283. .top_left_box_text1 {
  284. font-size: 28rpx;
  285. color: white;
  286. margin-bottom: 5px;
  287. }
  288. .top_left_box_text2 {
  289. font-size: 20rpx;
  290. color: white;
  291. }
  292. .bottom-message {
  293. width: 750rpx;
  294. /* #ifndef APP-NVUE */
  295. display: flex;
  296. /* #endif */
  297. flex-direction: column;
  298. position: absolute;
  299. bottom: 0px;
  300. }
  301. .bottom-box {
  302. /* #ifndef APP-NVUE */
  303. display: flex;
  304. /* #endif */
  305. flex-direction: row;
  306. bottom: 0px;
  307. /* background-color:rgba(0, 0, 0, 0.4); */
  308. }
  309. .jhim-message-box {
  310. max-height: 200px;
  311. }
  312. .jhim-message {
  313. /* #ifndef APP-NVUE */
  314. display: flex;
  315. /* #endif */
  316. flex-direction: row;
  317. align-items: center;
  318. margin-left: 10px;
  319. margin-right: 10px;
  320. margin-bottom: 10px;
  321. }
  322. .jhim-message-show {
  323. background-color: rgba(115,119,120,0.3);
  324. border-radius: 15px;
  325. padding: 5px;
  326. }
  327. .jhim-message-none {
  328. flex: 1;
  329. }
  330. .jhim-message-text {
  331. max-width: 400rpx;
  332. color: #fff;
  333. font-size: 14px;
  334. /* #ifndef APP-NVUE */
  335. word-break: break-all;
  336. /* #endif */
  337. /* #ifdef APP-NVUE */
  338. lines: 5;
  339. word-break: anywhere;
  340. /* #endif */
  341. }
  342. .jhim-message-text2 {
  343. color: #C8C8C8;
  344. font-size: 14px;
  345. }
  346. .jhim-input-box {
  347. padding: 10px;
  348. margin: 10px;
  349. align-items: center;
  350. display: flex;
  351. flex-direction: row;
  352. background-color:rgba(50, 50, 50, 0.3);
  353. border-radius: 15px;
  354. flex: 1;
  355. }
  356. .jhim-icon {
  357. width: 14px;
  358. height: 14px;
  359. margin-right: 5px;
  360. }
  361. .jhim-input {
  362. flex: 1;
  363. color: #fff;
  364. font-size: 28rpx;
  365. }
  366. .jhim-logining {
  367. padding: 10px;
  368. flex: 1;
  369. }
  370. .jhim-logining-text {
  371. color: #fff;
  372. font-size: 28rpx;
  373. }
  374. .bottom-box-btns {
  375. display: flex;
  376. flex-direction: row;
  377. align-items: center;
  378. }
  379. .bottom-box-btns-arr {
  380. margin-right: 5px;
  381. }
  382. .btns-icon {
  383. width: 40px;
  384. height: 40px;
  385. }
  386. .btns-text {
  387. text-align: center;
  388. }
  389. </style>