Index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <div class="hello">
  3. <Header> </Header>
  4. <el-container class="container-narrow">
  5. <el-row class="masthead">
  6. <div class="logo-title ">
  7. <h2 class="muted"><img src="static/logo/b_64.png" style="width:50px;height:50px;margin-bottom:-10px;" alt="">ShowDoc</h2>
  8. </div>
  9. <div class="header-btn-group pull-right">
  10. <el-button type="text" @click="feedback">{{$t("feedback")}}</el-button>
  11. <router-link to="/team/index" >&nbsp;&nbsp;&nbsp;{{$t('team_mamage')}}</router-link>
  12. <router-link to="/admin/index" v-if="isAdmin">&nbsp;&nbsp;&nbsp;{{$t('background')}}</router-link>
  13. &nbsp;&nbsp;&nbsp;
  14. <el-dropdown @command="dropdown_callback">
  15. <span class="el-dropdown-link">
  16. {{$t("more")}}<i class="el-icon-arrow-down el-icon--right"></i>
  17. </span>
  18. <el-dropdown-menu slot="dropdown">
  19. <el-dropdown-item><router-link to="/user/setting">{{$t("personal_setting")}}</router-link></el-dropdown-item>
  20. <el-dropdown-item><a target="_blank" v-if="lang =='zh-cn'" href="https://www.showdoc.cc/app">Apps</a></el-dropdown-item>
  21. <el-dropdown-item><a target="_blank" v-if="lang =='zh-cn'" href="http://runapi.showdoc.cc/">RunApi</a></el-dropdown-item>
  22. <el-dropdown-item :command="logout">{{$t("logout")}}</el-dropdown-item>
  23. </el-dropdown-menu>
  24. </el-dropdown>
  25. </div>
  26. </el-row>
  27. </el-container>
  28. <el-container class="container-narrow">
  29. <div class="container-thumbnails">
  30. <div class="search-box-div" v-if="itemList.length > 9">
  31. <div class="search-box el-input el-input--prefix">
  32. <input autocomplete="off" type="text" rows="2" validateevent="true" class="el-input__inner" v-model="keyword">
  33. <span class="el-input__prefix">
  34. <i class="el-input__icon el-icon-search"></i>
  35. </span>
  36. </div>
  37. </div>
  38. <ul class="thumbnails" id="item-list" v-if="itemListByKeyword">
  39. <draggable v-model="itemListByKeyword" tag="span" group="item" @end="endMove" ghostClass="sortable-chosen">
  40. <li class=" text-center" v-for="item in itemListByKeyword"
  41. v-dragging="{ item: item, list: itemListByKeyword, group: 'item' }"
  42. >
  43. <router-link class="thumbnail item-thumbnail" :to="'/' + (item.item_domain ? item.item_domain:item.item_id )" title="">
  44. <span class="item-setting " @click.prevent="click_item_setting(item.item_id)" :title="$t('item_setting')" v-if="item.creator" >
  45. <i class="el-icon-setting"></i>
  46. </span>
  47. <span class="item-exit" @click.prevent="click_item_exit(item.item_id)" :title="$t('item_exit')" v-if="! item.creator">
  48. <i class="el-icon-close"></i>
  49. </span>
  50. <p class="my-item">{{item.item_name}}</p>
  51. </router-link>
  52. </li>
  53. </draggable>
  54. <li class=" text-center" >
  55. <router-link class="thumbnail item-thumbnail" to="/item/add" title="">
  56. <p class="my-item">{{$t('new_item')}}<i class="el-icon-plus"></i></p>
  57. </router-link>
  58. </li>
  59. </ul>
  60. </div>
  61. </el-container>
  62. <Footer> </Footer>
  63. </div>
  64. </template>
  65. <style scoped>
  66. .container-narrow{
  67. margin: 0 auto;
  68. max-width: 930px;
  69. }
  70. .masthead{
  71. width: 100%;
  72. margin-top: 30px;
  73. }
  74. .header-btn-group{
  75. margin-top: -38px;
  76. }
  77. .logo-title{
  78. margin-left: 0px;
  79. }
  80. .container-thumbnails{
  81. margin-top: 30px;
  82. max-width: 1000px;
  83. }
  84. .my-item{
  85. margin: 40px 5px;
  86. }
  87. .thumbnails li {
  88. float: left;
  89. margin-bottom: 20px;
  90. margin-left: 20px;
  91. }
  92. .thumbnails li a{
  93. color: #444;
  94. font-weight: bold;
  95. height: 100px;
  96. width: 180px;
  97. }
  98. .thumbnails li a:hover,
  99. .thumbnails li a:focus{
  100. border-color:#f2f5e9;
  101. -webkit-box-shadow:none;
  102. box-shadow:none;
  103. text-decoration: none;
  104. background-color: #f2f5e9;
  105. }
  106. .thumbnail {
  107. display: block;
  108. padding: 4px;
  109. line-height: 20px;
  110. border: 1px solid #ddd;
  111. -webkit-border-radius: 4px;
  112. -moz-border-radius: 4px;
  113. border-radius: 4px;
  114. -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.055);
  115. -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.055);
  116. box-shadow: 0 1px 3px rgba(0,0,0,0.055);
  117. -webkit-transition: all .2s ease-in-out;
  118. -moz-transition: all .2s ease-in-out;
  119. -o-transition: all .2s ease-in-out;
  120. transition: all .2s ease-in-out;
  121. list-style: none;
  122. background-color: #ffffff;
  123. }
  124. .item-setting{
  125. float:right;
  126. margin-right:15px;
  127. margin-top:5px;
  128. display: none;
  129. }
  130. .item-exit{
  131. float:right;
  132. margin-right:5px;
  133. margin-top:5px;
  134. display: none;
  135. }
  136. .thumbnails li a i{
  137. color: #777;
  138. font-weight: bold;
  139. margin-left: 5px;
  140. }
  141. .item-thumbnail:hover .item-setting {
  142. display: block;
  143. }
  144. .item-thumbnail:hover .item-exit {
  145. display: block;
  146. }
  147. .search-box-div{
  148. width: 190px;
  149. margin-left: 60px;
  150. }
  151. .sortable-chosen .item-thumbnail{
  152. color: #ffffff;
  153. background-color: #ffffff;
  154. }
  155. </style>
  156. <script>
  157. import draggable from 'vuedraggable'
  158. if (typeof window !== 'undefined') {
  159. var $s = require('scriptjs');
  160. }
  161. export default {
  162. components: {
  163. draggable,
  164. },
  165. data() {
  166. return {
  167. currentDate: new Date(),
  168. itemList:{},
  169. isAdmin:false,
  170. keyword:'',
  171. lang:''
  172. };
  173. },
  174. computed:{
  175. itemListByKeyword:function(){
  176. if (!this.keyword) {
  177. return this.itemList ;
  178. };
  179. let itemListByKeyword = [] ;
  180. for (var i = 0; i < this.itemList.length; i++) {
  181. if (this.itemList[i]['item_name'].indexOf(this.keyword) > -1 ) {
  182. itemListByKeyword.push(this.itemList[i]);
  183. };
  184. };
  185. return itemListByKeyword ;
  186. }
  187. },
  188. methods:{
  189. get_item_list(){
  190. var that = this ;
  191. var url = DocConfig.server+'/api/item/myList';
  192. var params = new URLSearchParams();
  193. that.axios.get(url, params)
  194. .then(function (response) {
  195. if (response.data.error_code === 0 ) {
  196. //that.$message.success("加载成功");
  197. var json = response.data.data ;
  198. that.itemList = json ;
  199. //that.bind_item_even();
  200. }else{
  201. that.$alert(response.data.error_message);
  202. }
  203. });
  204. },
  205. feedback(){
  206. if (DocConfig.lang =='en') {
  207. window.open('https://github.com/star7th/showdoc/issues');
  208. }else{
  209. var msg = "你正在使用免费开源版showdoc,如有问题或者建议,请到github提issue:";
  210. msg += "<a href='https://github.com/star7th/showdoc/issues' target='_blank'>https://github.com/star7th/showdoc/issues</a><br>";
  211. msg += "如果你觉得showdoc好用,不妨给开源项目点一个star。良好的关注度和参与度有助于开源项目的长远发展。";
  212. this.$alert(msg, {
  213. dangerouslyUseHTMLString: true
  214. });
  215. }
  216. },
  217. item_top_class(top){
  218. if (top) {
  219. return 'el-icon-arrow-down';
  220. };
  221. return 'el-icon-arrow-up';
  222. },
  223. bind_item_even(){
  224. //这里偷个懒,直接用jquery来操作DOM。因为老版本的代码就是基于jquery的,所以复制过来稍微改下
  225. $s(["static/jquery.min.js"],()=>{
  226. //当鼠标放在项目上时将浮现设置和置顶图标
  227. $(".item-thumbnail").mouseover(function(){
  228. $(this).find(".item-setting").show();
  229. //$(this).find(".item-top").show();
  230. //$(this).find(".item-down").show();
  231. });
  232. //当鼠标离开项目上时将隐藏设置和置顶图标
  233. $(".item-thumbnail").mouseout(function(){
  234. $(this).find(".item-setting").hide();
  235. $(this).find(".item-top").hide();
  236. $(this).find(".item-down").hide();
  237. });
  238. });
  239. },
  240. //进入项目设置页
  241. click_item_setting(item_id){
  242. this.$router.push({path:'/item/setting/'+item_id});
  243. },
  244. click_item_exit(item_id){
  245. var that = this ;
  246. this.$confirm(that.$t('confirm_exit_item'), ' ', {
  247. confirmButtonText: that.$t('confirm'),
  248. cancelButtonText: that.$t('cancel'),
  249. type: 'warning'
  250. }).then(() => {
  251. var url = DocConfig.server+'/api/item/exitItem';
  252. var params = new URLSearchParams();
  253. params.append('item_id', item_id);
  254. that.axios.post(url, params)
  255. .then(function (response) {
  256. if (response.data.error_code === 0 ) {
  257. window.location.reload();
  258. }else{
  259. that.$alert(response.data.error_message);
  260. }
  261. });
  262. })
  263. },
  264. logout(){
  265. var that = this ;
  266. var url = DocConfig.server+'/api/user/logout';
  267. var params = new URLSearchParams();
  268. that.axios.get(url, params)
  269. .then(function (response) {
  270. if (response.data.error_code === 0 ) {
  271. that.$router.push({
  272. path: '/'
  273. });
  274. }else{
  275. that.$alert(response.data.error_message);
  276. }
  277. });
  278. },
  279. user_info(){
  280. var that = this ;
  281. this.get_user_info(function(response){
  282. if (response.data.error_code === 0 ) {
  283. if (response.data.data.groupid == 1 ) {
  284. that.isAdmin = true ;
  285. };
  286. }
  287. });
  288. },
  289. dropdown_callback(data){
  290. if (data) {
  291. data();
  292. };
  293. },
  294. sort_item(data){
  295. var that = this ;
  296. var url = DocConfig.server+'/api/item/sort';
  297. var params = new URLSearchParams();
  298. params.append('data', JSON.stringify(data));
  299. that.axios.post(url, params)
  300. .then(function (response) {
  301. if (response.data.error_code === 0 ) {
  302. that.get_item_list();
  303. //window.location.reload();
  304. }else{
  305. that.$alert(response.data.error_message,'',{
  306. callback:function(){
  307. window.location.reload();
  308. }
  309. });
  310. }
  311. });
  312. },
  313. exchangeArray( data , i , j ){
  314. let tmp = data[i];
  315. data[i] = data[j];
  316. data[j] = tmp ;
  317. return data;
  318. },
  319. endMove(evt){
  320. let data = {} ;
  321. let list = this.exchangeArray( this.itemList , evt['oldIndex'] , evt['newIndex'] ) ;
  322. this.itemList = [] ;
  323. this.$nextTick(()=>{
  324. this.itemList = list ;
  325. });
  326. for (var i = 0; i < list.length; i++) {
  327. let key = list[i]['item_id'] ;
  328. data[key] = i + 1 ;
  329. };
  330. this.sort_item(data);
  331. },
  332. script_cron(){
  333. var url = DocConfig.server+'/api/ScriptCron/run';
  334. this.axios.get(url);
  335. }
  336. },
  337. mounted () {
  338. this.get_item_list();
  339. this.user_info();
  340. this.lang = DocConfig.lang ;
  341. this.script_cron();
  342. },
  343. beforeDestroy(){
  344. this.$message.closeAll();
  345. }
  346. }
  347. </script>