send_memos.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
  6. <title>memos记录</title>
  7. <!-- 引入Quill样式 -->
  8. <!-- <link rel="stylesheet" href="./js/quill.snow.css">-->
  9. <link rel="stylesheet" href="https://cdn.staticfile.org/lxgw-wenkai-screen-webfont/1.6.0/lxgwwenkaiscreen.css"></link>
  10. <script src="js/util.js"></script>
  11. <script src="js/login.js"></script>
  12. <style>
  13. body {
  14. font-family: "LXGW WenKai Screen", sans-serif !important;
  15. }
  16. img {
  17. border: 1px solid #b7b6b6;
  18. }
  19. .img {
  20. border: 1px solid #b7b6b6;
  21. max-width: 200px;
  22. max-height: 200px;
  23. margin: 10px 10px 0 0 !important;
  24. cursor: pointer
  25. }
  26. .editClass button {
  27. display: inline;
  28. /*margin-top: 5px;*/
  29. margin-left: 10px;
  30. }
  31. .contentLine div {
  32. margin: 5px 0 0;
  33. }
  34. .border {
  35. /*border: 1px solid #b7b6b6;*/
  36. border-radius: 5px;
  37. padding: 10px;
  38. background-color: white;
  39. }
  40. body {
  41. background-color: #f4f4f5;
  42. }
  43. .myTop {
  44. position: fixed;
  45. top: 0;
  46. background-image: url("./img/gray.png");
  47. /* 背景铺满整个div*/
  48. background-size: 100% 100%;
  49. width: 100%;
  50. padding: 10px;
  51. z-index: 100;
  52. }
  53. </style>
  54. <script src="js/vue.min.js"></script>
  55. <script src="elementUI/index.js"></script>
  56. <link rel="stylesheet" href="elementUI/index.css">
  57. </head>
  58. <body>
  59. <div id="app">
  60. <div id="all">
  61. <div class="myTop">
  62. <el-link href="https://memos.tianyunperfect.cn/">memos主页</el-link>
  63. <el-button @click="page = page - 1;search()" :disabled="page === 1">上一页</el-button>
  64. <el-input type="number" style="width: 80px;" v-model="page" @change="search"></el-input>
  65. <el-button @click="page = page + 1;search()">下一页</el-button>
  66. <el-select v-model="size" placeholder="请选择" style="width: 80px" @change="search">
  67. <el-option
  68. v-for="item in [10, 20, 50, 100]"
  69. :key="item"
  70. :label="item"
  71. :value="item">
  72. </el-option>
  73. </el-select>
  74. <!--输入框,绑定回车事件,触发查询-->
  75. <el-input style="margin-left: 30px; width: 40vw; padding-left: 10px" placeholder="搜索" v-model="searchStr" @change="search"></el-input>
  76. <br><br>
  77. <div></div>
  78. <div style="display: flex;align-items:stretch; width: 70vw">
  79. <!-- 创建一个用于编辑的容器 -->
  80. <el-input
  81. @paste.native="handlePaste"
  82. @keydown.enter.native="keyDown"
  83. type="textarea"
  84. :autosize={minRows:2}
  85. placeholder="请输入内容"
  86. @input="localStorage.setItem('contentStr', contentStr)"
  87. v-model="contentStr">
  88. </el-input>
  89. <!-- 添加发送按钮 -->
  90. <el-button style="margin-left: 20px; width: 10%; font-size: 2rem" @click="sendData" :disabled="!sendBtnAble">记录</el-button>
  91. </div>
  92. <div style="display: flex">
  93. <div v-for="item in tmpFileIds">
  94. <el-image v-if="item['type'].startsWith('image')"
  95. :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=150'"
  96. :preview-src-list="['https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=750']"
  97. class="img"></el-image>
  98. <audio controls v-if="item['type'].startsWith('audio')">
  99. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/ogg">
  100. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/mpeg">
  101. 您的浏览器不支持 audio 元素。
  102. </audio>
  103. <video width="320" height="240" controls v-if="item['type'].startsWith('video')">
  104. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/mp4">
  105. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/ogg">
  106. 您的浏览器不支持 HTML5 video 元素。
  107. </video>
  108. <el-link v-if="item['type'].startsWith('application')" :href="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" target="_blank">{{item['filename']}}</el-link>
  109. <div @click="removeTmp(item)">删除</div>
  110. </div>
  111. </div>
  112. <!-- 添加多选按钮 -->
  113. <el-checkbox-group v-model="tagChecked">
  114. <el-checkbox-button v-for="tag in allTags" :label="tag"></el-checkbox-button>
  115. </el-checkbox-group>
  116. <div id="tags"></div>
  117. </div>
  118. <div style="margin-top: 180px"></div>
  119. <div v-for="item in contentList">
  120. <el-row style="margin: 10px; padding: 10px" class="border">
  121. <el-col :span="16" class="contentLine">
  122. <div style="display: flex">
  123. <el-date-picker
  124. v-model="item.created_ts"
  125. type="datetime"
  126. readonly="true"
  127. placeholder="选择日期时间">
  128. </el-date-picker>
  129. <div style="margin-left: 20px">
  130. <el-checkbox-button v-for="tag in commonTags" :label="tag" :key="item"
  131. @change="checked=>checkChange(checked,item,tag)"
  132. :checked="isChooseTag(item,tag)">{{tag}}
  133. </el-checkbox-button>
  134. </div>
  135. </div>
  136. <div class="myText" @dblclick="edit(item)">
  137. <el-input v-model="item.content" type="textarea" :autosize="{minRows: 1}" readonly="true"></el-input>
  138. </div>
  139. <div>
  140. <div v-for="item in resourceMap[item.id]">
  141. <el-image v-if="item['type'].startsWith('image')"
  142. :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=150'"
  143. :preview-src-list="['https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=750']"
  144. class="img">
  145. </el-image>
  146. <audio controls v-if="item['type'].startsWith('audio')">
  147. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/ogg">
  148. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/mpeg">
  149. 您的浏览器不支持 audio 元素。
  150. </audio>
  151. <video width="320" height="240" controls v-if="item['type'].startsWith('video')">
  152. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/mp4">
  153. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/ogg">
  154. 您的浏览器不支持 HTML5 video 元素。
  155. </video>
  156. <el-link v-if="item['type'].startsWith('application')" :href="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" target="_blank">{{item['filename']}}</el-link>
  157. </div>
  158. </div>
  159. </el-col>
  160. <el-col :span="4" style="display: flex">
  161. <div class="editClass">
  162. <el-button size="small" @click="window.open('https://memos.tianyunperfect.cn/m/' + item.resource_name)">跳转</el-button>
  163. <br>
  164. <el-button size="small" @click="edit(item)">编辑</el-button>
  165. </div>
  166. <div class="editClass">
  167. <el-button size="small" @click="archive(item)">归档</el-button>
  168. <br>
  169. <el-button size="small" type="warning" @click="del(item)">删除</el-button>
  170. </div>
  171. </el-col>
  172. </el-row>
  173. </div>
  174. </div>
  175. <el-dialog
  176. title="提示"
  177. :visible.sync="dialogVisible"
  178. width="60%"
  179. >
  180. <div v-if="tmpItem.id" class="contentLine">
  181. <div>
  182. <el-date-picker
  183. v-model="tmpItem.created_ts"
  184. type="datetime"
  185. value-format="yyyy-MM-ddTHH:mm:ss"
  186. placeholder="选择日期时间">
  187. </el-date-picker>
  188. </div>
  189. <div>
  190. <el-input
  191. @paste.native="handlePaste2"
  192. ref="contentEdit" v-model="tmpItem.content" type="textarea" :autosize="{minRows: 2}"></el-input>
  193. </div>
  194. <div style="display: flex">
  195. <div v-for="item in cloneFileIds">
  196. <el-image v-if="item['type'].startsWith('image')"
  197. :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=150'"
  198. :preview-src-list="['https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=750']"
  199. class="img">
  200. </el-image>
  201. <audio controls v-if="item['type'].startsWith('audio')">
  202. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/ogg">
  203. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/mpeg">
  204. 您的浏览器不支持 audio 元素。
  205. </audio>
  206. <video width="320" height="240" controls v-if="item['type'].startsWith('video')">
  207. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/mp4">
  208. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/ogg">
  209. 您的浏览器不支持 HTML5 video 元素。
  210. </video>
  211. <el-link v-if="item['type'].startsWith('application')" :href="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" target="_blank">{{item['filename']}}</el-link>
  212. <div @click="delPic(img)">删除</div>
  213. </div>
  214. </div>
  215. </div>
  216. <span slot="footer" class="dialog-footer">
  217. <el-button @click="dialogVisible = false">取 消</el-button>
  218. <el-button type="primary" @click="confirmSubmit">确 定</el-button>
  219. </span>
  220. </el-dialog>
  221. </div>
  222. <!-- 引入Quill库 -->
  223. <!--<script src="./js/cdn.quilljs.com_1.3.6_quill.js"></script>-->
  224. <!--异步请求示例:requestUtil.sync('https://jsonplaceholder.typicode.com/posts/1', 'post', data, headers) .then(data => console.log(data))-->
  225. <script>
  226. // if (getQueryString("id") !== "tianyunperfect") {
  227. // // location.href = "http://127.0.0.1";
  228. // }
  229. let authStr = "bearer eyJhbGciOiJIUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJuYW1lIjoidGlhbnl1bnBlcmZlY3QiLCJpc3MiOiJtZW1vcyIsInN1YiI6IjEiLCJhdWQiOlsidXNlci5hY2Nlc3MtdG9rZW4iXSwiaWF0IjoxNzA5MTc5NTUyfQ.LFxWB4efya1sL7VoJ42xpXxbAip-udT_Kx2OwZ8Y3-E";
  230. let myHeaders = {
  231. 'Content-type': 'application/json',
  232. 'Authorization': authStr
  233. };
  234. function getRandomId() {
  235. return Math.random().toString(36).substr(2);
  236. }
  237. let vm = new Vue({
  238. el: '#app',
  239. data: {
  240. tmpItem: {},
  241. dialogVisible: false,
  242. page: 1,
  243. size: 20,
  244. searchStr: '',
  245. contentStr: '',
  246. tagChecked: [],
  247. allTags: [],
  248. contentList: [],
  249. sendBtnAble: true,
  250. resourceMap: {}, // 资源map,
  251. commonTags: ['todo'],
  252. upload_url: 'https://memos.tianyunperfect.cn/api/v1/resource/blob',
  253. tmpFileIds: [],
  254. cloneFileIds: []
  255. },
  256. watch: {
  257. tagChecked: function () {
  258. if (!getQueryString("duoxuan")) {
  259. if (this.tagChecked.length > 1) {
  260. // 保留最后一个
  261. this.tagChecked = [this.tagChecked[this.tagChecked.length - 1]];
  262. }
  263. }
  264. localStorage.setItem('tags', JSON.stringify(this.tagChecked));
  265. this.search();
  266. },
  267. page: function () {
  268. this.search();
  269. },
  270. size: function () {
  271. this.search();
  272. }
  273. },
  274. mounted() {
  275. if (!checkLogin()) {
  276. return;
  277. }
  278. // 初始化contentStr,如果本地有缓存
  279. let item = localStorage.getItem('contentStr');
  280. if (item) {
  281. this.contentStr = item;
  282. }
  283. this.getAllTags();
  284. this.search();
  285. requestUtil.async('https://web_history.tianyunperfect.cn/memos/getCustomMemoTags', 'get').then(res => {
  286. this.commonTags = JSON.parse(res['res'][0]['content']);
  287. });
  288. },
  289. methods: {
  290. removeTmp(item) {
  291. // tmpFileIds 根据id删除
  292. let index = this.tmpFileIds.findIndex(item => item.id === item.id);
  293. if (index !== -1) {
  294. this.tmpFileIds.splice(index, 1);
  295. }
  296. },
  297. delPic(img) {
  298. // 根据id从 cloneFileIds 删除
  299. let index = this.cloneFileIds.findIndex(item => item.id === img.id);
  300. if (index !== -1) {
  301. this.cloneFileIds.splice(index, 1);
  302. }
  303. },
  304. getCloneResourceIds(id) {
  305. let resourceMapElement = this.resourceMap[id];
  306. if (resourceMapElement) {
  307. return JSON.parse(JSON.stringify(resourceMapElement))
  308. }
  309. return []
  310. },
  311. uploadFile(url, file, headers = {}) {
  312. return new Promise((resolve, reject) => {
  313. const xhr = new XMLHttpRequest();
  314. xhr.open('POST', url, true); // 使用异步的方式
  315. const formData = new FormData();
  316. formData.append('file', file);
  317. for (const [key, value] of Object.entries(headers)) {
  318. xhr.setRequestHeader(key, value);
  319. }
  320. xhr.onload = function () {
  321. if (xhr.status === 200) {
  322. resolve(JSON.parse(xhr.responseText));
  323. } else {
  324. reject(new Error(xhr.statusText));
  325. }
  326. };
  327. xhr.onerror = function () {
  328. reject(new Error("Network Error"));
  329. };
  330. xhr.send(formData);
  331. });
  332. },
  333. getFileFromPaste(e) {
  334. let clipboardData = e.clipboardData; // IE
  335. if (!clipboardData) {
  336. //chrome
  337. clipboardData = e.originalEvent.clipboardData;
  338. }
  339. let items = '';
  340. items = (e.clipboardData || window.clipboardData).items;
  341. let file = null;
  342. if (!items || items.length === 0) {
  343. this.$message.error('当前浏览器不支持粘贴本地图片,请打开图片复制后再粘贴!');
  344. return;
  345. }
  346. // 搜索剪切板items
  347. for (let i = 0; i < items.length; i++) {
  348. // 限制上传文件类型
  349. if (items[i].type.indexOf('image') !== -1) {
  350. file = items[i].getAsFile();
  351. break;
  352. }
  353. }
  354. // 对复制黏贴的类型进行判断,若是非文件类型,比如复制黏贴的文字,则不会调用上传文件的函数
  355. if (file) {
  356. return file;
  357. }
  358. },
  359. handlePaste(e) {
  360. let file = this.getFileFromPaste(e);
  361. // 对复制黏贴的类型进行判断,若是非文件类型,比如复制黏贴的文字,则不会调用上传文件的函数
  362. if (file) {
  363. this.uploadFile(this.upload_url, file, {'Authorization': myHeaders['Authorization']}).then(res => {
  364. let fileId = res['id'];
  365. if (fileId) {
  366. let sourceRes = requestUtil.sync("https://web_history.tianyunperfect.cn/memos/resourceById", 'post', {ids: fileId}, {});
  367. let sourceRe = sourceRes['res'];
  368. this.tmpFileIds.push(...sourceRe)
  369. }
  370. });
  371. }
  372. },
  373. handlePaste2(e) {
  374. let file = this.getFileFromPaste(e);
  375. // 对复制黏贴的类型进行判断,若是非文件类型,比如复制黏贴的文字,则不会调用上传文件的函数
  376. if (file) {
  377. this.uploadFile(this.upload_url, file, {'Authorization': myHeaders['Authorization']}).then(res => {
  378. let fileId = res['id'];
  379. if (fileId) {
  380. let sourceRes = requestUtil.sync("https://web_history.tianyunperfect.cn/memos/resourceById", 'post', {ids: fileId}, {});
  381. let sourceRe = sourceRes['res'];
  382. this.cloneFileIds.push(...sourceRe)
  383. }
  384. });
  385. }
  386. },
  387. keyDown() {
  388. // 如果是ctrl + enter \ meta + enter 则发送
  389. if (event.ctrlKey || event.metaKey) {
  390. this.sendData();
  391. }
  392. },
  393. msg(content) {
  394. this.$message({
  395. message: content,
  396. type: 'success'
  397. });
  398. },
  399. isChooseTag(item, tag) {
  400. return item.content.indexOf("#" + tag + " ") !== -1;
  401. },
  402. checkChange(val, item, tag) {
  403. if (val) {
  404. this.addTag(item, tag);
  405. } else {
  406. this.delTag(item, tag);
  407. }
  408. },
  409. addTag(item, cTag) {
  410. let content = item.content;
  411. // 如果已经有了,就不添加
  412. let tmpTag = '#' + cTag + ' ';
  413. if (content.indexOf(tmpTag) !== -1) {
  414. return;
  415. }
  416. item.content = tmpTag + content;
  417. // 提交记录
  418. let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/updateContent', 'post', {
  419. id: item.id,
  420. content: item.content,
  421. created_ts: item.created_ts
  422. }, {});
  423. if (res.code === 200) {
  424. this.msg('更新成功');
  425. // this.search();
  426. }
  427. },
  428. delTag(item, cTag) {
  429. let content = item.content;
  430. // 如果没有,就不删除
  431. if (content.indexOf(cTag) === -1) {
  432. return;
  433. }
  434. item.content = content.replace('#' + cTag + " ", '');
  435. // 提交记录
  436. let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/updateContent', 'post', {
  437. id: item.id,
  438. content: item.content,
  439. created_ts: item.created_ts
  440. }, {});
  441. if (res.code === 200) {
  442. this.msg('更新成功');
  443. // this.search();
  444. }
  445. },
  446. del(item) {
  447. // 提醒是否删除
  448. this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'}).then(() => {
  449. requestUtil.async(`https://web_history.tianyunperfect.cn/memos/delete`, 'post', {id: item.id}, {}).then(res => {
  450. if (res.code === 200) {
  451. this.msg('删除成功');
  452. // 在 this.contentList 上直接去除
  453. this.contentList = this.contentList.filter(it => it.id !== item.id);
  454. }
  455. });
  456. })
  457. },
  458. archive(item) {
  459. requestUtil.async(`https://web_history.tianyunperfect.cn/memos/archive`, 'post', {id: item.id}, {}).then(res => {
  460. this.msg('归档成功');
  461. // 本地缓存更新
  462. this.contentList = this.contentList.filter(it => it.id !== item.id);
  463. });
  464. },
  465. handleClose(done) {
  466. this.dialogVisible = false;
  467. done();
  468. },
  469. confirmSubmit(done) {
  470. // 提交记录
  471. let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/update', 'post', {
  472. id: this.tmpItem.id,
  473. content: this.tmpItem.content,
  474. created_ts: this.tmpItem.created_ts,
  475. resourceIdList: this.cloneFileIds.map(it => it.id)
  476. }, {});
  477. if (res.code === 200) {
  478. this.msg('更新成功');
  479. // 更新主页面的图片
  480. this.resourceMap[this.tmpItem.id] = this.cloneFileIds;
  481. // this.search();
  482. }
  483. this.dialogVisible = false;
  484. done();
  485. },
  486. edit(item) {
  487. this.tmpItem = item;
  488. this.cloneFileIds = this.getCloneResourceIds(item.id)
  489. this.dialogVisible = true;
  490. // 获取焦点
  491. this.$nextTick(() => {
  492. this.$refs.contentEdit.focus()
  493. })
  494. },
  495. isDisabled(item) {
  496. // 默认不可编辑,这个时候 没有disable属性
  497. return item['disable'] !== false;
  498. },
  499. sendData: function () {
  500. this.sendBtnAble = false;
  501. let content = this.contentStr;
  502. let categories = this.tagChecked;
  503. // 循环拼接类似 #tag #tag2 content
  504. let updatedContent = content;
  505. if (categories.length > 0) {
  506. // 循环拼接类似 #tag #tag2 content
  507. updatedContent = categories.map(tag => `#${tag}`).join(' ') + ' ' + content;
  508. }
  509. // updatedContent 去除尾部的\n,可能有多个
  510. updatedContent = updatedContent.replace(/\n+$/, '');
  511. let res = requestUtil.sync('https://memos.tianyunperfect.cn/api/v1/memo', 'post', {content: updatedContent, "resourceIdList": this.tmpFileIds.map(it => it.id)}, myHeaders);
  512. if (res['name']) {
  513. // window.location.href = `https://memos.tianyunperfect.cn/m/${res['name']}`;
  514. this.msg('记录成功');
  515. localStorage.setItem('contentStr', '');
  516. this.contentStr = '';
  517. this.tmpFileIds = []
  518. this.search();
  519. }
  520. this.sendBtnAble = true;
  521. },
  522. search: function () {
  523. document.documentElement.scrollTo(0, 0);
  524. this.resourceMap = {};
  525. let params = {'search': this.searchStr, tag_str: this.tagChecked.join(','), page: this.page, page_size: this.size};
  526. let url = 'https://web_history.tianyunperfect.cn/memos/list';
  527. let urlWithParams = requestUtil.buildUrl(url, params);
  528. let res = requestUtil.sync(urlWithParams, 'get', null, myHeaders);
  529. if (res.code !== 200) {
  530. return;
  531. }
  532. this.contentList = res.res;
  533. // contentList 循环获取里面所有的id数组
  534. let idArr = this.contentList.map(item => item['id']);
  535. // 获取资源
  536. let sourceRes = requestUtil.sync("https://web_history.tianyunperfect.cn/memos/resource", 'post', {ids: idArr.join(',')}, {});
  537. // {'code': 200, 'res': [{'memo_id': 1, 'resource_name': 'EfdmvRsodBviDQWRmDiTaV'}, {'memo_id': 4, 'resource_name': '2rY5kmn3AHsy23vK4vSskV'}, {'memo_id': 7, 'resource_name': 'FMhzJXjoTa7fdtbbCBjXnt'}]}
  538. // 循环遍历,以memo_id为key,resource_name数组为value
  539. sourceRes['res'].forEach(item => {
  540. if (this.resourceMap[item['memo_id']]) {
  541. this.resourceMap[item['memo_id']].push(item);
  542. } else {
  543. this.resourceMap[item['memo_id']] = [item];
  544. }
  545. });
  546. },
  547. getAllTags: function () {
  548. this.allTags = requestUtil.sync('https://memos.tianyunperfect.cn/api/v1/tag', 'get', null, myHeaders);
  549. // 先检查url
  550. if (getQueryString("tags")) {
  551. this.tagChecked = getQueryString("tags").split(',')
  552. return
  553. }
  554. // 否则检查本地存储
  555. let item1 = localStorage.getItem('tags'); // 获取本地存储的标签
  556. if (item1) {
  557. this.tagChecked = JSON.parse(item1);
  558. }
  559. }
  560. }
  561. });
  562. // 如果处于编辑状态,则执行esc取消
  563. window.onkeydown = function (event) {
  564. let edit = vm.dialogVisible;
  565. if (!edit) {
  566. return;
  567. }
  568. // esc
  569. if (event.keyCode === 27) {
  570. vm.dialogVisible = false;
  571. }
  572. // 如果是meta + enter 则保存
  573. if (event.metaKey && event.keyCode === 13) {
  574. vm.confirmSubmit();
  575. }
  576. // 如果是ctrl + enter 则保存
  577. if (event.ctrlKey && event.keyCode === 13) {
  578. vm.confirmSubmit();
  579. }
  580. };
  581. </script>
  582. </body>
  583. </html>