tianyun 10 months ago
parent
commit
b30d3b1de1
1 changed files with 64 additions and 22 deletions
  1. 64 22
      simple-demo/send_memos.html

+ 64 - 22
simple-demo/send_memos.html

@@ -121,10 +121,23 @@
 
             </div>
 
+
             <!-- 添加多选按钮 -->
-            <el-checkbox-group v-model="tagChecked">
-                <el-checkbox-button v-for="tag in allTags" :label="tag"></el-checkbox-button>
-            </el-checkbox-group>
+            <div style="display: flex;">
+                <div>
+                    <el-checkbox-group v-model="tagChecked" @change="checkChange1()">
+                        <el-checkbox-button v-for="tag in allTags" :label="tag"></el-checkbox-button>
+                    </el-checkbox-group>
+                </div>
+                <div>
+                    <el-switch
+                            @change="duoxuanChange"
+                            v-model="duoxuan"
+                            active-color="#13ce66"
+                            inactive-color="#ff4949">
+                    </el-switch>
+                </div>
+            </div>
             <div id="tags"></div>
         </div>
 
@@ -258,6 +271,7 @@
     let vm = new Vue({
         el: '#app',
         data: {
+            duoxuan: false,
             tmpItem: {},
             dialogVisible: false,
             page: 1,
@@ -275,16 +289,6 @@
             cloneFileIds: []
         },
         watch: {
-            tagChecked: function () {
-                if (!getQueryString("duoxuan")) {
-                    if (this.tagChecked.length > 1) {
-                        // 保留最后一个
-                        this.tagChecked = [this.tagChecked[this.tagChecked.length - 1]];
-                    }
-                }
-                localStorage.setItem('tags', JSON.stringify(this.tagChecked));
-                this.search();
-            },
             page: function () {
                 this.search();
             },
@@ -293,9 +297,14 @@
             }
         },
         mounted() {
+
             if (!checkLogin()) {
                 return;
             }
+            if (this.getQueryStr()) {
+                this.searchStr = this.getQueryStr();
+            }
+            this.duoxuan = this.getDuoXuan();
             // 初始化contentStr,如果本地有缓存
             let item = localStorage.getItem('contentStr');
             if (item) {
@@ -309,6 +318,36 @@
             });
         },
         methods: {
+            duoxuanChange() {
+                if (this.duoxuan) {
+                    this.setDuoXuan('ok');
+                } else {
+                    this.setDuoXuan('');
+                }
+            },
+            checkChange1(newVal) {
+                console.log(this.tagChecked)
+                if (!this.getDuoXuan()) {
+                    if (this.tagChecked.length > 1) {
+                        // 保留最后一个
+                        this.tagChecked = [this.tagChecked[this.tagChecked.length - 1]];
+                    }
+                }
+
+                location.href = requestUtil.buildUrl(location.href, {'tags': this.tagChecked.join(',')})
+            },
+            getQueryStr() {
+                return getQueryString('queryStr')
+            },
+            setQueryStr(content) {
+                location.href = requestUtil.buildUrl(location.href, {'queryStr': content})
+            },
+            getDuoXuan() {
+                return getQueryString('duoxuan') == "ok";
+            },
+            setDuoXuan(ok) {
+                location.href = requestUtil.buildUrl(location.href, {'duoxuan': ok})
+            },
             removeTmp(item) {
                 // tmpFileIds 根据id删除
                 let index = this.tmpFileIds.findIndex(item => item.id === item.id);
@@ -551,6 +590,7 @@
             search: function () {
                 document.documentElement.scrollTo(0, 0);
                 this.resourceMap = {};
+                console.log(this.tagChecked);
 
                 let params = {'search': this.searchStr, tag_str: this.tagChecked.join(','), page: this.page, page_size: this.size};
                 let url = 'https://web_history.tianyunperfect.cn/memos/list';
@@ -564,7 +604,11 @@
                 // contentList 循环获取里面所有的id数组
                 let idArr = this.contentList.map(item => item['id']);
                 // 获取资源
-                let sourceRes = requestUtil.sync("https://web_history.tianyunperfect.cn/memos/resource", 'post', {ids: idArr.join(',')}, {});
+                let ids = idArr.join(',');
+                if (!ids) {
+                    return;
+                }
+                let sourceRes = requestUtil.sync("https://web_history.tianyunperfect.cn/memos/resource", 'post', {ids: ids}, {});
                 // {'code': 200, 'res': [{'memo_id': 1, 'resource_name': 'EfdmvRsodBviDQWRmDiTaV'}, {'memo_id': 4, 'resource_name': '2rY5kmn3AHsy23vK4vSskV'}, {'memo_id': 7, 'resource_name': 'FMhzJXjoTa7fdtbbCBjXnt'}]}
                 // 循环遍历,以memo_id为key,resource_name数组为value
                 sourceRes['res'].forEach(item => {
@@ -578,14 +622,12 @@
             getAllTags: function () {
                 this.allTags = requestUtil.sync('https://memos.tianyunperfect.cn/api/v1/tag', 'get', null, myHeaders);
                 // 先检查url
-                if (getQueryString("tags")) {
-                    this.tagChecked = getQueryString("tags").split(',')
-                    return
-                }
-                // 否则检查本地存储
-                let item1 = localStorage.getItem('tags'); // 获取本地存储的标签
-                if (item1) {
-                    this.tagChecked = JSON.parse(item1);
+                let tagsStr = getQueryString("tags");
+                // 解码
+                tagsStr = decodeURIComponent(tagsStr);
+                if (tagsStr) {
+                    console.log(tagsStr)
+                    this.tagChecked = tagsStr.split(',')
                 }
             }
         }