jhlive.nvue 9.6 KB

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