jhlive.nvue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. <view v-if="showFav" class="top_left_box_collect">
  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. collect:"./live-collect.png", // 已收藏图标
  87. notCollect: "./live-notCollect.png", // 未收藏图标
  88. inputIcon: "./live-chat.png", // 输入框图标
  89. beautyIcon:"./live-beauty.png", // 美颜图标
  90. switchIcon: "./live-switch.png", // 切换摄像头图标
  91. likeIcon: "./live-support.png"
  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. 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. };
  208. </script>
  209. <style scoped>
  210. .container-jhlive {
  211. position: relative;
  212. /* #ifndef APP-NVUE */
  213. display: flex;
  214. /* #endif */
  215. flex-direction: column;
  216. align-items: stretch;
  217. background-color: black;
  218. width: 100%;
  219. height: 100%;
  220. }
  221. .liveView {
  222. flex: 1;
  223. /* z-index: -1; */
  224. }
  225. .top_left_box {
  226. left: 0;
  227. top: 0;
  228. margin-left: 10px;
  229. margin-top: 10px;
  230. position: absolute;
  231. z-index: 100;
  232. background-color: rgba(115, 111, 117, 0.4);
  233. border-radius: 1000px;
  234. /* #ifndef APP-NVUE */
  235. display: flex;
  236. /* #endif */
  237. flex-direction: row;
  238. padding: 5px;
  239. justify-content: center;
  240. align-items: center;
  241. }
  242. .top_left_box_img {
  243. width: 80rpx;
  244. height: 80rpx;
  245. border-radius: 1000px;
  246. background-color: white;
  247. }
  248. .top_left_box_collect {
  249. /* width: 26px;
  250. height: 26px; */
  251. border-radius: 1000px;
  252. padding: 3px 5px;
  253. background-color: green;
  254. }
  255. .top_left_box_collect_text {
  256. color: white;
  257. font-size: 20rpx;
  258. }
  259. .top_left_box_text {
  260. margin-left: 10px;
  261. margin-right: 10px;
  262. }
  263. .top_left_box_text1 {
  264. font-size: 28rpx;
  265. color: white;
  266. margin-bottom: 5px;
  267. }
  268. .top_left_box_text2 {
  269. font-size: 20rpx;
  270. color: white;
  271. }
  272. .bottom-message {
  273. width: 750rpx;
  274. /* #ifndef APP-NVUE */
  275. display: flex;
  276. /* #endif */
  277. flex-direction: column;
  278. position: absolute;
  279. bottom: 0px;
  280. }
  281. .bottom-box {
  282. /* #ifndef APP-NVUE */
  283. display: flex;
  284. /* #endif */
  285. flex-direction: row;
  286. bottom: 0px;
  287. background-color:rgba(0, 0, 0, 0.4);
  288. }
  289. .jhim-message-box {
  290. max-height: 375rpx;
  291. }
  292. .jhim-message {
  293. /* #ifndef APP-NVUE */
  294. display: flex;
  295. /* #endif */
  296. flex-direction: row;
  297. align-items: center;
  298. margin-left: 10px;
  299. margin-right: 10px;
  300. margin-bottom: 10px;
  301. }
  302. .jhim-message-show {
  303. background-color: rgba(115,119,120,0.3);
  304. border-radius: 15px;
  305. padding: 5px;
  306. }
  307. .jhim-message-none {
  308. flex: 1;
  309. }
  310. .jhim-message-text {
  311. max-width: 400rpx;
  312. color: #fff;
  313. font-size: 14px;
  314. /* #ifndef APP-NVUE */
  315. word-break: break-all;
  316. /* #endif */
  317. /* #ifdef APP-NVUE */
  318. lines: 5;
  319. word-break: anywhere;
  320. /* #endif */
  321. }
  322. .jhim-message-text2 {
  323. color: #C8C8C8;
  324. font-size: 14px;
  325. }
  326. .jhim-input-box {
  327. padding: 10px;
  328. margin: 10px;
  329. align-items: center;
  330. display: flex;
  331. flex-direction: row;
  332. background-color:rgba(50, 50, 50, 0.3);
  333. border-radius: 15px;
  334. flex: 1;
  335. }
  336. .jhim-icon {
  337. width: 14px;
  338. height: 14px;
  339. margin-right: 5px;
  340. }
  341. .jhim-input {
  342. flex: 1;
  343. color: #fff;
  344. font-size: 28rpx;
  345. }
  346. .jhim-logining {
  347. padding: 10px;
  348. flex: 1;
  349. }
  350. .jhim-logining-text {
  351. color: #fff;
  352. font-size: 28rpx;
  353. }
  354. .bottom-box-btns {
  355. display: flex;
  356. flex-direction: row;
  357. align-items: center;
  358. }
  359. .bottom-box-btns-arr {
  360. margin-right: 5px;
  361. }
  362. .btns-icon {
  363. width: 40px;
  364. height: 40px;
  365. }
  366. .btns-text {
  367. text-align: center;
  368. }
  369. </style>