frontend.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
  2. <script src="__CDN__/assets/addons/exam/js/vue.js"></script>
  3. <div id="app">
  4. <form class="form-horizontal" role="form" data-toggle="validator" method="POST" action="" id="setForm">
  5. <div class="form-group">
  6. <label class="control-label col-xs-12 col-sm-2">跳转页面:</label>
  7. <div class="col-xs-12 col-sm-8">
  8. <select name="info[url]" id="type" class="form-control" @change="changePage" v-model="currentPage">
  9. <option value="">请选择</option>
  10. <option v-for="(item, index) in pages" :value="item.path" :key="index">{{item.name}}</option>
  11. </select>
  12. </div>
  13. </div>
  14. <div v-if="currentItem && currentItem.params">
  15. <div class="form-group" v-for="(item, index) in currentItem.params" :key="index">
  16. <label class="control-label col-xs-12 col-sm-2">{{item.name}}{{item.require ? '(必填)' : ''}}:</label>
  17. <div class="col-xs-12 col-sm-8">
  18. <input v-if="item.type == 'string'" id="c-param_value" data-rule="required" class="form-control" :name="'info[params]['+item.field+']'" type="text" :value="item.value">
  19. <input v-if="item.type == 'selectpage'" id="c-param_value" :data-rule="item.require ? 'required' : ''" min="0" :data-source="item.selectpage.source" :data-field="item.selectpage.field" class="form-control selectpage" :name="'info[params]['+item.field+']'" type="text" :value="item.value">
  20. </div>
  21. </div>
  22. </div>
  23. <!--<input type="hidden" name="type" value="system">-->
  24. <div class="form-group layer-footer">
  25. <label class="control-label col-xs-12 col-sm-2"></label>
  26. <div class="col-xs-12 col-sm-8">
  27. <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
  28. <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
  29. </div>
  30. </div>
  31. </form>
  32. </div>
  33. <script>
  34. var faForm = null;
  35. var parentFrontendInfo = $('#c-front_info', parent.document).val();
  36. var pages = {:json_encode($pages, 256)};
  37. var app = new Vue({
  38. el: '#app',
  39. data: {
  40. pages: [],
  41. currentPage: '',
  42. currentItem: null,
  43. parentFrontendInfo: null,
  44. },
  45. created() {
  46. this.pages = pages
  47. this.getForm()
  48. if (parentFrontendInfo) {
  49. this.parentFrontendInfo = JSON.parse(parentFrontendInfo);
  50. this.currentPage = this.parentFrontendInfo.url;
  51. this.currentItem = this.pages.find(item => item.path === this.currentPage);
  52. if (this.currentItem && this.currentItem.params) {
  53. this.currentItem.params.forEach(item => {
  54. item.value = this.parentFrontendInfo.params[item.field];
  55. })
  56. }
  57. console.log('this.parentFrontendInfo', this.parentFrontendInfo)
  58. console.log('this.currentPage', this.currentPage)
  59. console.log('this.currentItem', this.currentItem)
  60. }
  61. },
  62. methods: {
  63. getForm() {
  64. var timer = setInterval(() => {
  65. if (faForm) {
  66. clearInterval(timer);
  67. console.log('faForm3', faForm);
  68. this.bindForm();
  69. }
  70. }, 500);
  71. },
  72. bindForm() {
  73. faForm.api.bindevent($("form[role=form]"), function(data, ret){
  74. console.log('bindevent', data, ret);
  75. if (ret.code == 1) {
  76. Fast.api.close(data);
  77. }
  78. return false;
  79. });
  80. },
  81. changePage(e) {
  82. console.log('changePage', e)
  83. this.currentPage = e.target.value;
  84. this.currentItem = this.pages.find(item => item.path === this.currentPage);
  85. setTimeout(() => {
  86. if (faForm) {
  87. this.bindForm();
  88. }
  89. }, 500);
  90. },
  91. // 验证
  92. valid() {
  93. }
  94. }
  95. });
  96. </script>