123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <template>
- <view class="u-demo">
- <view class="u-demo-wrap">
- <view class="u-demo-title">演示效果</view>
- <view class="u-demo-area">
- <u-toast ref="uToast"></u-toast>
- <view class="u-avatar-wrap">
- <image @tap="preAvatar" class="u-avatar-demo" v-if="avatar" :src="avatar" mode="aspectFill"></image>
- </view>
- <u-button @click="chooseAvatar">选择图片</u-button>
- </view>
- </view>
-
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- avatar: 'https://cdn.uviewui.com/uview/common/logo.png',
- }
- },
- created() {
- uni.$on('uAvatarCropper', path => {
- this.avatar = path;
-
-
-
-
-
-
-
-
-
- })
- },
- methods: {
- chooseAvatar() {
- this.$u.route({
- url: '/uview-ui/components/u-avatar-cropper/u-avatar-cropper',
- params: {
-
- destWidth: 300,
-
- rectWidth: 200,
-
- fileType: 'jpg',
- }
- })
- },
- qualityChange(index) {
- this.quality = index == 0 ? 0.3 : index == 1 ? 0.7 : 1;
- },
- styleChange(index) {
- if (index == 0) {
- this.rectHeight = this.rectWidth = this.destHeight = this.destWidth = 200;
- this.boundStyle = {
- lineWidth: 8,
- borderColor: this.$u.color['error'],
- mask: 'rgba(0, 0, 0, 0.8)'
- }
- } else {
- this.rectHeight = this.rectWidth = this.destHeight = this.destWidth = 400;
- this.boundStyle = {
- lineWidth: 4,
- borderColor: 'rgb(245, 245, 245)',
- mask: 'rgba(0, 0, 0, 0.35)'
- }
- }
- },
-
- preAvatar() {
- wx.previewImage({
- current: '',
- urls: [this.avatar]
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .wrap {
- padding: 24rpx;
- }
- .u-avatar-wrap {
- overflow: hidden;
- margin-bottom: 20rpx;
- }
- .u-avatar-demo {
- width: 150rpx;
- height: 150rpx;
- border-radius: 100rpx;
- }
- </style>
|