jhlive.nvue 9.5 KB

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