list.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view>
  3. <view class="uni-header">
  4. <view class="uni-group">
  5. <view class="uni-title"></view>
  6. <view class="uni-sub-title"></view>
  7. </view>
  8. <view class="uni-group">
  9. <input class="uni-search" type="text" v-model="query" @confirm="search" placeholder="请输入搜索内容" />
  10. <button class="uni-button" type="default" size="mini" @click="search">搜索</button>
  11. <button class="uni-button" type="default" size="mini" @click="navigateTo('./add')">新增</button>
  12. <button class="uni-button" type="default" size="mini" :disabled="!selectedIndexs.length"
  13. @click="delTable">批量删除</button>
  14. <download-excel class="hide-on-phone" :fields="exportExcel.fields" :data="exportExcelData"
  15. :type="exportExcel.type" :name="exportExcel.filename">
  16. <button class="uni-button" type="primary" size="mini">导出 Excel</button>
  17. </download-excel>
  18. </view>
  19. </view>
  20. <view class="uni-container">
  21. <unicloud-db ref="udb" :collection="collectionList"
  22. field="app_status,user_name,user_brand,user_model,api_src,request_parameters,response_parameters,api_status,error_info"
  23. :where="where" page-data="replace" :orderby="orderby" :getcount="true" :page-size="options.pageSize"
  24. :page-current="options.pageCurrent" v-slot:default="{data,pagination,loading,error,options}"
  25. :options="options" loadtime="manual" @load="onqueryload">
  26. <uni-table ref="table" :loading="loading" :emptyText="error.message || '没有更多数据'" border stripe
  27. type="selection" @selection-change="selectionChange">
  28. <uni-tr>
  29. <uni-th align="center" filter-type="search" @filter-change="filterChange($event, 'app_status')"
  30. sortable @sort-change="sortChange($event, 'app_status')">app_status</uni-th>
  31. <uni-th align="center" filter-type="search" @filter-change="filterChange($event, 'user_name')"
  32. sortable @sort-change="sortChange($event, 'user_name')">user_name</uni-th>
  33. <uni-th align="center" filter-type="search" @filter-change="filterChange($event, 'user_brand')"
  34. sortable @sort-change="sortChange($event, 'user_brand')">user_brand</uni-th>
  35. <uni-th align="center" filter-type="search" @filter-change="filterChange($event, 'user_model')"
  36. sortable @sort-change="sortChange($event, 'user_model')">user_model</uni-th>
  37. <uni-th align="center" filter-type="search" @filter-change="filterChange($event, 'api_src')"
  38. sortable @sort-change="sortChange($event, 'api_src')">api_src</uni-th>
  39. <uni-th align="center" filter-type="search"
  40. @filter-change="filterChange($event, 'request_parameters')" sortable
  41. @sort-change="sortChange($event, 'request_parameters')">request_parameters</uni-th>
  42. <uni-th align="center" filter-type="search"
  43. @filter-change="filterChange($event, 'response_parameters')" sortable
  44. @sort-change="sortChange($event, 'response_parameters')">response_parameters</uni-th>
  45. <uni-th align="center" filter-type="search" @filter-change="filterChange($event, 'api_status')"
  46. sortable @sort-change="sortChange($event, 'api_status')">api_status</uni-th>
  47. <uni-th align="center" filter-type="search" @filter-change="filterChange($event, 'error_info')"
  48. sortable @sort-change="sortChange($event, 'error_info')">error_info</uni-th>
  49. <uni-th align="center">操作</uni-th>
  50. </uni-tr>
  51. <uni-tr v-for="(item,index) in data" :key="index">
  52. <uni-td align="center">{{item.app_status}}</uni-td>
  53. <uni-td align="center">{{item.user_name}}</uni-td>
  54. <uni-td align="center">{{item.user_brand}}</uni-td>
  55. <uni-td align="center">{{item.user_model}}</uni-td>
  56. <uni-td align="center">{{item.api_src}}</uni-td>
  57. <uni-td align="center">{{item.request_parameters}}</uni-td>
  58. <uni-td align="center">{{item.response_parameters}} change()</uni-td>
  59. <uni-td align="center">{{item.api_status}}</uni-td>
  60. <uni-td align="center">{{item.error_info}}</uni-td>
  61. <uni-td align="center">
  62. <view class="uni-group">
  63. <button @click="navigateTo('./edit?id='+item._id, false)" class="uni-button" size="mini"
  64. type="primary">修改</button>
  65. <button @click="confirmDelete(item._id)" class="uni-button" size="mini"
  66. type="warn">删除</button>
  67. </view>
  68. </uni-td>
  69. </uni-tr>
  70. </uni-table>
  71. <view class="uni-pagination-box">
  72. <uni-pagination show-icon :page-size="pagination.size" v-model="pagination.current"
  73. :total="pagination.count" @change="onPageChanged" />
  74. </view>
  75. </unicloud-db>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. import {
  81. enumConverter,
  82. filterToWhere
  83. } from '../../js_sdk/validator/cyt-logs.js';
  84. const db = uniCloud.database()
  85. // 表查询配置
  86. const dbOrderBy = '' // 排序字段
  87. const dbSearchFields = [] // 模糊搜索字段,支持模糊搜索的字段列表。联表查询格式: 主表字段名.副表字段名,例如用户表关联角色表 role.role_name
  88. // 分页配置
  89. const pageSize = 20
  90. const pageCurrent = 1
  91. const orderByMapping = {
  92. "ascending": "asc",
  93. "descending": "desc"
  94. }
  95. export default {
  96. data() {
  97. return {
  98. collectionList: "cyt-logs",
  99. query: '',
  100. where: '',
  101. orderby: dbOrderBy,
  102. orderByFieldName: "",
  103. selectedIndexs: [],
  104. options: {
  105. pageSize,
  106. pageCurrent,
  107. filterData: {},
  108. ...enumConverter
  109. },
  110. imageStyles: {
  111. width: 64,
  112. height: 64
  113. },
  114. exportExcel: {
  115. "filename": "cyt-logs.xls",
  116. "type": "xls",
  117. "fields": {
  118. "app_status": "app_status",
  119. "user_name": "user_name",
  120. "user_brand": "user_brand",
  121. "user_model": "user_model",
  122. "api_src": "api_src",
  123. "request_parameters": "request_parameters",
  124. "response_parameters": "response_parameters",
  125. "api_status": "api_status",
  126. "error_info": "error_info"
  127. }
  128. },
  129. exportExcelData: []
  130. }
  131. },
  132. onLoad() {
  133. this._filter = {}
  134. },
  135. onReady() {
  136. this.$refs.udb.loadData()
  137. },
  138. methods: {
  139. onqueryload(data) {
  140. this.exportExcelData = data
  141. },
  142. getWhere() {
  143. const query = this.query.trim()
  144. if (!query) {
  145. return ''
  146. }
  147. const queryRe = new RegExp(query, 'i')
  148. return dbSearchFields.map(name => queryRe + '.test(' + name + ')').join(' || ')
  149. },
  150. search() {
  151. const newWhere = this.getWhere()
  152. this.where = newWhere
  153. this.$nextTick(() => {
  154. this.loadData()
  155. })
  156. },
  157. loadData(clear = true) {
  158. this.$refs.udb.loadData({
  159. clear
  160. })
  161. },
  162. onPageChanged(e) {
  163. this.selectedIndexs.length = 0
  164. this.$refs.table.clearSelection()
  165. this.$refs.udb.loadData({
  166. current: e.current
  167. })
  168. },
  169. navigateTo(url, clear) {
  170. // clear 表示刷新列表时是否清除页码,true 表示刷新并回到列表第 1 页,默认为 true
  171. uni.navigateTo({
  172. url,
  173. events: {
  174. refreshData: () => {
  175. this.loadData(clear)
  176. }
  177. }
  178. })
  179. },
  180. // 多选处理
  181. selectedItems() {
  182. var dataList = this.$refs.udb.dataList
  183. return this.selectedIndexs.map(i => dataList[i]._id)
  184. },
  185. // 批量删除
  186. delTable() {
  187. this.$refs.udb.remove(this.selectedItems(), {
  188. success: (res) => {
  189. this.$refs.table.clearSelection()
  190. }
  191. })
  192. },
  193. // 多选
  194. selectionChange(e) {
  195. this.selectedIndexs = e.detail.index
  196. },
  197. confirmDelete(id) {
  198. this.$refs.udb.remove(id, {
  199. success: (res) => {
  200. this.$refs.table.clearSelection()
  201. }
  202. })
  203. },
  204. sortChange(e, name) {
  205. this.orderByFieldName = name;
  206. if (e.order) {
  207. this.orderby = name + ' ' + orderByMapping[e.order]
  208. } else {
  209. this.orderby = ''
  210. }
  211. this.$refs.table.clearSelection()
  212. this.$nextTick(() => {
  213. this.$refs.udb.loadData()
  214. })
  215. },
  216. filterChange(e, name) {
  217. this._filter[name] = {
  218. type: e.filterType,
  219. value: e.filter
  220. }
  221. let newWhere = filterToWhere(this._filter, db.command)
  222. if (Object.keys(newWhere).length) {
  223. this.where = newWhere
  224. } else {
  225. this.where = ''
  226. }
  227. this.$nextTick(() => {
  228. this.$refs.udb.loadData()
  229. })
  230. }
  231. }
  232. }
  233. </script>
  234. <style>
  235. </style>