memos.html 33 KB

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