components.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. var componentSelect = {
  2. template: `
  3. <div class="my-Select" v-bind:style="'width:'+ width">
  4. <i v-if="!specile" class="fa fa-sort-up" v-bind:class="selectShow ? 'rotate180' : ''"></i>
  5. <div @click.stop = "showList($event)"
  6. class="select-screen"
  7. v-bind:class="changeClass()"
  8. ref="selectBorder">
  9. <input
  10. placeholder="请选择"
  11. type="text"
  12. ref="selectSearch"
  13. v-if="!multiple"
  14. v-bind:disabled="disabled"
  15. v-bind:value="name"
  16. @foucs.stop = "showList($event)"
  17. @blur.stop = "hideList()"
  18. @input="setScreen($event)"
  19. />
  20. <div
  21. v-if="multiple"
  22. @click.stop = "showList($event)">
  23. <span v-for="(item,index) in multipleList" class="multiple-list">
  24. <span>{{item.name}}</span>
  25. <i v-on:click.stop="multipleRemove(index)" style="font-style:normal;">&times;</i>
  26. </span>
  27. </div>
  28. </div>
  29. <transition type="animation" enter-active-class="fadeIn">
  30. <ul v-if="!specile" v-bind:class="disabled ? 'disabled': ''" :style="'top:'+top+'px;'" class="select-list" v-show = "selectShow"> <slot v-bind:message="val"></slot>
  31. </ul>
  32. <ul v-else-if="specile" v-bind:class="disabled ? 'disabled': ''" class="select-list select-list-specile" > <slot v-bind:message="val"></slot>
  33. </ul>
  34. </transition>
  35. </div>
  36. </div>`,
  37. props: ['width', 'value'],
  38. data: function () { //data必须是一个函数
  39. return {
  40. selectShow: false,
  41. top: '',
  42. name: '',
  43. screen: '',
  44. multipleList: [],
  45. val: ''
  46. }
  47. },
  48. computed: {
  49. disabled: function () {
  50. if (this.$attrs && (this.$attrs.disabled === 'true' || this.$attrs.disabled === '' || this.$attrs.disabled === 'disabled')) {
  51. return true
  52. } else {
  53. return false
  54. }
  55. },
  56. multiple: function () {
  57. if (this.$attrs && (this.$attrs.multiple === 'true' || this.$attrs.multiple === '' || this.$attrs.multiple === 'multiple')) {
  58. return true
  59. } else {
  60. return false
  61. }
  62. },
  63. specile: function () {
  64. if (this.$attrs && (this.$attrs.specile === 'true' || this.$attrs.specile === '' || this.$attrs.specile === 'specile')) {
  65. return true;
  66. } else {
  67. return false;
  68. }
  69. }
  70. },
  71. methods: {
  72. hideList: function () {
  73. var _this = this;
  74. window.setTimeout(function () {
  75. _this.selectShow = false
  76. }, 250);
  77. },
  78. setScreen: function (e) {
  79. var ele = e.target || e.srcElement;
  80. this.screen = ele.value
  81. },
  82. /* 切换外层class */
  83. changeClass: function () {
  84. if (this.disabled) {
  85. return 'disabled'
  86. } else if (this.selectShow) {
  87. return 'active'
  88. } else {
  89. return ''
  90. }
  91. },
  92. /* 展开子组件 */
  93. showList: function (event) {
  94. if (this.disabled) {
  95. return;
  96. }
  97. var ele = event.target || event.srcElement;
  98. if (!this.multiple) {
  99. if (ele.tagName == 'INPUT') {
  100. ele.select();
  101. } else {
  102. this.$refs.selectSearch.select();
  103. }
  104. }
  105. this.top = this.$refs.selectBorder.clientHeight + 7;
  106. this.selectShow = true;
  107. },
  108. findName: function () {
  109. var self = this;
  110. var status = false;
  111. this.$children.forEach(function () {
  112. if (self.val !== undefined && arguments[0].value !== undefined && ((self.val !== undefined && self.val !== null && self.val.toString) ? self.val.toString() : self.val) === (arguments[0].value.toString ? arguments[0].value.toString() : arguments[0].value)) {
  113. self.name = arguments[0].name;
  114. status = true;
  115. }
  116. })
  117. if (!status) {
  118. self.name = '';
  119. }
  120. },
  121. findMultipleName: function () {
  122. var self = this;
  123. /* 与循环的value顺序一致 用作删除 (就说了表达能力不强 不适合注释) */
  124. var ary = [];
  125. this.multipleList = [];
  126. this.$children.forEach(function () {
  127. if ($.inArray(arguments[0].value.toString(), self.val) != -1) {
  128. self.multipleList.push({value: arguments[0].value, name: arguments[0].name})
  129. ary.push(arguments[0].value.toString())
  130. }
  131. })
  132. this.val = ary
  133. },
  134. /* 多选删除项 */
  135. multipleRemove: function (index) {
  136. this.multipleList.splice(index, 1);
  137. this.val.splice(index, 1);
  138. this.$emit('input', this.val);
  139. }
  140. },
  141. mounted: function () {
  142. var self = this;
  143. // $('body').bind('click',function(){
  144. // self.selectShow = false;
  145. // });
  146. this.val = this.value;
  147. !this.multiple ? this.findName() : this.findMultipleName();
  148. },
  149. watch: {
  150. 'value': {
  151. handler: function (val, value) {
  152. this.val = val;
  153. this.$nextTick(function () {
  154. !this.multiple ? this.findName() : this.findMultipleName();
  155. })
  156. }
  157. },
  158. 'selectShow': {
  159. handler: function (val) {
  160. if (val == false) {
  161. this.screen = '';
  162. }
  163. }
  164. },
  165. /* 检测增加删除多选 改变多选框top值 */
  166. 'multipleList': {
  167. handler: function () {
  168. this.$nextTick(function () {
  169. this.top = this.$refs.selectBorder.clientHeight + 7;
  170. })
  171. }
  172. }
  173. }
  174. }
  175. var componentOption = {
  176. template: `<li
  177. v-bind:value="value"
  178. v-show="screenVal"
  179. v-bind:class="((parent.val !== undefined && parent.val !== null && parent.val.toString) ? parent.val.toString() : parent.val) === ((value !== undefined && value !== null && value.toString) ? value.toString() : value)? 'active' : ''"
  180. v-on:click.stop="valueHandle(value,name)" >
  181. {{name}}
  182. </li>`,
  183. props: ['value', 'name'],
  184. data: function () {
  185. return {}
  186. },
  187. computed: {
  188. parent: function () {
  189. return this.$parent;
  190. },
  191. /* 搜索筛选时 */
  192. screenVal: function () {
  193. if (this.name && this.name.indexOf(this.$parent.screen) == -1) {
  194. return false
  195. } else {
  196. /* 如果多选 被选中的隐藏 */
  197. if (this.multiple) {
  198. if ($.inArray(this.value.toString(), this.$parent.val) == -1) {
  199. return true
  200. } else {
  201. return false
  202. }
  203. } else {
  204. return true
  205. }
  206. }
  207. },
  208. multiple: function () {
  209. if (this.$parent.$attrs && (this.$parent.$attrs.multiple === 'true' || this.$parent.$attrs.multiple === '' || this.$parent.$attrs.multiple === 'multiple')) {
  210. return true
  211. } else {
  212. return false
  213. }
  214. },
  215. disabled: function () {
  216. if (this.$parent.$attrs && (this.$parent.$attrs.disabled === 'true' || this.$parent.$attrs.disabled === '' || this.$parent.$attrs.disabled === 'disabled')) {
  217. return true
  218. } else {
  219. return false
  220. }
  221. }
  222. },
  223. methods: {
  224. valueHandle: function (val, name) {
  225. if (this.disabled) {
  226. return;
  227. }
  228. if (this.multiple) {
  229. this.parent.multipleList.push({value: val, name: name})
  230. this.parent.val.push(val.toString());
  231. this.parent.$emit('input', this.parent.val);
  232. this.parent.$emit('change', this.parent.val)
  233. } else {
  234. var old = this.parent.val;
  235. this.parent.val = val;
  236. this.parent.name = name;
  237. this.parent.selectShow = false;
  238. this.parent.$emit('input', val, old);
  239. this.parent.$emit('change', val, old)
  240. }
  241. }
  242. },
  243. mounted: function () {
  244. }
  245. }
  246. var componentSelectbar = {
  247. template: `
  248. <ul>
  249. <li v-for="item in list" v-bind:class="pathselect(item) ? 'active' : ''">
  250. <a :target="item.target" v-bind:href="item.url" @click="item.slideDown = !item.slideDown">
  251. <i v-bind:class="item.icon"></i> <span v-html="item.name"></span>
  252. <i v-if="item.childs" v-bind:class="item.slideDown ? 'fa-angle-down' :' fa-angle-right'" class="fa pull-right"></i>
  253. </a>
  254. <div v-show="item.slideDown" v-if="item.childs" class="slidebar-childs">
  255. <ul>
  256. <li v-for="item2 in item.childs" v-bind:class="pathselect(item2, item) ? 'active' : ''">
  257. <a :target="item2.target" v-bind:href="item2.url">
  258. <i v-bind:class="item2.icon"></i> <span v-html="item2.name"></span>
  259. </a>
  260. </li>
  261. </ul>
  262. </div>
  263. </li>
  264. </ul>
  265. `,
  266. data(){
  267. return {
  268. pathname: location.pathname,
  269. list: [
  270. {
  271. item: '1',
  272. name: '域名管理',
  273. icon: 'fa fa-file-word-o',
  274. url: 'domain',
  275. target: '',
  276. },
  277. {
  278. item: '1',
  279. name: '任务管理',
  280. icon: 'fa fa-link',
  281. url: 'task',
  282. target: '',
  283. },
  284. ],
  285. }
  286. },
  287. methods: {
  288. //是否被选中
  289. pathselect: function (item, parent) {
  290. if (item.url == this.pathname) {
  291. parent ? parent.slideDown = true : null;
  292. return true
  293. }
  294. }
  295. }
  296. }
  297. var componentPage = {
  298. template: `<div class="st-pagination-box">
  299. <p class="mr-10 total">
  300. 共<span>&nbsp;{{total}}&nbsp;条</span>
  301. </p>
  302. <ul class="st-pagination">
  303. <template v-if="pageListTitle()">
  304. <li v-on:click=""><a v-on:click="devnowpage(1)" v-bind:class="page == 1 ? 'active' : ''" href="javascript:void(0);">1</a></li>
  305. <li><a>...</a></li>
  306. </template>
  307. <template v-for="(item, index) in pageListContent()">
  308. <template v-if="(p + index) <= total_page">
  309. <li><a v-on:click="devnowpage(set(p, index))" v-bind:class="set(p, index) == page ? 'active' : ''" href="javascript:void(0);">{{set(p, index)}}</a></li>
  310. </template>
  311. </template>
  312. <template v-if="pageListBottom()">
  313. <li><a>...</a></li>
  314. <li><a v-on:click="devnowpage(total_page)" v-bind:class="page == total_page ? 'active' : ''" href="javascript:void(0);">{{total_page}}</a></li>
  315. </template>
  316. </ul>
  317. <div class="st-page">
  318. <p>显示&nbsp;&nbsp;</p>
  319. <input
  320. type="text"
  321. v-bind:value="page_rows"
  322. name="page_rows"
  323. v-on:blur="setVal($event)"
  324. class="st-bdradius-4"/>
  325. <p>&nbsp;条&nbsp;跳至&nbsp;&nbsp;</p>
  326. <input
  327. type="text"
  328. v-bind:value="currentpage"
  329. name="currentpage"
  330. v-on:blur="setVal($event)"
  331. class="st-bdradius-4"/>
  332. <p>&nbsp;/&nbsp;
  333. <span>{{total_page}}</span>
  334. &nbsp;页
  335. </p>
  336. </div>
  337. </div>`,
  338. data(){
  339. return {
  340. currentpage: this.page,//跳转到第几页
  341. total_page: Math.ceil(this.total / this.perpage), // 总共多少页
  342. s: 2, //每页左右间隔几个,
  343. page_rows: this.perpage,
  344. }
  345. },
  346. props: [
  347. 'total', //总共多少条
  348. 'perpage', // 每次显示多少条
  349. 'page', // 当前第几页
  350. ],
  351. computed: {
  352. p: function () {
  353. var p = this.page - this.s;
  354. if ((p + this.s * 2) >= this.total_page) {
  355. p = this.total_page - this.s * 2
  356. }
  357. if (p <= 0) {
  358. p = 1
  359. }
  360. return p
  361. },
  362. },
  363. methods: {
  364. pageListTitle: function () {
  365. if (!(this.page - this.s <= 1)) {
  366. return true
  367. }
  368. return false
  369. },
  370. pageListBottom: function () {
  371. if (!(this.page + this.s >= this.total_page)) {
  372. if (this.s * 2 + 1 < this.total_page) {
  373. return true
  374. }
  375. }
  376. return false
  377. },
  378. pageListContent: function () {
  379. var p = this.page - this.s;
  380. return this.s * 2 + 1;
  381. },
  382. set: function (p, index) {
  383. return (p + index) <= 0 ? '1' : (p + index)
  384. },
  385. setVal: function (e) {
  386. var el = e.target || e.srcElement;
  387. if (isNaN(el.value)) {
  388. this.$refs.alertbox.show('格式不正确 请出入纯数字 MMP');
  389. return;
  390. }
  391. this[el.name] = el.value;
  392. /*如果修改了每页显示多少条 默认跳回第一页*/
  393. if (el.name == 'page_rows') {
  394. this.devnowpage(1)
  395. } else {
  396. this.devnowpage(el.value)
  397. }
  398. },
  399. devnowpage: function (page) {
  400. if (page > this.total_page) {
  401. page = this.total_page;
  402. } else if (page <= 0) {
  403. page = 1;
  404. }
  405. this.$emit('nowpage', page, this.page_rows);
  406. },
  407. },
  408. watch: {
  409. 'perpage': function (val) {
  410. this.total_page = Math.ceil(this.total / val);
  411. this.page_rows = val;
  412. // this.currentpage = 1;
  413. },
  414. 'total': function (val) {
  415. this.total_page = Math.ceil(val / this.perpage)
  416. },
  417. 'page': function (val) {
  418. this.currentpage = val;
  419. }
  420. }
  421. }