livingInvite.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <view class="container" :class="isLoggedIn?'bg-red':'bg-redA'">
  3. <!-- <view class="container" :class="{'bg-red':isLoggedIn}"> -->
  4. <!-- View 1: Not Logged In -->
  5. <view v-if="!isLoggedIn" class="landing-view">
  6. <view class="card" @click="handleLogin">
  7. <view class="icon-box">
  8. <!-- Using a link icon, if not available locally, using a remote one or css shape -->
  9. <!-- <image class="icon-link" :src="linkIcon" mode="aspectFit"></image> -->
  10. <u-icon name="share" size='40' color='#ffffff'></u-icon>
  11. </view>
  12. <view class="text">邀请您生成专属直播观看链接</view>
  13. </view>
  14. </view>
  15. <!-- View 2: Logged In / Success -->
  16. <view v-else class="success-view">
  17. <view class="header-text">您的专属直播观看链接生成成功,为保障您的个人信息安全,请勿分享给别人</view>
  18. <view class="info-card">
  19. <view class="user-row">
  20. <image class="avatar" :src="userInfo.avatar || defaultAvatar" mode="aspectFill"></image>
  21. <view class="user-details">
  22. <view class="name">{{userInfo.nickName || '微信用户'}}</view>
  23. <view class="id">ID {{userInfo.userId || userInfo.id || '8059522'}}</view>
  24. </view>
  25. </view>
  26. <view class="divider"></view>
  27. <view class="detail-row">
  28. <text class="label">所属经销商</text>
  29. <text class="value">{{userInfo.deptName || '运营'}}</text>
  30. </view>
  31. <view class="detail-row">
  32. <text class="label">当前跟进人</text>
  33. <text class="value">{{userInfo.userName || '运营'}}</text>
  34. </view>
  35. </view>
  36. <button class="copy-btn" @click="handleCopyLink">复制链接</button>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import { loginByMiniApp, getUserInfo ,getConfigByKey} from '@/api/user.js';
  42. export default {
  43. data() {
  44. return {
  45. isLoggedIn: false,
  46. userInfo: {},
  47. defaultAvatar: 'https://jsbk-1356516894.cos.ap-chongqing.myqcloud.com/orangeShop/detault_head.png',
  48. linkIcon: 'https://jsbk-1356516894.cos.ap-chongqing.myqcloud.com/orangeShop/link_icon.png',
  49. liveLink: ''
  50. }
  51. },
  52. onLoad(option) {
  53. this.checkLoginStatus();
  54. },
  55. methods: {
  56. checkLoginStatus() {
  57. const token = uni.getStorageSync('AppToken');
  58. if (token) {
  59. this.isLoggedIn = true;
  60. this.loadUserInfo();
  61. } else {
  62. this.handleLogin()
  63. this.isLoggedIn = false;
  64. }
  65. },
  66. loadUserInfo() {
  67. const storedUser = uni.getStorageSync('userInfo');
  68. if (storedUser) {
  69. try {
  70. this.userInfo = JSON.parse(storedUser);
  71. } catch (e) {
  72. this.userInfo = storedUser;
  73. }
  74. }
  75. // Optionally fetch latest info
  76. getUserInfo().then(res => {
  77. if (res.code === 200 && res.user) {
  78. this.userInfo = res.user;
  79. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  80. }
  81. });
  82. },
  83. // Silent Login Flow
  84. async handleLogin(data){
  85. if(data){
  86. console.log('huoqu1222',data)
  87. uni.showLoading({
  88. title: '登录中...'
  89. })
  90. uni.login({
  91. provider: "weixin",
  92. success: async loginRes => {
  93. console.log(loginRes)
  94. let code = loginRes.code // 获取开发code
  95. handleFsUserWx({
  96. code: code,
  97. appId:wx.getAccountInfoSync().miniProgram.appId,
  98. userId:data.userId
  99. })
  100. .then( res => {
  101. uni.hideLoading();
  102. if(res.code==200){
  103. console.log("loginFsUserWx:",res)
  104. // this.userinfos=uni.getStorageSync('userinfos')
  105. let token = uni.getStorageSync('TOKEN_WEXIN');
  106. let user = uni.getStorageSync('userInfo')
  107. uni.setStorageSync(TOKEN_KEYAuto, token);
  108. uni.setStorageSync('auto_userInfo', JSON.stringify(user));
  109. this.user = user
  110. this.isLoggedIn = true
  111. // this.getIsAddKf()
  112. }else if(res.code==406){
  113. uni.showToast({
  114. icon:'none',
  115. title: '该用户已成为其他销售会员',
  116. });
  117. }else{
  118. uni.showToast({
  119. icon:'none',
  120. title: res.msg,
  121. });
  122. }
  123. })
  124. },
  125. })
  126. }else{
  127. uni.setStorageSync('H5course',{
  128. companyId: this.urlOption.companyId,
  129. companyUserId:this.urlOption.companyUserId,
  130. type: 1, //1自动,其他手动
  131. })
  132. await this.$store.dispatch('getWebviewUrl');
  133. uni.navigateTo({
  134. url:'/pages_course/webview?H5course='+uni.getStorageSync('H5course')
  135. })
  136. }
  137. },
  138. generateLiveLink() {
  139. // Mocking the link generation based on user ID
  140. // In a real app, this might come from an API
  141. const userId = this.userInfo.userId || this.userInfo.id;
  142. // Example link format
  143. this.liveLink = `https://course.jsbk.com/live/invite?uid=${userId}`;
  144. },
  145. handleCopyLink() {
  146. if (!this.liveLink) {
  147. this.generateLiveLink();
  148. }
  149. uni.setClipboardData({
  150. data: this.liveLink,
  151. success: () => {
  152. uni.showToast({ title: '链接已复制', icon: 'success' });
  153. }
  154. });
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. .container {
  161. min-height: 100vh;
  162. background-color: #f5f5f5;
  163. display: flex;
  164. flex-direction: column;
  165. align-items: center;
  166. &.bg-red {
  167. /* Red gradient background for View 2 */
  168. background: linear-gradient(180deg, #D52C32 0%, #ff4455 20%, #f5f5f5 30%, #f5f5f5 100%);
  169. }
  170. &.bg-redA {
  171. /* Red gradient background for View 2 */
  172. background: linear-gradient(180deg, #ffe1e2 0%, #f3e2e2 20%, #faeaea 30%, #f5f5f5 100%);
  173. }
  174. }
  175. /* View 1 Styles */
  176. .landing-view {
  177. width: 100%;
  178. height: 100vh;
  179. display: flex;
  180. justify-content: center;
  181. padding-top: 150rpx;
  182. // background-color: #f8f8f8;
  183. }
  184. .card {
  185. width: 600rpx;
  186. height: 400rpx;
  187. background: #ffffff;
  188. border-radius: 20rpx;
  189. display: flex;
  190. flex-direction: column;
  191. justify-content: center;
  192. align-items: center;
  193. box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.05);
  194. &:active {
  195. opacity: 0.9;
  196. transform: scale(0.98);
  197. }
  198. .icon-box {
  199. width: 120rpx;
  200. height: 120rpx;
  201. background: #FF4D4F; /* Red background for the icon placeholder */
  202. border-radius: 30rpx;
  203. display: flex;
  204. justify-content: center;
  205. align-items: center;
  206. margin-bottom: 40rpx;
  207. box-shadow: 0 4rpx 10rpx rgba(255, 77, 79, 0.3);
  208. .icon-link {
  209. width: 70rpx;
  210. height: 70rpx;
  211. filter: brightness(0) invert(1); /* Make the icon white */
  212. }
  213. }
  214. .text {
  215. font-size: 30rpx;
  216. color: #666666;
  217. text-align: center;
  218. }
  219. }
  220. /* View 2 Styles */
  221. .success-view {
  222. width: 100%;
  223. padding: 40rpx;
  224. display: flex;
  225. flex-direction: column;
  226. align-items: center;
  227. }
  228. .header-text {
  229. color: #ffffff;
  230. font-size: 28rpx;
  231. line-height: 1.5;
  232. margin-bottom: 40rpx;
  233. text-align: left;
  234. width: 100%;
  235. padding: 0 10rpx;
  236. }
  237. .info-card {
  238. width: 100%;
  239. background: #ffffff;
  240. border-radius: 20rpx;
  241. padding: 40rpx;
  242. box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.05);
  243. margin-bottom: 60rpx;
  244. }
  245. .user-row {
  246. display: flex;
  247. align-items: center;
  248. margin-bottom: 30rpx;
  249. .avatar {
  250. width: 100rpx;
  251. height: 100rpx;
  252. border-radius: 50%;
  253. margin-right: 20rpx;
  254. background-color: #eee;
  255. }
  256. .user-details {
  257. .name {
  258. font-size: 32rpx;
  259. font-weight: bold;
  260. color: #333333;
  261. margin-bottom: 8rpx;
  262. }
  263. .id {
  264. font-size: 24rpx;
  265. color: #999999;
  266. }
  267. }
  268. }
  269. .divider {
  270. height: 1rpx;
  271. background-color: #eeeeee;
  272. width: 100%;
  273. margin-bottom: 30rpx;
  274. }
  275. .detail-row {
  276. display: flex;
  277. justify-content: space-between;
  278. margin-bottom: 20rpx;
  279. font-size: 28rpx;
  280. &:last-child {
  281. margin-bottom: 0;
  282. }
  283. .label {
  284. color: #999999;
  285. }
  286. .value {
  287. color: #333333;
  288. font-weight: 500;
  289. }
  290. }
  291. .copy-btn {
  292. width: 100%;
  293. height: 90rpx;
  294. background: #FF2E4D;
  295. color: #ffffff;
  296. font-size: 32rpx;
  297. border-radius: 45rpx;
  298. display: flex;
  299. justify-content: center;
  300. align-items: center;
  301. box-shadow: 0 8rpx 16rpx rgba(255, 46, 77, 0.3);
  302. &:active {
  303. background: #E02844;
  304. }
  305. &::after {
  306. border: none;
  307. }
  308. }
  309. </style>