index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="index">
  3. <capsule :showBorder="true" bgColor="transparent">
  4. <template v-slot:top>
  5. <view class="detail-top">
  6. <view class="top-left" @click="openDrawer">
  7. <image class="" src="@/static/images/catalogue_icon.png" />
  8. </view>
  9. <view class="top-text">团蜂电子名片</view>
  10. </view>
  11. </template>
  12. </capsule>
  13. <view class="seat"></view>
  14. <view class="box-bg">
  15. <!-- <view class="bg"></view> -->
  16. </view>
  17. <view class="container">
  18. <view
  19. class="card-list"
  20. :style="{ height: cardListHeight + 'rpx' }"
  21. v-if="cardList.length > 0"
  22. >
  23. <view
  24. class="card-item"
  25. v-for="(item, index) in cardList"
  26. :key="index"
  27. :style="{ top: index * 120 + 'rpx', zIndex: index }"
  28. @click.stop="goCard('/pages_module/myCard/index?id=' + item.id)"
  29. >
  30. <cardCom :cardData="item" :imgSerial="item.style"></cardCom>
  31. </view>
  32. <!-- <view class="card-item" v-for="item in 3" :key="item" :style="{top: (item)*120 + 'rpx'}">
  33. <cardCom></cardCom>
  34. </view> -->
  35. </view>
  36. <view class="empty-box" v-else>
  37. <image src="@/static/images/empty-card.png" />
  38. <text>暂未添加名片</text>
  39. </view>
  40. <view class="card-btn">
  41. <button @click="addCard">+&nbsp; &nbsp;&nbsp;新增名片</button>
  42. </view>
  43. </view>
  44. <tui-drawer mode="left" :visible="visible" @close="closeDrawer">
  45. <view class="d-container">
  46. <view class="d-image">
  47. <template v-if="cardList[0].head">
  48. <image class="" :src="cardList[0].head" />
  49. </template>
  50. <template v-else>
  51. <image class="" src="@/static/images/default_avatar.png" />
  52. </template>
  53. <text>{{ cardList[0].name }}</text>
  54. </view>
  55. <view class="quit" @click="quitLogin">退出登录</view>
  56. </view>
  57. </tui-drawer>
  58. <!-- <tui-modal
  59. :show="modal"
  60. :button="[{ text: '确定', type: 'red', plain: false }]"
  61. @click="handleClick"
  62. @cancel="hideModal"
  63. title="提示"
  64. content="您还未登录,是否需要登录?"
  65. ></tui-modal> -->
  66. <tui-bottom-popup
  67. :zIndex="1000"
  68. backgroundColor="#FFFFFF"
  69. :show="modal"
  70. @close="clonePopup"
  71. >
  72. <view class="tf-login">
  73. <tui-icon
  74. class="close"
  75. name="shut"
  76. :size="24"
  77. color="#1C1B1E"
  78. @click="modal = false"
  79. ></tui-icon>
  80. <view class="tf-container">
  81. <image class="" src="@/static/images/index-select.png" />
  82. <text>登录团蜂电子名片</text>
  83. </view>
  84. <view class="tf-agreement">
  85. <checkbox-group @change="changeBox">
  86. <checkbox :checked="false" value="check" color="#0E40FF" />
  87. </checkbox-group>
  88. <view @click="goPrivacy">
  89. 已阅读并同意<text>团蜂电子名片服务协议</text>和<text>隐私政策</text>
  90. </view>
  91. </view>
  92. <view class="tf-btn">
  93. <button @click="handleClick">快捷授权登录</button>
  94. </view>
  95. </view>
  96. </tui-bottom-popup>
  97. </view>
  98. </template>
  99. <script>
  100. import cardCom from "@/components/cardCom/index.vue";
  101. import { wxLoginApi, getCardListApi } from "@/api/index.js";
  102. export default {
  103. components: {
  104. cardCom,
  105. },
  106. onShow() {
  107. // 判断是否登录
  108. if (!this.$cache.getCache("token")) return;
  109. this.getCardList();
  110. },
  111. computed: {
  112. // 计算高度
  113. cardListHeight() {
  114. let num = 308 + this.cardList.length * 120;
  115. return num;
  116. },
  117. },
  118. data() {
  119. return {
  120. visible: false,
  121. top: null,
  122. modal: false,
  123. checkList: [],
  124. // 卡片列表
  125. cardList: [],
  126. };
  127. },
  128. methods: {
  129. changeBox(list) {
  130. this.checkList = list.detail.value;
  131. },
  132. // 去到隐私页面
  133. goPrivacy() {
  134. uni.navigateTo({
  135. url: "/pages_module/privacy/index",
  136. });
  137. },
  138. // 获取当前用户所有名片
  139. async getCardList() {
  140. let { data, statusCode } = await getCardListApi();
  141. if (statusCode == 50000) {
  142. this.modal = true;
  143. this.cardList = [];
  144. return;
  145. }
  146. this.cardList = data;
  147. },
  148. // 打开侧边弹框
  149. openDrawer() {
  150. if (!this.$cache.getCache("token")) {
  151. this.modal = true;
  152. return;
  153. }
  154. this.visible = true;
  155. },
  156. // 关闭侧边弹框
  157. closeDrawer() {
  158. this.visible = false;
  159. },
  160. // 新增卡片
  161. addCard() {
  162. // 获取本地 token
  163. const flag = this.$cache.getCache("token");
  164. if (!flag) {
  165. this.modal = true;
  166. return;
  167. }
  168. uni.navigateTo({
  169. url: "/pages_module/establish/index",
  170. });
  171. },
  172. // 退出登录
  173. quitLogin() {
  174. // #ifdef MP-WEIXIN
  175. wx.showModal({
  176. title: "提示",
  177. content: "是否退出当前登录的账号",
  178. success: async (res) => {
  179. if (res.confirm) {
  180. this.$cache.removeCache("token");
  181. this.cardList = [];
  182. this.visible = false;
  183. }
  184. },
  185. });
  186. // #endif
  187. },
  188. handleClick(e) {
  189. console.log(this.checked);
  190. if (this.checkList.length <= 0) {
  191. uni.showToast({
  192. title: "请先阅读并同意协议",
  193. icon: "none",
  194. });
  195. return;
  196. }
  197. // 微信登录
  198. this.$loading.show("登录中...");
  199. // #ifdef MP-WEIXIN
  200. wx.login({
  201. success: async (res) => {
  202. let codeRes = await wxLoginApi({ code: res.code });
  203. if (codeRes.statusCode !== 20000) return;
  204. // 获取名片列表
  205. this.getCardList();
  206. // 存储 token 到本地
  207. this.$cache.setCache("token", codeRes.data);
  208. this.modal = false;
  209. },
  210. complete: () => {
  211. this.$loading.hide();
  212. },
  213. });
  214. // #endif
  215. },
  216. hideModal() {
  217. this.modal = false;
  218. },
  219. goCard(url) {
  220. uni.navigateTo({
  221. url: url,
  222. });
  223. },
  224. },
  225. };
  226. </script>
  227. <style lang="scss" scoped>
  228. @import "./index.scss";
  229. </style>