mp_page.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <div>
  3. <use-table ref="tbl"></use-table>
  4. <div class="container padding_b_0">
  5. <div class="dflex_wrap">
  6. <div class="dflex_vertical_c margin_r_40 margin_b_20">
  7. <div class="search_name">页面名称:</div>
  8. <el-input v-model="req.name" placeholder="请输入" class="search_input" @input="loadData"></el-input>
  9. </div>
  10. <div class="dflex_vertical_c margin_r_40 margin_b_20">
  11. <div class="search_name">URL地址:</div>
  12. <el-input v-model="req.url" placeholder="请输入" class="search_input" @input="loadData"></el-input>
  13. </div>
  14. <div class="dflex_vertical_c margin_r_40 margin_b_20" v-if="advancedSearch">
  15. <div class="search_name">页面类型:</div>
  16. <el-select v-model="req.type" class="search_input" @change="loadData">
  17. <el-option v-for="(item, idx) in typeOptions" :key="idx" :label="item.label"
  18. :value="item.value"></el-option>
  19. </el-select>
  20. </div>
  21. <div class="dflex_vertical_c margin_r_40 margin_b_20" v-if="advancedSearch">
  22. <div class="search_name">状态:</div>
  23. <el-select v-model="req.state" class="search_input" @change="loadData">
  24. <el-option v-for="(item, idx) in stateOptions" :key="idx" :label="item.label"
  25. :value="item.value"></el-option>
  26. </el-select>
  27. </div>
  28. <el-button size="mini" class="search_btn margin_b_20 margin_r_40" @click="loadData">搜索</el-button>
  29. <div class="search_advanced margin_b_20" @click="advancedSearch = !advancedSearch"
  30. v-if="!advancedSearch">高级筛选</div>
  31. <div class="search_common margin_b_20" @click="advancedSearch = !advancedSearch" v-if="advancedSearch">
  32. 常用筛选</div>
  33. </div>
  34. </div>
  35. <div class="container use-table">
  36. <div class="dflex_sb margin_b_15">
  37. <div>
  38. <el-button class="batch_btn padding0" @click="removes">删除</el-button>
  39. </div>
  40. <el-button class="add_btn pos_r padding0" icon="iconfont iconxinzeng" @click="toAdd">新增</el-button>
  41. </div>
  42. <el-table :height="tblHeight" :data="tableDatas" @selection-change="handleSelectionChange"
  43. highlight-current-row>
  44. <el-table-column type="selection"></el-table-column>
  45. <el-table-column label="排序" width="200" align="center">
  46. <template slot-scope="scope">
  47. <el-input-number size="small" :min="1" v-model="scope.row.sort" @change="sortChange(scope.row)"
  48. @blur="sortChange(scope.row)"></el-input-number>
  49. </template>
  50. </el-table-column>
  51. <el-table-column property="name" label="页面名称" align="center"></el-table-column>
  52. <el-table-column property="type" label="页面类型" align="center"></el-table-column>
  53. <el-table-column property="url" label="url地址" align="center"></el-table-column>
  54. <el-table-column property="remark" label="备注" align="center"></el-table-column>
  55. <el-table-column label="状态" align="center">
  56. <template slot-scope="scope">
  57. <el-tooltip :content="scope.row.state == '启用' ? '点击禁用' : '点击启用'" placement="top"
  58. :hide-after="1000" :enterable="false" effect="light">
  59. <el-switch v-model="scope.row.state" active-color="#ff6a6c" inactive-color="#bbb"
  60. active-value="启用" inactive-value="禁用" @change="stateChange(scope.row)"></el-switch>
  61. </el-tooltip>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="操作" align="center" fixed="right">
  65. <template slot-scope="scope">
  66. <el-tooltip content="编辑" placement="top" :hide-after="1000" :enterable="false" effect="light">
  67. <el-button type="text" icon="iconfont iconbianji" class="bbb"
  68. @click="toEdit(scope.row._id)"></el-button>
  69. </el-tooltip>
  70. <el-tooltip content="删除" placement="top" :hide-after="1000" :enterable="false" effect="light">
  71. <el-button type="text" icon="iconfont iconshanchu" class="bbb"
  72. @click="remove(scope.row._id)"></el-button>
  73. </el-tooltip>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <el-pagination :current-page="req.page" :page-sizes="[10, 20, 30, 50, 100]" :page-size="req.rows"
  78. layout="total, sizes, prev, pager, next, jumper" :total="tableTotal" @size-change="sizeChange"
  79. @current-change="currentChange"></el-pagination>
  80. </div>
  81. </div>
  82. </template>
  83. <script>
  84. const __name = 'usemall-app-wxmini-page';
  85. export default {
  86. data() {
  87. return {
  88. advancedSearch: false,
  89. typeOptions: [{
  90. value: '',
  91. label: '全部'
  92. },
  93. {
  94. value: '网页',
  95. label: '网页'
  96. },
  97. {
  98. value: '页面',
  99. label: '页面'
  100. }
  101. ],
  102. stateOptions: [{
  103. value: '',
  104. label: '全部'
  105. },
  106. {
  107. value: '启用',
  108. label: '启用'
  109. },
  110. {
  111. value: '禁用',
  112. label: '禁用'
  113. }
  114. ],
  115. req: {
  116. page: 1,
  117. rows: 10,
  118. orderby: 'sort asc',
  119. name: '',
  120. url: '',
  121. type: '',
  122. state: ''
  123. },
  124. tblHeight: 0,
  125. tableDatas: [],
  126. tableTotal: 0,
  127. selectDatas: []
  128. };
  129. },
  130. methods: {
  131. async loadData() {
  132. await this.$db[__name]
  133. .whereif(this.req.name, {
  134. name: new RegExp(this.req.name)
  135. })
  136. .whereif(this.req.type, {
  137. type: this.req.type
  138. })
  139. .whereif(this.req.url, {
  140. url: new RegExp(this.req.url)
  141. })
  142. .whereif(this.req.state, {
  143. state: this.req.state
  144. })
  145. .totable(this.req)
  146. .then(res => {
  147. if (res.code == 200) {
  148. this.tableDatas = res.datas.rows;
  149. this.tableTotal = res.datas.total;
  150. }
  151. });
  152. },
  153. toAdd() {
  154. uni.navigateTo({
  155. url: `/pages/app/mp/mp_page_add_edit?tab=添加小程序`,
  156. events: {
  157. refreshData: () => {
  158. this.loadData();
  159. }
  160. }
  161. });
  162. },
  163. toEdit(id) {
  164. uni.navigateTo({
  165. url: `/pages/app/mp/mp_page_add_edit?id=${id}&tab=编辑小程序`,
  166. events: {
  167. refreshData: () => {
  168. this.loadData();
  169. }
  170. }
  171. });
  172. },
  173. remove(id) {
  174. this.$confirm('此操作将永久删除该数据!', '提示', {
  175. confirmButtonText: '确定',
  176. cancelButtonText: '取消',
  177. type: 'warning'
  178. }).then(() => {
  179. this.$db[__name].remove(id).then(res => {
  180. if (res.code == 200) {
  181. this.loadData();
  182. }
  183. });
  184. });
  185. },
  186. selectionChange(datas) {
  187. this.selectDatas = datas;
  188. },
  189. removes() {
  190. if (this.selectDatas.length <= 0) {
  191. this.$message('请勾选需要删除的数据');
  192. return;
  193. }
  194. let ids = this.selectDatas.map(x => x._id);
  195. this.$confirm('此操作将永久删除勾选数据!', '提示', {
  196. confirmButtonText: '确定',
  197. cancelButtonText: '取消',
  198. type: 'warning'
  199. }).then(() => {
  200. this.$db[__name]
  201. .where({
  202. _id: this.$db.$cmd.in(ids)
  203. })
  204. .remove()
  205. .then(res => {
  206. if (res.code == 200) {
  207. this.loadData();
  208. }
  209. });
  210. });
  211. },
  212. stateChange(row) {
  213. this.$db[__name].update(row._id, {
  214. state: row.state
  215. }).then(res => {
  216. if (res.code == 200) this.loadData();
  217. });
  218. },
  219. sortChange(row) {
  220. if (row.sort == '') {
  221. return;
  222. }
  223. this.$db[__name].update(row._id, {
  224. sort: row.sort
  225. }).then(res => {
  226. if (res.code == 200) this.loadData();
  227. });
  228. },
  229. sizeChange(size) {
  230. this.req.rows = size;
  231. this.loadData();
  232. },
  233. currentChange(current) {
  234. this.req.page = current;
  235. this.loadData();
  236. }
  237. },
  238. created() {
  239. this.loadData();
  240. },
  241. updated() {
  242. if (!this.tblHeight) {
  243. this.tblHeight = this.$refs.tbl.tblHeight;
  244. }
  245. }
  246. };
  247. </script>
  248. <style></style>