ananzhusen 3 сар өмнө
parent
commit
fa0efdab59

+ 40 - 5
src/views/components/View.vue

@@ -313,10 +313,9 @@
           <!-- <t-icon name="share" :class="{ primary: shared }" /> -->
         </a>
       </t-tooltip>
-      <t-popup placement="bottom" v-model="qrcode.visible">
+      <!-- <t-popup placement="bottom" v-model="qrcode.visible">
         <a>
           <qrcode-icon />
-          <!-- <t-icon name="qrcode" /> -->
         </a>
         <template #content>
           <div style="padding: 12px 12px 6px 12px">
@@ -330,7 +329,7 @@
             </div>
           </div>
         </template>
-      </t-popup>
+      </t-popup> -->
 
       <t-tooltip placement="bottom" :content="$t('云发布')">
         <a @click="onShowPublish">
@@ -773,7 +772,7 @@
     </t-dialog>
 
     <!-- 分享弹窗 -->
-    <ShareModal  :shared="shared" v-model:visible="shareVisible" />
+    <ShareModal  :shared="shared" v-model:visible="shareVisible" @change="sChange"/>
     <t-dialog
       v-if="addDataDialog.show"
       :visible="true"
@@ -2185,6 +2184,7 @@ const onSelDataset = async (init = false) => {
     }
   }
 };
+
 const registerLe5leTheme = ()=>{
   fetch((cdn ? cdn + '/v' : import.meta.env.BASE_URL.slice(0, -1)) + '/theme/custom.json')
     .then((r) => r.json())
@@ -2222,9 +2222,44 @@ const share = async () => {
     MessagePlugin.error($t('组件不允许分享!'));
     return;
   }
-  shareVisible.value = true;
+  if(!shared.value){
+    const result = shareChange(!shared.value);
+    if(result){
+      shared.value = !shared.value;
+      MessagePlugin.success(shared.value ? "分享成功!" : "取消分享成功");
+      if(shared.value){
+        shareVisible.value = true;
+      }
+    }
+  }else{
+    shareVisible.value = true;
+  }
 };
 
+const sChange = (e)=>{
+  shared.value = e;
+}
+
+//TODO 配置shared无用,图纸不能根据用户id查找
+async function shareChange(shared: boolean) {
+  const id = route.query.id;
+  if (!id) {
+    // 提示需要先保存
+    MessagePlugin.warning("请先保存!");
+    return;
+  }
+  const res: any = await axios.post(`/api/data/v/update`, {
+    _id: id,
+    id: id,
+    shared,
+  });
+  if (res.error) {
+    return false;
+  }else {
+    return true;
+  }
+}
+
 let qrTimer: any;
 const onEnterQrcode = () => {
   if (!qrcode.visible && !qrTimer) {

+ 12 - 2
src/views/components/common/ShareModal.vue

@@ -7,14 +7,23 @@
     @close="close"
   >
     <div class="shareModal">
-      <div class="item" v-if="shareFlag">
+      <!-- <div class="item" v-if="shareFlag">
         <t-radio-group v-model:value="isShare" @change="onChange">
           <t-radio :value="true"> {{$t('分享公开')}} </t-radio>
           <t-radio :value="false"> {{$t('不分享')}} </t-radio>
         </t-radio-group>
+      </div> -->
+      <div class="item">
+        <t-switch size="small" v-model:value="isShare" @change="onChange"/>
+        <p class="ml-8" style="color: #fff;">
+          {{ isShare?"已开启,所有人可查看":"未开启,仅自己可查看" }}
+        </p>
       </div>
       <div class="item">
-        <t-input v-model:value="link" :readonly="true"></t-input>
+        <t-input
+          v-model:value="link"
+          :readonly="true"
+        />
         <t-button @click="onSearch">{{$t('复制链接')}}</t-button>
       </div>
       <div class="desc">{{$t('分享到')}}</div>
@@ -68,6 +77,7 @@ function close() {
 }
 function onChange(e) {
   share(e);
+  emit("change",isShare.value);
 }
 function onSearch() {
   copy2clipboard(link.value);