Browse Source

feat: 完善代码

jinx 2 years ago
parent
commit
5d26cb4291

+ 5 - 1
src/components/files/TagEditor.vue

@@ -32,6 +32,7 @@
             </footer>
         </div>
         <Toast v-if="showTips" type="warn" :content="showTips" :close="() => (showTips = null)" />
+        <Loading v-if="showLoading"></Loading>
     </div>
 </template>
 <script setup>
@@ -40,12 +41,13 @@ import { convertBlob2File } from '@/utils/file'
 import { http } from '@/utils/request'
 import browser from '@/utils/browser'
 import Toast from '@/components/dialog/Toast'
+import Loading from '@/components/loading/Loading.vue'
 import UiArea from '../form/Area.vue'
 import UiInput from '../form/Input.vue'
 import UiMedias from '../form/medias'
 import UiSelectList from '../form/SelectList.vue'
 import { from } from 'readable-stream'
-
+const showLoading = ref(false)
 const showTips = ref(null)
 const projectId = browser.valueFromUrl('projectId') || 1
 const notify = inject('notify')
@@ -119,6 +121,7 @@ const onSubmit = async () => {
     await handlerUpload(tag)
 }
 const handlerUpload = async data => {
+    showLoading.value = true
     if (mediaList.length) {
         for (let i = 0; i < mediaList.length; i++) {
             if (mediaList[i].file) {
@@ -153,6 +156,7 @@ const handlerUpload = async data => {
     }
 
     http.post(`smart-site/marking/addOrUpdate`, params).then(response => {
+        showLoading.value = false
         if (response.success) {
             notify.value.status = tag.status
             notify.value.members = tag.members

+ 4 - 3
src/components/files/TagView.vue

@@ -306,9 +306,10 @@ onBeforeUnmount(() => {
         overflow: hidden;
         > div {
             width: 50%;
-            &:first-child {
-                border-right: solid 1px rgba(255, 255, 255, 0.16);
-            }
+            
+            // &.left-item {
+            //     border-right: solid 1px rgba(255, 255, 255, 0.16);
+            // }
         }
     }
 

+ 69 - 42
src/components/files/content/Comment.vue

@@ -8,7 +8,7 @@
                     <div class="avatar-box" :style="i.head ? `background-image:url(${i.head});` : `background-image:url(${emptyAvatar});`"></div>
                     <div class="comment-box">
                         <div class="view-box view-top">
-                            <span class="user-name">{{ i.nickName }}</span>
+                            <span class="user-name">{{ i.nickName || '未知用户' }}</span>
                             <i class="iconfont icon-del" v-if="i.userId == userId" @click="delComment({ commentId: i.commentId, index })"></i>
                         </div>
                         <div class="view-box view-middle">
@@ -23,20 +23,20 @@
                                 <div class="avatar-box" :style="j.head ? `background-image:url(${j.head});` : `background-image:url(${emptyAvatar});`"></div>
                                 <div class="reply-box">
                                     <div class="view-box view-top">
-                                        <span class="user-name">{{ j.nickName }}</span>
+                                        <span class="user-name">{{ j.nickName || '未知用户' }}</span>
                                         <i class="iconfont icon-del" v-if="j.userId == userId" @click="delComment({ commentId: j.commentId, index: j_index, parentIndex: index })"></i>
                                     </div>
                                     <div class="view-box view-middle">
                                         <span class="reply-text"
                                             ><span v-if="j.replyId"
-                                                >回复<span class="reply-tips">@{{ j.replyNickName }}</span></span
+                                                >回复<span class="reply-tips">@{{ j.replyNickName || '未知用户' }}</span></span
                                             >
                                             {{ j.content }}</span
                                         >
                                     </div>
                                     <div class="view-box view-bottom">
                                         <span class="reply-time">{{ j.createTime }}</span>
-                                        <span class="reply-btn" @click="handlerReply({ parentId: i.commentId, replyId: j.commentId, parentUserId: j.userId, nickName: i.nickName }, j_index)"
+                                        <span class="reply-btn" @click="handlerReply({ parentId: i.commentId, replyId: j.commentId, parentUserId: j.userId, nickName: j.nickName }, j_index)"
                                             >回复</span
                                         >
                                     </div>
@@ -58,6 +58,12 @@
         </div>
     </div>
     <Toast v-if="showTips" :type="tipsType" :content="showTips" :close="() => (showTips = null)" />
+
+    <ui-confirm v-if="delComfirm" @ok="handlerDel" @no="handlerDel">
+        <template #content>
+            <div>确定要删除吗?</div>
+        </template>
+    </ui-confirm>
 </template>
 
 <script setup>
@@ -65,12 +71,14 @@ import { ref, onMounted, onBeforeUnmount, computed, inject, nextTick, defineProp
 import Toast from '@/components/dialog/Toast'
 import { http } from '@/utils/request'
 import avatar from '@/assets/img/avatar@2x.png'
+import UiConfirm from '@/components/dialog/Confirm.vue'
 const props = defineProps({
     slideHeigt: Number,
 })
+let canPut = true
+const delComfirm = ref(null)
 const emptyAvatar = ref(avatar)
 const notify = inject('notify')
-console.log(notify.value)
 const emits = defineEmits(['action'])
 const input$ = ref(null)
 const inputText = ref('')
@@ -82,11 +90,11 @@ const slider = ref(null)
 
 const handlerReply = (data, index) => {
     inputText.value = ''
-    placeholderText.value = '@' + data.nickName
+    let name = data.nickName ? data.nickName : '未知用户'
+    placeholderText.value = '@' + name
     delete data.nickName
     replyInfo.value = data
 
-    console.log(replyInfo.value)
 }
 
 const handlerInput = () => {
@@ -121,29 +129,35 @@ const hanlderSubmit = () => {
         }
     }
 
-    console.log(params)
-    http.post(`smart-site/comment/reply`, params).then(response => {
-        console.log(response)
-        if (response.success) {
-            getAllComments()
+    if (canPut) {
+        canPut = false
+        http.post(`smart-site/comment/reply`, params)
+            .then(response => {
+                if (response.success) {
+                    getAllComments()
 
-            // if (replyInfo.value) {
-            // } else {
-            //     // slider.value.
-            //     slider.value.scrollTo({
-            //         top: 0,
-            //         behavior: 'smooth',
-            //     })
-            // }
+                    // if (replyInfo.value) {
+                    // } else {
+                    //     // slider.value.
+                    //     slider.value.scrollTo({
+                    //         top: 0,
+                    //         behavior: 'smooth',
+                    //     })
+                    // }
 
-            replyInfo.value = null
-            inputText.value = ''
-            placeholderText.value = '发一条评论吧'
-        } else {
-            tipsType.value = 'error'
-            showTips.value = response.message
-        }
-    })
+                    replyInfo.value = null
+                    inputText.value = ''
+                    placeholderText.value = '发一条评论吧'
+                } else {
+                    tipsType.value = 'error'
+                    showTips.value = response.message
+                }
+                canPut = true
+            })
+            .catch(err => {
+                canPut = true
+            })
+    }
 }
 const onClose = () => {
     if (window.kankan) {
@@ -162,22 +176,35 @@ const getAllComments = () => {
         }
     })
 }
-
-const delComment = data => {
-    http.post(`smart-site/comment/del`, { commentId: data.commentId }).then(response => {
-        if (response.success) {
-            if (!data.parentIndex) {
-                commentList.value.splice(data.index, 1)
+const handlerDel = status => {
+    if (status == 'ok') {
+        http.post(`smart-site/comment/del`, { commentId: delComfirm.value.commentId }).then(response => {
+            if (response.success) {
+                // if (!delComfirm.value.parentIndex) {
+                //     commentList.value.splice(delComfirm.value.index, 1)
+                // } else {
+                //     commentList.value[delComfirm.value.parentIndex].children.splice(delComfirm.value.index, 1)
+                // }
+                getAllComments()
+                if (replyInfo.value?.parentId == delComfirm.value.commentId) {
+                    replyInfo.value = null
+                    inputText.value = ''
+                    placeholderText.value = '发一条评论吧'
+                }
+                tipsType.value = 'success'
+                showTips.value = '删除成功'
             } else {
-                commentList.value[data.parentIndex].children.splice(data.index, 1)
+                tipsType.value = 'error'
+                showTips.value = response.message
             }
-            tipsType.value = 'success'
-            showTips.value = '删除成功'
-        } else {
-            tipsType.value = 'error'
-            showTips.value = response.message
-        }
-    })
+            delComfirm.value = null
+        })
+    } else {
+        delComfirm.value = null
+    }
+}
+const delComment = data => {
+    delComfirm.value = data
 }
 onMounted(() => {
     getAllComments()

+ 38 - 23
src/components/files/content/TagMsg.vue

@@ -46,6 +46,7 @@
             </div>
         </teleport>
     </div>
+    <Toast v-if="showTips" :type="showTips?.type" :content="showTips.text" :close="closeTips" />
 </template>
 
 <script setup>
@@ -57,6 +58,7 @@ import Video from '@/components/form/medias/Video.vue'
 import Audio from '@/components/form/medias/Audio.vue'
 import Link from '@/components/form/medias/Link.vue'
 import UiAudio from '@/components/audio/index.vue'
+import Toast from '@/components/dialog/Toast'
 import { nextTick } from 'process'
 const projectId = browser.valueFromUrl('projectId') || 1
 const notify = inject('notify')
@@ -79,6 +81,7 @@ const data = ref({
     ],
     members: [],
 })
+const showTips = ref(null)
 const media = computed(() => {
     return notify.value.type || 'image'
 })
@@ -104,32 +107,43 @@ const onClose = () => {
     }
     notify.value = null
 }
+const closeTips = () => {
+    notify.value = null
+    showTips.value = null
+}
 onMounted(() => {
     http.post(`smart-site/projectTeam/select`, { projectId }).then(response => {
-        data.value.members = response.data.map(item => {
-            return {
-                text: item.nickName,
-                value: item.userId,
-            }
-        })
+        if (response.success) {
+            data.value.members = response.data.map(item => {
+                return {
+                    text: item.nickName,
+                    value: item.userId,
+                }
+            })
 
-        if (notify.value) {
-            form.value.status = String(notify.value.status || '')
-            form.value.title = notify.value.title || ''
-            form.value.describe = notify.value.content || ''
-            form.value.members = []
-            if (notify.value.members && notify.value.members.length) {
-                notify.value.members.forEach(item => {
-                    let find = data.value.members.find(c => c.value == item)
-                    if (find) {
-                        form.value.members.push(find)
-                    }
-                })
+            if (notify.value) {
+                form.value.status = String(notify.value.status || '')
+                form.value.title = notify.value.title || ''
+                form.value.describe = notify.value.content || ''
+                form.value.members = []
+                if (notify.value.members && notify.value.members.length) {
+                    notify.value.members.forEach(item => {
+                        let find = data.value.members.find(c => c.value == item)
+                        if (find) {
+                            form.value.members.push(find)
+                        }
+                    })
+                }
+            }
+            nextTick(() => {
+                emits('setShow')
+            })
+        } else {
+            showTips.value = {
+                type: 'warn',
+                text: response.message,
             }
         }
-        nextTick(() => {
-            emits('setShow')
-        })
     })
 
     if (window.kankan) {
@@ -177,7 +191,7 @@ onBeforeUnmount(() => {})
     top: 0;
     left: 0;
     background: #292929;
-    z-index: 1000;
+    z-index: 10000;
     .layer-content {
         width: 90%;
         height: 80%;
@@ -189,7 +203,7 @@ onBeforeUnmount(() => {})
     .close-btn {
         position: absolute;
         top: 20px;
-        right: 20px;
+        right: 60px;
         cursor: pointer;
         z-index: 100;
         i {
@@ -211,6 +225,7 @@ onBeforeUnmount(() => {})
     }
     &.left-item {
         width: 400px;
+        border-right: solid 1px rgba(255, 255, 255, 0.16);
         .item-title {
             font-size: 14px;
             color: #999;

+ 26 - 14
src/components/form/medias/Image.vue

@@ -8,7 +8,7 @@
             <div class="swiper-button-next"></div>
         </div>
         <div v-if="isEdit" class="add" @click="file.click()" :class="{ disable: images.length >= 9 }">
-            继续添加&nbsp;<span>{{ images.length }}</span
+            <span style="color: #fff" v-if="images.length < 9">继续添加</span>&nbsp;<span>{{ images.length }}</span
             >&nbsp;/&nbsp;9
         </div>
     </div>
@@ -18,7 +18,7 @@
             <span>上传图片</span>
         </div>
         <div class="tips">支持JPG、PNG等图片格式,单张不超过5MB,最多支持上传9张。</div>
-        <input ref="file" type="file" style="display: none" accept="image/jpg,image/jpeg,image/png" @change="onChange" />
+        <input ref="file" multiple type="file" style="display: none" accept="image/jpg,image/jpeg,image/png" @change="onChange" />
     </div>
 
     <div class="del-btn" v-if="isEdit" v-show="notify.media?.[notify.type]?.length" @click="delPic">
@@ -38,23 +38,35 @@ const swiper$ = ref(null)
 
 const images = ref([])
 const onChange = e => {
-    if (!e.target.files.length) {
+    let files = e.target.files
+    if (!files.length) {
         return
     }
 
-    let file = e.target.files[0]
-
-    if (checkSizeLimitFree(file.size, 5)) {
-        let reader = new FileReader()
-        reader.onload = function () {
-            images.value.push({ src: base64ToDataURL(reader.result), file })
-
-            notify.value.media['image'] = images.value
+    // let file = e.target.files[0]
+    let frist = false
+    for (let i = 0; i < files.length; i++) {
+        let file = e.target.files[i]
+        if (checkSizeLimitFree(file.size, 5)) {
+            let reader = new FileReader()
+            reader.onload = function () {
+                if (images.value.length >= 9) {
+                    if (!frist) {
+                        frist = true
+                        emits('tips', '图片数量最多支持上传9张')
+                    }
+                } else {
+                    images.value.push({ src: base64ToDataURL(reader.result), file })
+                    notify.value.media['image'] = images.value
+                }
+            }
+            reader.readAsDataURL(file)
+        } else {
+            emits('tips', '请上传 5MB 以内的 jpg/png 文件')
         }
-        reader.readAsDataURL(file)
-    } else {
-        emits('tips', '请上传 5MB 以内的 jpg/png 文件')
+        console.log(images.value.length)
     }
+
     e.target.value = ''
 }
 const delPic = () => {