抖音平台小程序

my.vue 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view class="page-wrap" :style="{ 'padding-top': `${pageContentTop}px;` }">
  3. <!-- S 用户信息 -->
  4. <view class="user-wrap">
  5. <view class="lt-wrap">
  6. <image class="avatar" :src="appLogo" />
  7. </view>
  8. <view class="rt-wrap">
  9. <view class="name">登录账号</view>
  10. <view class="id">ID:{{ userInfo.name || "-" }}</view>
  11. </view>
  12. </view>
  13. <!-- E 用户信息 -->
  14. <view class="line"></view>
  15. <!-- S 菜单入口 -->
  16. <view class="menu-wrap">
  17. <block v-for="menu in menuList" :key="menu.id">
  18. <view class="menu-item-wrap" @click="onClickMenu(menu.id)">
  19. <view class="lt">
  20. <image class="icon" :src="menu.icon" />
  21. <text class="label">{{ menu.label }}</text>
  22. </view>
  23. <view class="rt">
  24. <image class="arrow" src="/static/imgs/icon-jt.png" />
  25. </view>
  26. <!-- 联系客服入口 -->
  27. <button
  28. v-if="menu.id === 'lxkf' && imId"
  29. open-type="im"
  30. :data-im-id="imId"
  31. class="im-btn"
  32. @im="onImSuccess"
  33. @error="onImError"
  34. >
  35. 跳转 IM
  36. </button>
  37. </view>
  38. </block>
  39. </view>
  40. <!-- E 菜单入口 -->
  41. </view>
  42. </template>
  43. <script>
  44. const app = getApp();
  45. export default {
  46. components: {},
  47. data() {
  48. return {
  49. appName: app.globalData.$appInfo.appName,
  50. appLogo: app.globalData.$appInfo.appLogo,
  51. pageContentTop: app.globalData.pageContentTop,
  52. menuList: [
  53. { id: "gkls", label: "观看历史", icon: "/static/imgs/icon-ls.png" },
  54. { id: "wxhd", label: "我喜欢的", icon: "/static/imgs/icon-sc.png" },
  55. { id: "lxkf", label: "联系客服", icon: "/static/imgs/icon-kf.png" },
  56. ],
  57. userInfo: {
  58. name: "",
  59. },
  60. imId: "", // 客服抖音号
  61. };
  62. },
  63. onLoad() {
  64. app.handleSetNavTitle();
  65. this.handleGetImId();
  66. },
  67. onShow() {
  68. this.handleGetUserInfo();
  69. },
  70. methods: {
  71. async handleGetImId() {
  72. try {
  73. const url = this.$api.my_getService;
  74. const params = {};
  75. const { data: res = {} } = await this.$postJSON(url, params);
  76. console.log('res => ', res)
  77. if (res && res.errno == 0) {
  78. this.imId = res.rst.account
  79. } else {
  80. uni.showToast({ title: res.err || "操作失败", icon: "none" });
  81. }
  82. } catch (error) {
  83. console.log('error => ', error)
  84. } finally {
  85. }
  86. },
  87. async handleGetUserInfo() {
  88. const openid = uni.getStorageSync("openid") || "";
  89. if (openid) {
  90. this.userInfo.name = openid.slice(-6); // 展示后六位字符
  91. } else {
  92. const { openid } = await app.handleLogin();
  93. this.userInfo.name = openid.slice(-6); // 展示后六位字符
  94. }
  95. },
  96. onClickMenu(menuId) {
  97. if (menuId === "gkls") {
  98. // 观看历史
  99. uni.navigateTo({
  100. url: "/pages/subPackages/history/index",
  101. });
  102. } else if (menuId === "wxhd") {
  103. // 我喜欢的
  104. uni.navigateTo({
  105. url: "/pages/subPackages/like/index",
  106. });
  107. } else if (menuId === "lxkf") {
  108. // 联系客服
  109. if (!this.imId) uni.showToast({ title: "敬请期待", icon: "none" });
  110. }
  111. },
  112. onImSuccess(e) {
  113. console.log("onImSuccess => e", e);
  114. },
  115. onImError(e) {
  116. console.log("onImError => ", e);
  117. uni.showToast({ title: `异常:${e.detail.errMsg}`, icon: "none" });
  118. },
  119. },
  120. };
  121. </script>
  122. <style lang="scss" scoped>
  123. .page-wrap {
  124. min-height: 100vh;
  125. background: url(https://dou-smallapp.oss-cn-beijing.aliyuncs.com/static/bg-01.png)
  126. #ffffff no-repeat;
  127. background-size: 750rpx 524rpx;
  128. background-color: #fff;
  129. .user-wrap {
  130. display: flex;
  131. align-items: center;
  132. margin: 60rpx 0 0 40rpx;
  133. .lt-wrap {
  134. width: 168rpx;
  135. height: 168rpx;
  136. .avatar {
  137. width: 100%;
  138. height: 100%;
  139. border-radius: 50%;
  140. }
  141. }
  142. .rt-wrap {
  143. margin-left: 36rpx;
  144. .name {
  145. font-weight: 600;
  146. font-size: 34rpx;
  147. color: #000000;
  148. line-height: 48rpx;
  149. font-style: normal;
  150. }
  151. .id {
  152. margin-top: 30rpx;
  153. font-weight: 400;
  154. font-size: 28rpx;
  155. color: #333333;
  156. line-height: 40rpx;
  157. font-style: normal;
  158. }
  159. }
  160. }
  161. .line {
  162. margin: 64rpx 68rpx 0;
  163. width: 614rpx;
  164. height: 2rpx;
  165. background: #e6e6e6;
  166. }
  167. .menu-wrap {
  168. padding: 96rpx 70rpx 0;
  169. .menu-item-wrap {
  170. position: relative;
  171. display: flex;
  172. align-items: center;
  173. justify-content: space-between;
  174. margin-bottom: 70rpx;
  175. .lt {
  176. display: flex;
  177. align-items: center;
  178. .icon {
  179. width: 48rpx;
  180. height: 48rpx;
  181. }
  182. .label {
  183. margin-left: 16rpx;
  184. font-weight: 400;
  185. font-size: 28rpx;
  186. color: #333333;
  187. line-height: 40rpx;
  188. font-style: normal;
  189. }
  190. }
  191. .rt {
  192. .arrow {
  193. width: 38rpx;
  194. height: 38rpx;
  195. }
  196. }
  197. .im-btn {
  198. position: absolute;
  199. top: 0;
  200. left: 0;
  201. width: 100%;
  202. height: 100%;
  203. opacity: 0;
  204. }
  205. }
  206. }
  207. }
  208. </style>