send_memos.html 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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="searchStrChange"></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. <div style="display: flex;">
  114. <div>
  115. <el-checkbox-group v-model="tagChecked" @change="checkChange1()">
  116. <el-checkbox-button v-for="tag in allTags" :label="tag"></el-checkbox-button>
  117. </el-checkbox-group>
  118. </div>
  119. <div style="margin-left: 20px; display: flex;align-items: center">
  120. <el-switch
  121. @change="duoxuanChange"
  122. v-model="duoxuan"
  123. active-text="多选"
  124. inactive-text="单选"
  125. >
  126. </el-switch>
  127. </div>
  128. </div>
  129. <div id="tags"></div>
  130. </div>
  131. <div style="margin-top: 180px"></div>
  132. <div v-for="item in contentList">
  133. <el-row style="margin: 10px; padding: 10px" class="border">
  134. <el-col :span="16" class="contentLine">
  135. <div style="display: flex">
  136. <el-date-picker
  137. v-model="item.created_ts"
  138. type="datetime"
  139. readonly="true"
  140. placeholder="选择日期时间">
  141. </el-date-picker>
  142. <div style="margin-left: 20px">
  143. <el-checkbox-button v-for="tag in commonTags" :label="tag" :key="item"
  144. @change="checked=>checkChange(checked,item,tag)"
  145. :checked="isChooseTag(item,tag)">{{tag}}
  146. </el-checkbox-button>
  147. </div>
  148. </div>
  149. <div class="myText" @dblclick="edit(item)">
  150. <el-input v-model="item.content" type="textarea" :autosize="{minRows: 1}" readonly="true"></el-input>
  151. </div>
  152. <div>
  153. <div v-for="item in resourceMap[item.id]">
  154. <el-image v-if="item['type'].startsWith('image')"
  155. :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=150'"
  156. :preview-src-list="['https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=750']"
  157. class="img">
  158. </el-image>
  159. <audio controls v-if="item['type'].startsWith('audio')">
  160. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/ogg">
  161. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/mpeg">
  162. 您的浏览器不支持 audio 元素。
  163. </audio>
  164. <video width="320" height="240" controls v-if="item['type'].startsWith('video')">
  165. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/mp4">
  166. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/ogg">
  167. 您的浏览器不支持 HTML5 video 元素。
  168. </video>
  169. <el-link v-if="item['type'].startsWith('application')" :href="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" target="_blank">{{item['filename']}}</el-link>
  170. </div>
  171. </div>
  172. </el-col>
  173. <el-col :span="4" style="display: flex">
  174. <div class="editClass">
  175. <el-button size="small" @click="window.open('https://memos.tianyunperfect.cn/m/' + item.resource_name)">跳转</el-button>
  176. <br>
  177. <el-button size="small" @click="edit(item)">编辑</el-button>
  178. </div>
  179. <div class="editClass">
  180. <el-button size="small" @click="archive(item)">归档</el-button>
  181. <br>
  182. <el-button size="small" type="warning" @click="del(item)">删除</el-button>
  183. </div>
  184. </el-col>
  185. </el-row>
  186. </div>
  187. </div>
  188. <el-dialog
  189. title="提示"
  190. :visible.sync="dialogVisible"
  191. width="60%"
  192. >
  193. <div v-if="tmpItem.id" class="contentLine">
  194. <div>
  195. <el-date-picker
  196. v-model="tmpItem.created_ts"
  197. type="datetime"
  198. value-format="yyyy-MM-ddTHH:mm:ss"
  199. placeholder="选择日期时间">
  200. </el-date-picker>
  201. </div>
  202. <div>
  203. <el-input
  204. @paste.native="handlePaste2"
  205. ref="contentEdit" v-model="tmpItem.content" type="textarea" :autosize="{minRows: 2}"></el-input>
  206. </div>
  207. <div style="display: flex">
  208. <div v-for="item in cloneFileIds">
  209. <el-image v-if="item['type'].startsWith('image')"
  210. :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=150'"
  211. :preview-src-list="['https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=750']"
  212. class="img">
  213. </el-image>
  214. <audio controls v-if="item['type'].startsWith('audio')">
  215. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/ogg">
  216. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/mpeg">
  217. 您的浏览器不支持 audio 元素。
  218. </audio>
  219. <video width="320" height="240" controls v-if="item['type'].startsWith('video')">
  220. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/mp4">
  221. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/ogg">
  222. 您的浏览器不支持 HTML5 video 元素。
  223. </video>
  224. <el-link v-if="item['type'].startsWith('application')" :href="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" target="_blank">{{item['filename']}}</el-link>
  225. <div @click="delPic(img)">删除</div>
  226. </div>
  227. </div>
  228. </div>
  229. <span slot="footer" class="dialog-footer">
  230. <el-button @click="dialogVisible = false">取 消</el-button>
  231. <el-button type="primary" @click="confirmSubmit">确 定</el-button>
  232. </span>
  233. </el-dialog>
  234. </div>
  235. <!-- 引入Quill库 -->
  236. <!--<script src="./js/cdn.quilljs.com_1.3.6_quill.js"></script>-->
  237. <!--异步请求示例:requestUtil.sync('https://jsonplaceholder.typicode.com/posts/1', 'post', data, headers) .then(data => console.log(data))-->
  238. <script>
  239. // if (getQueryString("id") !== "tianyunperfect") {
  240. // // location.href = "http://127.0.0.1";
  241. // }
  242. let authStr = "bearer eyJhbGciOiJIUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJuYW1lIjoidGlhbnl1bnBlcmZlY3QiLCJpc3MiOiJtZW1vcyIsInN1YiI6IjEiLCJhdWQiOlsidXNlci5hY2Nlc3MtdG9rZW4iXSwiaWF0IjoxNzA5MTc5NTUyfQ.LFxWB4efya1sL7VoJ42xpXxbAip-udT_Kx2OwZ8Y3-E";
  243. let myHeaders = {
  244. 'Content-type': 'application/json',
  245. 'Authorization': authStr
  246. };
  247. function getRandomId() {
  248. return Math.random().toString(36).substr(2);
  249. }
  250. let vm = new Vue({
  251. el: '#app',
  252. data: {
  253. duoxuan: false,
  254. tmpItem: {},
  255. dialogVisible: false,
  256. page: 1,
  257. size: 20,
  258. searchStr: '',
  259. contentStr: '',
  260. tagChecked: [],
  261. allTags: [],
  262. contentList: [],
  263. sendBtnAble: true,
  264. resourceMap: {}, // 资源map,
  265. commonTags: ['todo'],
  266. upload_url: 'https://memos.tianyunperfect.cn/api/v1/resource/blob',
  267. tmpFileIds: [],
  268. cloneFileIds: []
  269. },
  270. watch: {
  271. page: function () {
  272. this.search();
  273. },
  274. size: function () {
  275. this.search();
  276. }
  277. },
  278. mounted() {
  279. if (!checkLogin()) {
  280. return;
  281. }
  282. if (this.getQueryStr()) {
  283. this.searchStr = this.getQueryStr();
  284. }
  285. this.duoxuan = this.getDuoXuan();
  286. // 初始化contentStr,如果本地有缓存
  287. let item = localStorage.getItem('contentStr');
  288. if (item) {
  289. this.contentStr = item;
  290. }
  291. let queryStr = this.getQueryStr();
  292. if (queryStr) {
  293. this.searchStr = queryStr;
  294. }
  295. // 解码
  296. let tagsStr = decodeURIComponent(getQueryString("tags"));
  297. if (tagsStr) {
  298. this.tagChecked = tagsStr.split(',')
  299. }
  300. this.getAllTags();
  301. this.search();
  302. requestUtil.async('https://web_history.tianyunperfect.cn/memos/getCustomMemoTags', 'get').then(res => {
  303. this.commonTags = JSON.parse(res['res'][0]['content']);
  304. });
  305. },
  306. methods: {
  307. searchStrChange() {
  308. location.href = requestUtil.buildUrl(location.href, {'queryStr': this.searchStr})
  309. },
  310. duoxuanChange() {
  311. if (this.duoxuan) {
  312. this.setDuoXuan('ok');
  313. } else {
  314. this.setDuoXuan('');
  315. }
  316. },
  317. checkChange1(newVal) {
  318. console.log(this.tagChecked)
  319. if (!this.getDuoXuan()) {
  320. if (this.tagChecked.length > 1) {
  321. // 保留最后一个
  322. this.tagChecked = [this.tagChecked[this.tagChecked.length - 1]];
  323. }
  324. }
  325. location.href = requestUtil.buildUrl(location.href, {'tags': this.tagChecked.join(',')})
  326. },
  327. getQueryStr() {
  328. return getQueryString('queryStr')
  329. },
  330. getDuoXuan() {
  331. return getQueryString('duoxuan') == "ok";
  332. },
  333. setDuoXuan(ok) {
  334. location.href = requestUtil.buildUrl(location.href, {'duoxuan': ok})
  335. },
  336. removeTmp(item) {
  337. // tmpFileIds 根据id删除
  338. let index = this.tmpFileIds.findIndex(item => item.id === item.id);
  339. if (index !== -1) {
  340. this.tmpFileIds.splice(index, 1);
  341. }
  342. },
  343. delPic(img) {
  344. // 根据id从 cloneFileIds 删除
  345. let index = this.cloneFileIds.findIndex(item => item.id === img.id);
  346. if (index !== -1) {
  347. this.cloneFileIds.splice(index, 1);
  348. }
  349. },
  350. getCloneResourceIds(id) {
  351. let resourceMapElement = this.resourceMap[id];
  352. if (resourceMapElement) {
  353. return JSON.parse(JSON.stringify(resourceMapElement))
  354. }
  355. return []
  356. },
  357. uploadFile(url, file, headers = {}) {
  358. return new Promise((resolve, reject) => {
  359. const xhr = new XMLHttpRequest();
  360. xhr.open('POST', url, true); // 使用异步的方式
  361. const formData = new FormData();
  362. formData.append('file', file);
  363. for (const [key, value] of Object.entries(headers)) {
  364. xhr.setRequestHeader(key, value);
  365. }
  366. xhr.onload = function () {
  367. if (xhr.status === 200) {
  368. resolve(JSON.parse(xhr.responseText));
  369. } else {
  370. reject(new Error(xhr.statusText));
  371. }
  372. };
  373. xhr.onerror = function () {
  374. reject(new Error("Network Error"));
  375. };
  376. xhr.send(formData);
  377. });
  378. },
  379. getFileFromPaste(e) {
  380. let clipboardData = e.clipboardData; // IE
  381. if (!clipboardData) {
  382. //chrome
  383. clipboardData = e.originalEvent.clipboardData;
  384. }
  385. let items = '';
  386. items = (e.clipboardData || window.clipboardData).items;
  387. let file = null;
  388. if (!items || items.length === 0) {
  389. this.$message.error('当前浏览器不支持粘贴本地图片,请打开图片复制后再粘贴!');
  390. return;
  391. }
  392. // 搜索剪切板items
  393. for (let i = 0; i < items.length; i++) {
  394. // 限制上传文件类型
  395. if (items[i].type.indexOf('image') !== -1) {
  396. file = items[i].getAsFile();
  397. break;
  398. }
  399. }
  400. // 对复制黏贴的类型进行判断,若是非文件类型,比如复制黏贴的文字,则不会调用上传文件的函数
  401. if (file) {
  402. return file;
  403. }
  404. },
  405. handlePaste(e) {
  406. let file = this.getFileFromPaste(e);
  407. // 对复制黏贴的类型进行判断,若是非文件类型,比如复制黏贴的文字,则不会调用上传文件的函数
  408. if (file) {
  409. this.uploadFile(this.upload_url, file, {'Authorization': myHeaders['Authorization']}).then(res => {
  410. let fileId = res['id'];
  411. if (fileId) {
  412. let sourceRes = requestUtil.sync("https://web_history.tianyunperfect.cn/memos/resourceById", 'post', {ids: fileId}, {});
  413. let sourceRe = sourceRes['res'];
  414. this.tmpFileIds.push(...sourceRe)
  415. }
  416. });
  417. }
  418. },
  419. handlePaste2(e) {
  420. let file = this.getFileFromPaste(e);
  421. // 对复制黏贴的类型进行判断,若是非文件类型,比如复制黏贴的文字,则不会调用上传文件的函数
  422. if (file) {
  423. this.uploadFile(this.upload_url, file, {'Authorization': myHeaders['Authorization']}).then(res => {
  424. let fileId = res['id'];
  425. if (fileId) {
  426. let sourceRes = requestUtil.sync("https://web_history.tianyunperfect.cn/memos/resourceById", 'post', {ids: fileId}, {});
  427. let sourceRe = sourceRes['res'];
  428. this.cloneFileIds.push(...sourceRe)
  429. }
  430. });
  431. }
  432. },
  433. keyDown() {
  434. // 如果是ctrl + enter \ meta + enter 则发送
  435. if (event.ctrlKey || event.metaKey) {
  436. this.sendData();
  437. }
  438. },
  439. msg(content) {
  440. this.$message({
  441. message: content,
  442. type: 'success'
  443. });
  444. },
  445. isChooseTag(item, tag) {
  446. return item.content.indexOf("#" + tag + " ") !== -1;
  447. },
  448. checkChange(val, item, tag) {
  449. if (val) {
  450. this.addTag(item, tag);
  451. } else {
  452. this.delTag(item, tag);
  453. }
  454. },
  455. addTag(item, cTag) {
  456. let content = item.content;
  457. // 如果已经有了,就不添加
  458. let tmpTag = '#' + cTag + ' ';
  459. if (content.indexOf(tmpTag) !== -1) {
  460. return;
  461. }
  462. item.content = tmpTag + content;
  463. // 提交记录
  464. let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/updateContent', 'post', {
  465. id: item.id,
  466. content: item.content,
  467. created_ts: item.created_ts
  468. }, {});
  469. if (res.code === 200) {
  470. this.msg('更新成功');
  471. // this.search();
  472. }
  473. },
  474. delTag(item, cTag) {
  475. let content = item.content;
  476. // 如果没有,就不删除
  477. if (content.indexOf(cTag) === -1) {
  478. return;
  479. }
  480. item.content = content.replace('#' + cTag + " ", '');
  481. // 提交记录
  482. let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/updateContent', 'post', {
  483. id: item.id,
  484. content: item.content,
  485. created_ts: item.created_ts
  486. }, {});
  487. if (res.code === 200) {
  488. this.msg('更新成功');
  489. // this.search();
  490. }
  491. },
  492. del(item) {
  493. // 提醒是否删除
  494. this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'}).then(() => {
  495. requestUtil.async(`https://web_history.tianyunperfect.cn/memos/delete`, 'post', {id: item.id}, {}).then(res => {
  496. if (res.code === 200) {
  497. this.msg('删除成功');
  498. // 在 this.contentList 上直接去除
  499. this.contentList = this.contentList.filter(it => it.id !== item.id);
  500. }
  501. });
  502. })
  503. },
  504. archive(item) {
  505. requestUtil.async(`https://web_history.tianyunperfect.cn/memos/archive`, 'post', {id: item.id}, {}).then(res => {
  506. this.msg('归档成功');
  507. // 本地缓存更新
  508. this.contentList = this.contentList.filter(it => it.id !== item.id);
  509. });
  510. },
  511. handleClose(done) {
  512. this.dialogVisible = false;
  513. done();
  514. },
  515. confirmSubmit(done) {
  516. // 提交记录
  517. let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/update', 'post', {
  518. id: this.tmpItem.id,
  519. content: this.tmpItem.content,
  520. created_ts: this.tmpItem.created_ts,
  521. resourceIdList: this.cloneFileIds.map(it => it.id)
  522. }, {});
  523. if (res.code === 200) {
  524. this.msg('更新成功');
  525. // 更新主页面的图片
  526. this.resourceMap[this.tmpItem.id] = this.cloneFileIds;
  527. // this.search();
  528. }
  529. this.dialogVisible = false;
  530. done();
  531. },
  532. edit(item) {
  533. this.tmpItem = item;
  534. this.cloneFileIds = this.getCloneResourceIds(item.id)
  535. this.dialogVisible = true;
  536. // 获取焦点
  537. this.$nextTick(() => {
  538. this.$refs.contentEdit.focus()
  539. })
  540. },
  541. isDisabled(item) {
  542. // 默认不可编辑,这个时候 没有disable属性
  543. return item['disable'] !== false;
  544. },
  545. sendData: function () {
  546. this.sendBtnAble = false;
  547. let content = this.contentStr;
  548. let categories = this.tagChecked;
  549. // 循环拼接类似 #tag #tag2 content
  550. let updatedContent = content;
  551. if (categories.length > 0) {
  552. // 循环拼接类似 #tag #tag2 content
  553. updatedContent = categories.map(tag => `#${tag}`).join(' ') + ' ' + content;
  554. }
  555. // updatedContent 去除尾部的\n,可能有多个
  556. updatedContent = updatedContent.replace(/\n+$/, '');
  557. let res = requestUtil.sync('https://memos.tianyunperfect.cn/api/v1/memo', 'post', {content: updatedContent, "resourceIdList": this.tmpFileIds.map(it => it.id)}, myHeaders);
  558. if (res['name']) {
  559. // window.location.href = `https://memos.tianyunperfect.cn/m/${res['name']}`;
  560. this.msg('记录成功');
  561. localStorage.setItem('contentStr', '');
  562. this.contentStr = '';
  563. this.tmpFileIds = []
  564. this.search();
  565. }
  566. this.sendBtnAble = true;
  567. },
  568. search: function () {
  569. document.documentElement.scrollTo(0, 0);
  570. this.resourceMap = {};
  571. console.log(this.tagChecked);
  572. let params = {'search': this.searchStr, tag_str: this.tagChecked.join(','), page: this.page, page_size: this.size};
  573. let url = 'https://web_history.tianyunperfect.cn/memos/list';
  574. let urlWithParams = requestUtil.buildUrl(url, params);
  575. let res = requestUtil.sync(urlWithParams, 'get', null, myHeaders);
  576. if (res.code !== 200) {
  577. return;
  578. }
  579. this.contentList = res.res;
  580. // contentList 循环获取里面所有的id数组
  581. let idArr = this.contentList.map(item => item['id']);
  582. // 获取资源
  583. let ids = idArr.join(',');
  584. if (!ids) {
  585. return;
  586. }
  587. let sourceRes = requestUtil.sync("https://web_history.tianyunperfect.cn/memos/resource", 'post', {ids: ids}, {});
  588. // {'code': 200, 'res': [{'memo_id': 1, 'resource_name': 'EfdmvRsodBviDQWRmDiTaV'}, {'memo_id': 4, 'resource_name': '2rY5kmn3AHsy23vK4vSskV'}, {'memo_id': 7, 'resource_name': 'FMhzJXjoTa7fdtbbCBjXnt'}]}
  589. // 循环遍历,以memo_id为key,resource_name数组为value
  590. sourceRes['res'].forEach(item => {
  591. if (this.resourceMap[item['memo_id']]) {
  592. this.resourceMap[item['memo_id']].push(item);
  593. } else {
  594. this.resourceMap[item['memo_id']] = [item];
  595. }
  596. });
  597. },
  598. getAllTags: function () {
  599. this.allTags = requestUtil.async('https://memos.tianyunperfect.cn/api/v1/tag', 'get', null, myHeaders).then(res => {
  600. this.allTags = res;
  601. })
  602. }
  603. }
  604. });
  605. // 如果处于编辑状态,则执行esc取消
  606. window.onkeydown = function (event) {
  607. let edit = vm.dialogVisible;
  608. if (!edit) {
  609. return;
  610. }
  611. // esc
  612. if (event.keyCode === 27) {
  613. vm.dialogVisible = false;
  614. }
  615. // 如果是meta + enter 则保存
  616. if (event.metaKey && event.keyCode === 13) {
  617. vm.confirmSubmit();
  618. }
  619. // 如果是ctrl + enter 则保存
  620. if (event.ctrlKey && event.keyCode === 13) {
  621. vm.confirmSubmit();
  622. }
  623. };
  624. </script>
  625. </body>
  626. </html>