123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <template>
- <view>
- <!--#ifdef APP-PLUS-->
- <view class="lz-status_bar">
- <view class="lz-top_view"></view>
- </view>
- <!--#endif-->
- <view class="kaoshi-head">
- <view class="kaoshi-head-top">
- <view class="kaoshi-head-left" @tap="$navigateBack">
- <view class="icon icon-zuojiantou"></view>
- </view>
- <view class="kaoshi-head-m">头像</view>
- </view>
- </view>
- <view>
- <sunui-upbasic :upImgConfig="upImgBasic" @onUpImg="upBasicData" @onImgDel="delImgInfo" ref="uImage">
- </sunui-upbasic>
- <button type="primary" @tap="uImageTap">提交</button>
- </view>
- </view>
- </template>
- <script>
- import sunuiUpbasic from '@/src/components/sunui-upimg/sunui-upimg-basic.vue'
- import {
- mapState
- } from 'vuex'
- export default {
- data() {
- return {
- basicArr: [],
- // 基础版配置
- upImgBasic: {
- // 后端图片接口地址
- basicConfig: {
- url: 'http://rrf.quanyouyisheng.com/api/common/upload',
- },
- // 是否开启提示(提醒上传图片的数量)
- // tips: false,
- // 是否开启notli(开启的话就是选择完直接上传,关闭的话当count满足数量时才上传)
- notli: false,
- // 图片数量
- count: 1,
- // 相机来源(相机->camera,相册->album,两者都有->all,默认all)
- sourceType: 'camera',
- // 是否压缩上传照片(仅小程序生效)
- sizeType: true,
- // 上传图片背景修改
- upBgColor: '#E8A400',
- // 上传icon图标颜色修改(仅限于iconfont)
- upIconColor: '#fff',
- // 上传svg图标名称
- // upSvgIconName: 'icon-card',
- // 上传文字描述(仅限四个字)
- // upTextDesc: '上传证书',
- // 删除按钮位置(left,right,bleft,bright),默认右上角
- delBtnLocation: '',
- // 是否隐藏添加图片
- // isAddImage: false,
- // 是否隐藏删除图标
- // isDelIcon: false,
- // 删除图标定义背景颜色
- // delIconColor: '',
- // 删除图标字体颜色
- // delIconText: '',
- // 上传图标替换(+),是个http,https图片地址(https://www.playsort.cn/right.png)
- iconReplace: '',
- header: {}
- }
- };
- },
- computed: {
- ...mapState(['subject', 'userinfo']),
- },
- components: {
- sunuiUpbasic
- },
- onLoad() {
- this.upImgBasic.basicConfig.url = this.upImgBasic.basicConfig.url + '?tokne=' + this.userinfo.token;
- this.upImgBasic.header = {
- token: this.userinfo.token
- };
- },
- methods: {
- // 手动上传图片(适用于表单等上传) -2019/05/10增加
- uImageTap() {
- this.$refs.uImage.uploadimage(this.upImgBasic);
- },
- // 删除图片 -2019/05/12(本地图片进行删除)
- async delImgInfo(e) {
- console.log('你删除的图片地址为:', e, this.basicArr.splice(e.index, 1));
- },
- // 基础版
- async upBasicData(e) {
- console.log('===>', e);
- // 上传图片数组
- let arrImg = [];
- for (let i = 0, len = e.length; i < len; i++) {
- try {
- if (e[i].path_server != "") {
- await arrImg.push(e[i].path_server.split(','));
- }
- } catch (err) {
- console.log('上传失败...');
- }
- }
- // 图片信息保存到data数组
- this.basicArr = arrImg;
- // 可以根据长度来判断图片是否上传成功. 2019/4/11新增
- if (arrImg.length == this.upImgBasic.count) {
- uni.showToast({
- title: `上传成功`,
- icon: 'none'
- });
- }
- },
- // 获取上传图片basic
- getUpImgInfoBasic() {
- console.log('后端转成一维数组:', this.basicArr.join().split(','));
- }
- }
- }
- </script>
- <style>
- </style>
|