修改部分自写公共组件代码

This commit is contained in:
YeMingfei666 2024-09-28 15:05:54 +08:00
parent c3d4f1d78c
commit 1aa502103b
4 changed files with 100 additions and 58 deletions

View File

@ -105,7 +105,7 @@ import { computed } from 'vue';
margin: auto;
}
.shadow{
box-shadow: 0 0 10px #999;
box-shadow: 0 0 10px #aaa;
}
.btn {
font-size: 28rpx;

View File

@ -1,10 +1,11 @@
<template>
<view class="my-radio u-font-28 u-flex color-333" @tap.stop="changeVal" >
<view class="circle u-flex u-row-center" :style="computedStyle()" :class="{active:modelValue,square:shape==='square'}">
<view class="my-radio u-font-28 u-flex color-333" @tap.stop="changeVal">
<view class="circle u-flex u-row-center" :style="computedStyle()"
:class="{active:modelValue,square:shape==='square'}">
<uni-icons type="checkmarkempty" v-if="modelValue" :size="size-4" color="#fff"></uni-icons>
</view>
<view class="u-m-l-12">
{{text}}
<slot>{{text}}</slot>
</view>
</view>
</template>
@ -14,11 +15,11 @@
} from 'vue'
import color from '@/commons/color.js'
const props = defineProps({
disabled:{
disabled: {
type: [Boolean],
default: false
},
borderColor:{
borderColor: {
type: String,
default: '#bbb',
},
@ -29,10 +30,10 @@
},
// v-modal
modelValue: {
type: [Number,Boolean],
type: [Number, Boolean],
default: false,
},
shape:{
shape: {
//circle square
type: String,
default: 'circle',
@ -52,18 +53,19 @@
`
}
const emits = defineEmits(['update:modelValue', 'change'])
function changeVal() {
if(props.disabled){
if (props.disabled) {
return
}
emits('click')
let currentVal=props.modelValue
let type=typeof currentVal
if(type==='number'){
currentVal=currentVal===0?1:0
let currentVal = props.modelValue
let type = typeof currentVal
if (type === 'number') {
currentVal = currentVal === 0 ? 1 : 0
}
if(type==='boolean'){
currentVal=!currentVal
if (type === 'boolean') {
currentVal = !currentVal
}
emits('update:modelValue', currentVal)
emits('change', currentVal)
@ -75,7 +77,7 @@
.circle {
background: #FFFFFF;
&.active {
background-color: $my-main-color;
border-color: $my-main-color;
@ -84,7 +86,8 @@
border: 1px solid #707070;
border-radius: 50%;
overflow: hidden;
&.square{
&.square {
border-radius: 8rpx;
}
}

View File

@ -6,7 +6,7 @@
<view class="left-line" :class="{hide:index==list.length-1}"></view>
</view>
<view class="u-p-l-12 ">
<view class="u-font-20">{{item[titleKey]||''}}</view>
<view class="u-font-20">{{formatTitle(item[titleKey]||'') }}</view>
<view class="u-font-24 u-m-t-2">{{item[contentKey]||''}}</view>
</view>
</view>
@ -14,6 +14,7 @@
</template>
<script setup>
import dayjs from 'dayjs';
const props = defineProps({
active: {
type: [String, Number],
@ -32,6 +33,10 @@
default: 'content'
}
})
function formatTitle(time){
return dayjs(time).format('YYYY-M-D HH:MM:ss')
}
</script>
<style lang="scss" scoped>

View File

@ -1,69 +1,103 @@
<template>
<up-upload :fileList="images" @afterRead="afterRead" @delete="deletePic" :multiple="multiple"
:width="width" :height="height"
:maxCount="10"></up-upload>
<up-upload :fileList="images" @afterRead="afterRead" @delete="deletePic" :multiple="multiple" :width="width"
:height="height" :maxCount="maxCount"></up-upload>
</template>
<script setup>
import {$uploadFile} from '@/http/yskApi/file.js'
import {
ref, watch
$uploadFile
} from '@/http/yskApi/file.js'
import {
ref,
watch
} from 'vue';
const props=defineProps({
modelValue:{
type:Array,
default:()=>[]
const props = defineProps({
modelValue: {
type: Array,
default: () => []
},
width:{
type:[String,Number],
default:60
width: {
type: [String, Number],
default: 60
},
height:{
type:[String,Number],
default:60
height: {
type: [String, Number],
default: 60
},
multiple:{
type:Boolean,
default:true
maxCount: {
type: [Number],
default: 10
},
multiple: {
type: Boolean,
default: true
}
})
const emits=defineEmits(['update:modelValue'])
const emits = defineEmits(['update:modelValue'])
const images = ref(props.modelValue)
function afterRead(e){
for(let i in e.file){
const file=e.file[i].file
function afterRead(e) {
console.log(e);
if (Array.isArray(e)) {
for (let i in e.file) {
const file = e.file[i].file
$uploadFile(file).then(res => {
console.log(res);
images.value.push({
url: e.file[i].url,
serveUrl: res.data[0]
})
}).catch(res => {
console.log(res);
if (res.errMsg) {
images.value.splice(i, 1)
uni.showToast({
title: '图片大小超出限制',
icon: 'error'
})
}
})
}
}else{
const i=0
const file = e.file.file
$uploadFile(file).then(res => {
console.log(res);
images.value.push({
url: e.file[i].url,
url: e.file.url,
serveUrl: res.data[0]
})
}).catch(res=>{
}).catch(res => {
console.log(res);
if(res.errMsg){
images.value.splice(i,1)
if (res.errMsg) {
images.value.splice(i, 1)
uni.showToast({
title:'图片大小超出限制',
icon:'error'
title: '图片大小超出限制',
icon: 'error'
})
}
})
}
}
function deletePic(e){
const {index}=e
images.value.splice(index,1)
function deletePic(e) {
const {
index
} = e
images.value.splice(index, 1)
}
watch(()=>images.value,(newval)=>{
emits('update:modelValue',newval)
watch(() => images.value, (newval) => {
emits('update:modelValue', newval)
})
watch(()=>props.modelValue,(newval)=>{
images.value=newval
watch(() => props.modelValue, (newval) => {
images.value = newval
})
</script>