list.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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">
  59. <y-json-view :json="item.response_parameters"/>
  60. <!-- {{item.response_parameters}} change() -->
  61. </uni-td>
  62. <uni-td align="center">{{item.api_status}}</uni-td>
  63. <uni-td align="center">{{item.error_info}}</uni-td>
  64. <uni-td align="center">
  65. <view class="uni-group">
  66. <button @click="navigateTo('./edit?id='+item._id, false)" class="uni-button" size="mini"
  67. type="primary">修改</button>
  68. <button @click="confirmDelete(item._id)" class="uni-button" size="mini"
  69. type="warn">删除</button>
  70. </view>
  71. </uni-td>
  72. </uni-tr>
  73. </uni-table>
  74. <view class="uni-pagination-box">
  75. <uni-pagination show-icon :page-size="pagination.size" v-model="pagination.current"
  76. :total="pagination.count" @change="onPageChanged" />
  77. </view>
  78. </unicloud-db>
  79. </view>
  80. </view>
  81. </template>
  82. <script>
  83. import {
  84. enumConverter,
  85. filterToWhere
  86. } from '../../js_sdk/validator/cyt-logs.js';
  87. const db = uniCloud.database()
  88. // 表查询配置
  89. const dbOrderBy = '' // 排序字段
  90. const dbSearchFields = [] // 模糊搜索字段,支持模糊搜索的字段列表。联表查询格式: 主表字段名.副表字段名,例如用户表关联角色表 role.role_name
  91. // 分页配置
  92. const pageSize = 20
  93. const pageCurrent = 1
  94. const orderByMapping = {
  95. "ascending": "asc",
  96. "descending": "desc"
  97. }
  98. export default {
  99. data() {
  100. return {
  101. collectionList: "cyt-logs",
  102. query: '',
  103. where: '',
  104. orderby: dbOrderBy,
  105. orderByFieldName: "",
  106. selectedIndexs: [],
  107. options: {
  108. pageSize,
  109. pageCurrent,
  110. filterData: {},
  111. ...enumConverter
  112. },
  113. imageStyles: {
  114. width: 64,
  115. height: 64
  116. },
  117. exportExcel: {
  118. "filename": "cyt-logs.xls",
  119. "type": "xls",
  120. "fields": {
  121. "app_status": "app_status",
  122. "user_name": "user_name",
  123. "user_brand": "user_brand",
  124. "user_model": "user_model",
  125. "api_src": "api_src",
  126. "request_parameters": "request_parameters",
  127. "response_parameters": "response_parameters",
  128. "api_status": "api_status",
  129. "error_info": "error_info"
  130. }
  131. },
  132. exportExcelData: []
  133. }
  134. },
  135. onLoad() {
  136. this._filter = {}
  137. },
  138. onReady() {
  139. this.$refs.udb.loadData()
  140. },
  141. methods: {
  142. lookdetails(){
  143. },
  144. onqueryload(data) {
  145. this.exportExcelData = data
  146. },
  147. getWhere() {
  148. const query = this.query.trim()
  149. if (!query) {
  150. return ''
  151. }
  152. const queryRe = new RegExp(query, 'i')
  153. return dbSearchFields.map(name => queryRe + '.test(' + name + ')').join(' || ')
  154. },
  155. search() {
  156. const newWhere = this.getWhere()
  157. this.where = newWhere
  158. this.$nextTick(() => {
  159. this.loadData()
  160. })
  161. },
  162. loadData(clear = true) {
  163. this.$refs.udb.loadData({
  164. clear
  165. })
  166. },
  167. onPageChanged(e) {
  168. this.selectedIndexs.length = 0
  169. this.$refs.table.clearSelection()
  170. this.$refs.udb.loadData({
  171. current: e.current
  172. })
  173. },
  174. navigateTo(url, clear) {
  175. // clear 表示刷新列表时是否清除页码,true 表示刷新并回到列表第 1 页,默认为 true
  176. uni.navigateTo({
  177. url,
  178. events: {
  179. refreshData: () => {
  180. this.loadData(clear)
  181. }
  182. }
  183. })
  184. },
  185. // 多选处理
  186. selectedItems() {
  187. var dataList = this.$refs.udb.dataList
  188. return this.selectedIndexs.map(i => dataList[i]._id)
  189. },
  190. // 批量删除
  191. delTable() {
  192. this.$refs.udb.remove(this.selectedItems(), {
  193. success: (res) => {
  194. this.$refs.table.clearSelection()
  195. }
  196. })
  197. },
  198. // 多选
  199. selectionChange(e) {
  200. this.selectedIndexs = e.detail.index
  201. },
  202. confirmDelete(id) {
  203. this.$refs.udb.remove(id, {
  204. success: (res) => {
  205. this.$refs.table.clearSelection()
  206. }
  207. })
  208. },
  209. sortChange(e, name) {
  210. this.orderByFieldName = name;
  211. if (e.order) {
  212. this.orderby = name + ' ' + orderByMapping[e.order]
  213. } else {
  214. this.orderby = ''
  215. }
  216. this.$refs.table.clearSelection()
  217. this.$nextTick(() => {
  218. this.$refs.udb.loadData()
  219. })
  220. },
  221. filterChange(e, name) {
  222. this._filter[name] = {
  223. type: e.filterType,
  224. value: e.filter
  225. }
  226. let newWhere = filterToWhere(this._filter, db.command)
  227. if (Object.keys(newWhere).length) {
  228. this.where = newWhere
  229. } else {
  230. this.where = ''
  231. }
  232. this.$nextTick(() => {
  233. this.$refs.udb.loadData()
  234. })
  235. }
  236. }
  237. }
  238. </script>
  239. <style>
  240. </style>