123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- // components/imageViewer/index.js
- import api from '../../api/api'
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- list:{
- value:'',
- type:Array
- },
- isdelete:{
- type:Boolean,
- value:true
- },
- },
- /**
- * 组件的初始数据
- */
- data: {
- visible: false,
- showIndex: false,
- closeBtn: false,
- deleteBtn: false,
- images2:[],
- gridConfig: {
- column: 5,
- width: 120,
- height: 120,
- },
- },
- /**
- * 组件的方法列表
- */
- lifetimes:{
- attached () {
- setTimeout(() => {
- this.setData({
- images2:this.data.list.map(e=>{
- return {url:e.url,type:this.validateImageType(e.postfix),linksid:e.linksid}
- })
- })
- console.log(this.data.images2)
- }, 1000);
- }
- },
- methods: {
- validateImageType(file) {
- const allowedTypes = /(\jpg|\jpeg|\png|\gif)$/i;
- const allowedTypes1 = /(\mp4|\mov|\3gp|\3g2)$/i;
- if (allowedTypes.test(file)) {
- return 'image'
- } else if (allowedTypes1.test(file)) {
- return 'video'
- } else {
- return 'file'
- }
- },
- async deleteFile (data) {
- const res = await api._post({
- "classname": "system.attachment.Attachment",
- "method": "deleteFileLink",
- "content": {
- "linksids": [data.detail.file.linksid]
- }
- })
- if (res.code == 1) {
- this.setData({
- images2:this.data.images2.filter(e=>{
- return e.linksid !== data.detail.file.linksid
- })
- })
- }
- else {
- wx.showToast({
- title: res.data,
- icon:'none'
- })
- }
- }
- }
- })
|