jhlive.nvue 9.9 KB

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