jhlive.nvue 9.0 KB

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