123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
- <title>memos记录</title>
- <!-- 引入Quill样式 -->
- <!-- <link rel="stylesheet" href="./js/quill.snow.css">-->
- <link rel="stylesheet" href="https://cdn.staticfile.org/lxgw-wenkai-screen-webfont/1.6.0/lxgwwenkaiscreen.css"></link>
- <script src="js/util.js"></script>
- <style>
- body {
- font-family: "LXGW WenKai Screen", sans-serif !important;
- }
- img {
- border: 1px solid #b7b6b6;
- }
- .editClass button {
- display: inline;
- /*margin-top: 5px;*/
- margin-left: 10px;
- }
- .contentLine div {
- margin: 5px 0 0;
- }
- .border {
- border: 1px solid #b7b6b6;
- border-radius: 5px;
- padding: 10px;
- }
- .editor {
- min-height: 50px;
- padding: 10px;
- }
- #mask {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */
- display: flex;
- justify-content: center;
- align-items: center;
- }
- #model {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- background-color: white;
- width: 50%;
- padding: 20px;
- border-radius: 5px;
- }
- .myTop {
- position: fixed;
- top: 0;
- background-image: url("./img/white.png");
- /* 背景铺满整个div*/
- background-size: 100% 100%;
- width: 100%;
- padding: 10px;
- z-index: 100;
- }
- </style>
- <script src="js/vue.min.js"></script>
- <script src="elementUI/index.js"></script>
- <link rel="stylesheet" href="elementUI/index.css">
- </head>
- <body>
- <div id="app">
- <div id="all">
- <div class="myTop">
- <el-link href="https://memos.tianyunperfect.cn/">memos主页</el-link>
- <!-- 页码输入框,默认为1,修改触发查询-->
- <span style="margin-left: 20px">页码:</span>
- <el-input type="number" style="width: 80px; margin-left: 20px" v-model="page" @change="search"></el-input>
- <span style="margin-left: 20px">大小:</span>
- <el-input type="number" style="width: 80px; margin-left: 20px" v-model="size" @change="search" step="10"></el-input>
- <!--输入框,绑定回车事件,触发查询-->
- <el-input style="margin-left: 30px; width: 70vw; padding-left: 10px" placeholder="搜索" v-model="searchStr" @change="search"></el-input>
- <br><br>
- <div></div>
- <div style="display: flex;align-items:stretch">
- <!-- 创建一个用于编辑的容器 -->
- <el-input
- type="textarea"
- :autosize={minRows:2}
- placeholder="请输入内容"
- @input="localStorage.setItem(contentStr, getEditContent())"
- v-model="contentStr">
- </el-input>
- <!-- 添加发送按钮 -->
- <el-button style="margin-left: 20px; width: 10%; font-size: 2rem" @click="sendData" :disabled="!sendBtnAble">记录</el-button>
- </div>
- <!-- 添加多选按钮 -->
- <el-checkbox-group v-model="tagChecked">
- <el-checkbox v-for="tag in allTags" :label="tag"></el-checkbox>
- </el-checkbox-group>
- <div id="tags"></div>
- </div>
- <div style="margin-top: 180px"></div>
- <div v-for="item in contentList">
- <el-row style="margin: 10px; padding: 10px" class="border">
- <el-col :span="12" class="contentLine">
- <div style="display: flex">
- <el-date-picker
- v-model="item.created_ts"
- type="datetime"
- readonly="true"
- placeholder="选择日期时间">
- </el-date-picker>
- <div style="margin-left: 20px">
- <el-checkbox-button v-for="tag in commonTags" :label="tag" :key="item"
- @change="checked=>checkChange(checked,item,tag)"
- :checked="isChooseTag(item,tag)">{{tag}}
- </el-checkbox-button>
- </div>
- </div>
- <div class="myText" @dblclick="edit(item)">
- <el-input v-model="item.content" type="textarea" :autosize="{minRows: 1}" readonly="true"></el-input>
- </div>
- <div>
- <el-image v-for="img in resourceMap[item.id]"
- :src="'https://memos_assert.tianyunperfect.cn/' + img + '?width=150'"
- :preview-src-list="['https://memos_assert.tianyunperfect.cn/' + img]"
- style="height: 200px; width: 200px; margin: 10px 10px 0 0; cursor: pointer">
- </el-image>
- </div>
- </el-col>
- <el-col :span="4" style="display: flex">
- <div class="editClass">
- <el-button size="small" @click="window.open('https://memos.tianyunperfect.cn/m/' + item.resource_name)">跳转</el-button>
- <br>
- <el-button size="small" @click="edit(item)">编辑</el-button>
- </div>
- <div class="editClass">
- <el-button size="small" @click="archive(item)">归档</el-button>
- <br>
- <el-button size="small" type="warning" @click="del(item)">删除</el-button>
- </div>
- </el-col>
- </el-row>
- </div>
- </div>
- <el-dialog
- title="提示"
- :visible.sync="dialogVisible"
- width="60%"
- >
- <div v-if="tmpItem.id" class="contentLine">
- <div>
- <el-date-picker
- v-model="tmpItem.created_ts"
- type="datetime"
- value-format="yyyy-MM-ddTHH:mm:ss"
- placeholder="选择日期时间">
- </el-date-picker>
- </div>
- <div>
- <el-input ref="contentEdit" v-model="tmpItem.content" type="textarea" :autosize="{minRows: 2}"></el-input>
- </div>
- <div style="display: flex">
- <div v-for="img in resourceMap[tmpItem.id]">
- <el-image :src="'https://memos_assert.tianyunperfect.cn/' + img + '?width=150'"
- :preview-src-list="['https://memos_assert.tianyunperfect.cn/' + img]"
- style="height: 200px; width: 200px; margin: 10px 10px 0 0; cursor: pointer">
- </el-image>
- </div>
- </div>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button @click="dialogVisible = false">取 消</el-button>
- <el-button type="primary" @click="confirmSubmit">确 定</el-button>
- </span>
- </el-dialog>
- </div>
- <!-- 引入Quill库 -->
- <!--<script src="./js/cdn.quilljs.com_1.3.6_quill.js"></script>-->
- <!--异步请求示例:requestUtil.sync('https://jsonplaceholder.typicode.com/posts/1', 'post', data, headers) .then(data => console.log(data))-->
- <script>
- let authStr = "bearer eyJhbGciOiJIUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJuYW1lIjoidGlhbnl1bnBlcmZlY3QiLCJpc3MiOiJtZW1vcyIsInN1YiI6IjEiLCJhdWQiOlsidXNlci5hY2Nlc3MtdG9rZW4iXSwiaWF0IjoxNzA5MTc5NTUyfQ.LFxWB4efya1sL7VoJ42xpXxbAip-udT_Kx2OwZ8Y3-E";
- let myHeaders = {
- 'Content-type': 'application/json',
- 'Authorization': authStr
- };
- function getRandomId() {
- return Math.random().toString(36).substr(2);
- }
- let vm = new Vue({
- el: '#app',
- data: {
- tmpItem: {},
- dialogVisible: false,
- page: 1,
- size: 10,
- searchStr: '',
- contentStr: '',
- tagChecked: [],
- allTags: [],
- contentList: [],
- sendBtnAble: true,
- resourceMap: {}, // 资源map,
- commonTags: ['todo', '日记', '梦记', '美食', '备份', '歌曲', '电影', '随笔'],
- },
- watch: {
- tagChecked: function () {
- localStorage.setItem('tags', JSON.stringify(this.tagChecked));
- this.search();
- },
- page: function () {
- this.search();
- },
- size: function () {
- this.search();
- }
- },
- mounted() {
- this.getAllTags();
- this.search();
- },
- methods: {
- msg(content) {
- this.$message({
- message: content,
- type: 'success'
- });
- },
- isChooseTag(item, tag) {
- return item.content.indexOf("#" + tag + " ") !== -1;
- },
- checkChange(val, item, tag) {
- if (val) {
- this.addTag(item, tag);
- } else {
- this.delTag(item, tag);
- }
- },
- addTag(item, cTag) {
- let content = item.content;
- // 如果已经有了,就不添加
- if (content.indexOf(cTag) !== -1) {
- return;
- }
- item.content = '#' + cTag + ' ' + content;
- // 提交记录
- let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/update', 'post', {
- id: item.id,
- content: item.content,
- created_ts: item.created_ts
- }, {});
- if (res.code === 200) {
- this.msg('更新成功');
- // this.search();
- }
- },
- delTag(item, cTag) {
- let content = item.content;
- // 如果没有,就不删除
- if (content.indexOf(cTag) === -1) {
- return;
- }
- item.content = content.replace('#' + cTag + " ", '');
- // 提交记录
- let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/update', 'post', {
- id: item.id,
- content: item.content,
- created_ts: item.created_ts
- }, {});
- if (res.code === 200) {
- this.msg('更新成功');
- // this.search();
- }
- },
- del(item) {
- // 提醒是否删除
- this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'}).then(() => {
- requestUtil.async(`https://web_history.tianyunperfect.cn/memos/delete`, 'post', {id: item.id}, {}).then(res => {
- if (res.code === 200) {
- this.msg('删除成功');
- // 在 this.contentList 上直接去除
- this.contentList = this.contentList.filter(it => it.id !== item.id);
- }
- });
- })
- },
- archive(item) {
- requestUtil.async(`https://web_history.tianyunperfect.cn/memos/archive`, 'post', {id: item.id}, {}).then(res => {
- this.msg('归档成功');
- this.search();
- });
- },
- handleClose(done) {
- this.dialogVisible = false;
- done();
- },
- confirmSubmit(done) {
- // 提交记录
- let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/update', 'post', {
- id: this.tmpItem.id,
- content: this.tmpItem.content,
- created_ts: this.tmpItem.created_ts
- }, {});
- if (res.code === 200) {
- this.msg('更新成功');
- // this.search();
- }
- this.dialogVisible = false;
- done();
- },
- edit(item) {
- this.tmpItem = item;
- this.dialogVisible = true;
- // 获取焦点
- this.$nextTick(() => {
- this.$refs.contentEdit.focus()
- })
- },
- isDisabled(item) {
- // 默认不可编辑,这个时候 没有disable属性
- return item['disable'] !== false;
- },
- sendData: function () {
- this.sendBtnAble = false;
- let content = this.contentStr;
- let categories = this.tagChecked;
- // 循环拼接类似 #tag #tag2 content
- let updatedContent = content;
- if (categories.length > 0) {
- // 循环拼接类似 #tag #tag2 content
- updatedContent = categories.map(tag => `#${tag}`).join(' ') + ' ' + content;
- }
- // updatedContent 去除尾部的\n,可能有多个
- updatedContent = updatedContent.replace(/\n+$/, '');
- let res = requestUtil.sync('https://memos.tianyunperfect.cn/api/v1/memo', 'post', {content: updatedContent}, myHeaders);
- if (res['name']) {
- // window.location.href = `https://memos.tianyunperfect.cn/m/${res['name']}`;
- this.msg('记录成功');
- this.contentStr = '';
- this.search();
- }
- this.sendBtnAble = true;
- },
- search: function () {
- document.documentElement.scrollTo(0, 0);
- this.resourceMap = {};
- 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';
- let urlWithParams = requestUtil.buildUrl(url, params);
- let res = requestUtil.sync(urlWithParams, 'get', null, myHeaders);
- if (res.code !== 200) {
- return;
- }
- this.contentList = res.res;
- // 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(',')}, {});
- // {'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 => {
- if (this.resourceMap[item['memo_id']]) {
- this.resourceMap[item['memo_id']].push(item['internal_path']);
- } else {
- this.resourceMap[item['memo_id']] = [item['internal_path']];
- }
- });
- },
- getAllTags: function () {
- this.allTags = requestUtil.sync('https://memos.tianyunperfect.cn/api/v1/tag', 'get', null, myHeaders);
- let item1 = localStorage.getItem('tags'); // 获取本地存储的标签
- if (item1) {
- this.tagChecked = JSON.parse(item1);
- }
- }
- }
- });
- // 如果处于编辑状态,则执行esc取消
- window.onkeydown = function (event) {
- let edit = vm.dialogVisible;
- if (!edit) {
- return;
- }
- // esc
- if (event.keyCode === 27) {
- vm.dialogVisible = false;
- }
- // 如果是meta + enter 则保存
- if (event.metaKey && event.keyCode === 13) {
- vm.confirmSubmit();
- }
- // 如果是ctrl + enter 则保存
- if (event.ctrlKey && event.keyCode === 13) {
- vm.confirmSubmit();
- }
- };
- </script>
- </body>
- </html>
|