memos.html 33 KB

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