Index.vue 11 KB

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