123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <template>
- <view class="index">
- <capsule :showBorder="true" bgColor="transparent">
- <template v-slot:top>
- <view class="detail-top">
- <view class="top-left" @click="openDrawer">
- <image class="" src="@/static/images/catalogue_icon.png" />
- </view>
- <view class="top-text">团蜂电子名片</view>
- </view>
- </template>
- </capsule>
- <view class="seat"></view>
- <view class="box-bg">
- <!-- <view class="bg"></view> -->
- </view>
- <view class="container">
- <view
- class="card-list"
- :style="{ height: cardListHeight + 'rpx' }"
- v-if="cardList.length > 0"
- >
- <view
- class="card-item"
- v-for="(item, index) in cardList"
- :key="index"
- :style="{ top: index * 120 + 'rpx', zIndex: index }"
- @click.stop="goCard('/pages_module/myCard/index?id=' + item.id)"
- >
- <cardCom :cardData="item" :imgSerial="item.style"></cardCom>
- </view>
- <!-- <view class="card-item" v-for="item in 3" :key="item" :style="{top: (item)*120 + 'rpx'}">
- <cardCom></cardCom>
- </view> -->
- </view>
- <view class="empty-box" v-else>
- <image src="@/static/images/empty-card.png" />
- <text>暂未添加名片</text>
- </view>
- <view class="card-btn">
- <button @click="addCard">+ 新增名片</button>
- </view>
- </view>
- <tui-drawer mode="left" :visible="visible" @close="closeDrawer">
- <view class="d-container">
- <view class="d-image">
- <template v-if="cardList[0].head">
- <image class="" :src="cardList[0].head" />
- </template>
- <template v-else>
- <image class="" src="@/static/images/default_avatar.png" />
- </template>
- <text>{{ cardList[0].name }}</text>
- </view>
- <view class="quit" @click="quitLogin">退出登录</view>
- </view>
- </tui-drawer>
- <tui-modal
- :show="modal"
- :button="[{ text: '确定', type: 'red', plain: false }]"
- @click="handleClick"
- @cancel="hideModal"
- title="提示"
- content="您还未登录,是否需要登录?"
- ></tui-modal>
- </view>
- </template>
- <script>
- import cardCom from "@/components/cardCom/index.vue";
- import { wxLoginApi, getCardListApi } from "@/api/index.js";
- export default {
- components: {
- cardCom,
- },
- onShow() {
- // 判断是否登录
- if (!this.$cache.getCache("token")) return;
- this.getCardList();
- },
- computed: {
- // 计算高度
- cardListHeight() {
- let num = 308 + this.cardList.length * 120;
- return num;
- },
- },
- data() {
- return {
- visible: false,
- top: null,
- modal: false,
- // 卡片列表
- cardList: [],
- };
- },
- methods: {
- // 获取当前用户所有名片
- async getCardList() {
- let { data } = await getCardListApi();
- this.cardList = data;
- },
- // 打开侧边弹框
- openDrawer() {
- if (!this.$cache.getCache("token")){
- this.modal = true;
- return
- }
- this.visible = true;
- },
- // 关闭侧边弹框
- closeDrawer() {
- this.visible = false;
- },
- // 新增卡片
- addCard() {
- // 获取本地 token
- const flag = this.$cache.getCache("token");
- if (!flag) {
- this.modal = true;
- return;
- }
- uni.navigateTo({
- url: "/pages_module/establish/index",
- });
- },
- // 退出登录
- quitLogin() {
- // #ifdef MP-WEIXIN
- wx.showModal({
- title: "提示",
- content: "是否退出当前登录的账号",
- success: async (res) => {
- if (res.confirm) {
- this.$cache.removeCache("token");
- this.cardList = [];
- this.visible = false;
- }
- },
- });
- // #endif
- },
- handleClick(e) {
- // 微信登录
- this.$loading.show("登录中...");
- // #ifdef MP-WEIXIN
- wx.login({
- success: async (res) => {
- let codeRes = await wxLoginApi({ code: res.code });
- // 获取名片列表
- this.getCardList();
- // 存储 token 到本地
- this.$cache.setCache("token", codeRes.data);
- this.modal = false;
- },
- complete: () => {
- this.$loading.hide();
- },
- });
- // #endif
- },
- hideModal() {
- this.modal = false;
- },
- goCard(url) {
- uni.navigateTo({
- url: url,
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- @import "./index.scss";
- </style>
|