uniapp 拍照和从相册选择的弹窗

1、在common创建一个vue,把下列代码复制进去

<template>
  <view>
    <view class="tui-actionsheet-class tui-actionsheet" :class="[show?'tui-actionsheet-show':'']">
      <view class="tui-tips" :style="{fontSize:size+'rpx',color:color}" v-if="tips">
        {{tips}}
      </view>
      <view :class="[isCancel?'tui-operate-box':'']">
        <block v-for="(item,index) in itemList" :key="index">
          <view class="tui-actionsheet-btn tui-actionsheet-divider"
            :class="[(!isCancel && index==itemList.length-1)?'tui-btn-last':'']"
            hover-class="tui-actionsheet-hover" :hover-stay-time="150" :data-index="index"
            :style="{color:item.color || '#1a1a1a'}" @tap="handleClickItem">{{item.text}}</view>
        </block>
      </view>
      <view class="tui-actionsheet-btn tui-actionsheet-cancel" hover-class="tui-actionsheet-hover"
        :hover-stay-time="150" v-if="isCancel" @tap="handleClickCancel">取消</view>
    </view>
    <view class="tui-actionsheet-mask" :class="[show?'tui-mask-show':'']" @tap="handleClickMask"></view>
  </view>
</template>

<script>
  export default {
    name: "tuiActionsheet",
    props: {
      //点击遮罩 是否可关闭
      maskClosable: {
        type: Boolean,
        default: true
      },
      //显示操作菜单
      show: {
        type: Boolean,
        default: false
      },
      //菜单按钮数组,自定义文本颜色,红色参考色:#e53a37
      itemList: {
        type: Array,
        default: function() {
          return [{
            text: "确定",
            color: "#1a1a1a"
          }]
        }
      },
      //提示文字
      tips: {
        type: String,
        default: ""
      },
      //提示文字颜色
      color: {
        type: String,
        default: "#9a9a9a"
      },
      //提示文字大小 rpx
      size: {
        type: Number,
        default: 26
      },
      //是否需要取消按钮
      isCancel: {
        type: Boolean,
        default: true
      }
    },
    methods: {
      handleClickMask() {
        if (!this.maskClosable) return;
        this.handleClickCancel();
      },
      handleClickItem(e) {
        if (!this.show) return;
        const dataset = e.currentTarget.dataset;
        this.$emit('click', {
          index: dataset.index
        });
      },
      handleClickCancel() {
        this.$emit('chooseCancel');
      }
    }
  }
</script>

<style>
  .tui-actionsheet {
    width: 100%;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    visibility: hidden;
    transform: translate3d(0, 100%, 0);
    transform-origin: center;
    transition: all 0.3s ease-in-out;
    background: #eaeaec;
    min-height: 100rpx;
  }

  .tui-actionsheet-show {
    transform: translate3d(0, 0, 0);
    visibility: visible;
  }

  .tui-tips {
    width: 100%;
    padding: 30rpx 60rpx;
    box-sizing: border-box;
    text-align: center;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .tui-operate-box {
    padding-bottom: 12rpx;
  }

  .tui-actionsheet-btn {
    width: 100%;
    height: 100rpx;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 36rpx;
    position: relative;
  }

  .tui-btn-last {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .tui-actionsheet-divider::before {
    content: '';
    width: 100%;
    border-top: 1rpx solid #d9d9d9;
    position: absolute;
    top: 0;
    left: 0;
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
  }

  .tui-actionsheet-cancel {
    color: #1a1a1a;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .tui-actionsheet-hover {
    background: #f7f7f9;
  }

  .tui-actionsheet-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9996;
    transition: all 0.3s ease-in-out;
    opacity: 0;
    visibility: hidden;
  }

  .tui-mask-show {
    opacity: 1;
    visibility: visible;
  }
</style>

2、在需要用的地方引入新创建的vue

import showActionSheet from '@/common/show-action-sheet/index.vue'

components: {
            showActionSheet
        },

3、使用刚引进来的

<show-action-sheet :tips="showActionSheet.tips" :itemList="showActionSheet.itemList"
            :show="showActionSheet.show" :maskClosable="showActionSheet.maskClosable"
            :isCancel="showActionSheet.isCancel" @chooseCancel="chooseCancel" @click="click"></show-action-sheet>

在data里面:

showActionSheet: {
                    show: false,
                    maskClosable: true,
                    itemList: [{
                            text: "拍摄",
                            color: "#333"
                        },
                        {
                            text: "从相册选择",
                            color: "#333"
                        },
                    ],
                    color: "#9a9a9a",
                    size: 26,
                    isCancel: true
                },

关闭弹窗
this.showActionSheet.show = false;

打开弹窗

this.showActionSheet.show = true;

弹窗里面的取消

chooseCancel() {
                this.showActionSheet.show = false;
            },

点击的是弹窗的那个

click(e){

console.log(e);

}

本人纯属记录

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在uniapp中实现地图打点和点击功能,可以使用uni-app官方提供的uni-ui组件库中的u-map组件来实现。 以下是实现步骤: 1. 引入u-map组件 在需要使用地图的页面中,引入u-map组件: ```html <template> <view> <u-map :key="mapKey" :markers="markers" @markertap="onMarkerTap"></u-map> </view> </template> <script> import uMap from '@/uni-ui/u-map/u-map.vue' export default { components: { uMap }, data() { return { mapKey: 'your map key', markers: [ { id: 1, latitude: 39.90469, longitude: 116.40717, title: '北京市', iconPath: '/static/img/marker.png', width: 30, height: 30 } ] } }, methods: { onMarkerTap(marker) { uni.showToast({ title: marker.title, icon: 'none' }) } } } </script> ``` 在上述代码中,我们引入了u-map组件,并在data中定义了一个mapKey属性和一个markers属性。其中,mapKey是你申请的地图key,markers是地图上的标记点数组。 2. 配置地图key 在uniapp的manifest.json文件中,配置地图key: ```json { "app-plus": { "modules": { "map": { "apiKey": "your map key" } } } } ``` 3. 配置标记点 在markers数组中,我们配置了一个标记点,包括id、latitude、longitude、title、iconPath、width和height等属性。其中,latitude和longitude表示标记点的经纬度,title表示标记点的标题,iconPath表示标记点的图标路径,width和height表示标记点的宽度和高度。 4. 点击 我们在u-map组件上监听markertap事件,当用户点击标记点时,会触发该事件并传入被点击的标记点对象。我们可以在该事件中出一个提示框,显示标记点的标题。 在onMarkerTap方法中,我们使用uni.showToast方法出一个提示框,显示标记点的标题。 至此,我们就实现了在uniapp中使用u-map组件实现地图打点和点击功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值