PowersModal.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="register"
  5. title="设置场景权限"
  6. @cancel="resetFields"
  7. @ok="handleSubmit"
  8. :width="1000"
  9. :min-height="0"
  10. >
  11. <div class="pt-2px pr-3px">{{roleId}}
  12. <BasicForm @register="registerForm" :model="model">
  13. <template #text="{ model, field }">
  14. {{ model[field] }}
  15. </template>
  16. </BasicForm>
  17. <BasicTable v-show="fileFlow.showList" class="powesrTable" @register="registerTable">
  18. <template #toolbar>
  19. <a-button type="primary" v-if="getCheckPerm('scenes-powers-add')" @click="addPowes"> 新增 </a-button>
  20. </template>
  21. <template #action="{ record }">
  22. <TableAction
  23. stopButtonPropagation
  24. :actions="[
  25. {
  26. label: '编辑',
  27. ifShow: getCheckPerm('scenes-powers-edit'),
  28. onClick: handleEdit.bind(null, record),
  29. },
  30. {
  31. label: '删除',
  32. //icon: 'ic:outline-delete-outline',
  33. disabled: record.canDel != 0,
  34. color: 'error',
  35. ifShow: getCheckPerm('scenes-powers-delete'),
  36. onClick: handleDelete.bind(null, record),
  37. },
  38. ]"
  39. />
  40. </template>
  41. </BasicTable>
  42. <detailModal @register="registerDetail" @update="reload" />
  43. </div>
  44. </BasicModal>
  45. </template>
  46. <script lang="ts">
  47. import { defineComponent, ref, computed, onMounted, reactive } from 'vue';
  48. import { BasicModal, useModalInner } from '/@/components/Modal';
  49. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  50. import { useMessage } from '/@/hooks/web/useMessage';
  51. import { sceneMove } from '/@/api/operate';
  52. import { useModal } from '/@/components/Modal';
  53. import { useI18n } from '/@/hooks/web/useI18n';
  54. import detailModal from './detailModal.vue';
  55. import { usePermissionStore } from '/@/store/modules/permission';
  56. import { getAuthList, getAuthType, setAuthType, delAuth } from '/@/api/operate';
  57. import { BasicTable, useTable, TableAction, BasicColumn } from '/@/components/Table';
  58. import { useUserStore } from '/@/store/modules/user';
  59. import dayjs from 'dayjs';
  60. const { t } = useI18n();
  61. export default defineComponent({
  62. components: { BasicModal, BasicForm, BasicTable, TableAction, detailModal },
  63. props: {
  64. userData: { type: Object },
  65. },
  66. emits: ['update', 'register'],
  67. setup(props, { emit }) {
  68. const modelRef = ref({});
  69. const numRef = ref(null);
  70. const fileFlow = reactive({
  71. showList: true,
  72. });
  73. const [registerDetail, { openModal: openDetaileModal }] = useModal();
  74. const columns: BasicColumn[] = [
  75. {
  76. title: '警员ID',
  77. dataIndex: 'ryId',
  78. width: 150,
  79. },
  80. {
  81. title: '姓名',
  82. dataIndex: 'ryNickName',
  83. width: 180,
  84. },
  85. {
  86. title: '查看权限',
  87. dataIndex: 'lookAuth',
  88. customRender: ({ record }) => {
  89. return record.lookAuth == 1 ? '不限时间' : record.lookAuth == 0 ? '无权' : dayjs().isBefore(dayjs(record.lookEndTime)) ? '已过期' : `${dayjs(record.lookEndTime).format('YYYY-MM-DD HH:mm')} 截止`;
  90. },
  91. width: 150,
  92. },
  93. {
  94. title: '编辑权限',
  95. dataIndex: 'editAuth',
  96. customRender: ({ record }) => {
  97. return record.editAuth == 1 ? '不限时间' : record.editAuth == 0 ? '无权' : dayjs().isBefore(dayjs(record.editEndTime)) ? '已过期' : `${dayjs(record.editEndTime).format('YYYY-MM-DD HH:mm')} 截止`;
  98. },
  99. width: 150,
  100. },
  101. {
  102. title: '可授权他人',
  103. dataIndex: 'canLook',
  104. customRender: ({ record }) => {
  105. return record.canEditLook == 1 ? '编辑和查看' : record.canAuthLook == 1 ? '查看' : `无权`;
  106. },
  107. width: 120,
  108. },
  109. {
  110. title: '操作',
  111. dataIndex: 'action',
  112. slots: { customRender: 'action' },
  113. ifShow: true,
  114. fixed: 'right',
  115. flag: 'ACTION',
  116. width: 80,
  117. },
  118. ];
  119. const permissionStore = usePermissionStore();
  120. const userStore = useUserStore();
  121. const userName = computed(() => userStore.getUserInfo?.userName);
  122. const roleId = computed(() => userStore.getUserInfo?.roleId);
  123. const { getCheckPerm } = permissionStore;
  124. const { createMessage, createConfirm } = useMessage();
  125. const [registerTable, { reload, getRawDataSource }] = useTable({
  126. api: getAuthList,
  127. title: `已授权列表`,
  128. columns: columns,
  129. useSearchForm: false,
  130. immediate: false,
  131. searchInfo: {
  132. num: numRef,
  133. },
  134. // afterFetch: (T) => {
  135. // let { authType } = getRawDataSource();
  136. // setFieldsValue({
  137. // authType,
  138. // });
  139. // fileFlow.showList = authType ? false : true;
  140. // return T;
  141. // },
  142. showTableSetting: true,
  143. tableSetting: { fullScreen: true },
  144. showIndexColumn: false,
  145. canResize: true,
  146. rowKey: 'id',
  147. fetchSetting: {
  148. pageField: 'pageNum',
  149. sizeField: 'pageSize',
  150. listField: 'list',
  151. totalField: 'total',
  152. },
  153. });
  154. const schemas: FormSchema[] = [
  155. {
  156. field: 'authType',
  157. component: 'RadioGroup',
  158. defaultValue: 0,
  159. componentProps: {
  160. options: [
  161. { label: '授权用户', value: 0 },
  162. { label: '公开浏览', value: 1 },
  163. ],
  164. onChange: (value) => {
  165. fileFlow.showList = value.target.value ? false : true;
  166. console.log('fileFlow.showList', value.target.value, fileFlow.showList);
  167. },
  168. },
  169. label: '授权方式',
  170. colProps: {
  171. span: 24,
  172. },
  173. },
  174. ];
  175. const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({
  176. labelWidth: 80,
  177. schemas,
  178. showActionButtonGroup: false,
  179. actionColOptions: {
  180. span: 24,
  181. },
  182. });
  183. onMounted(() => {});
  184. let addListFunc = () => {};
  185. const [register, { closeModal }] = useModalInner((data) => {
  186. data && onDataReceive(data);
  187. });
  188. async function onDataReceive(data) {
  189. modelRef.value = data;
  190. numRef.value = data.num;
  191. reload();
  192. resetFields();
  193. const { authType } = await getAuthType({num:numRef.value});;
  194. fileFlow.showList = authType ? false : true;
  195. setFieldsValue({
  196. type: data.sceneName,
  197. authType,
  198. });
  199. console.log('roleId', roleId.value, (userName.value != data.userName || roleId.value != 1 || roleId.value != 45));
  200. updateSchema({
  201. field: 'authType',
  202. componentProps: {
  203. disabled: !(userName.value == data.userName || roleId.value == 1 || roleId.value == 45),
  204. },
  205. });
  206. }
  207. const handleSubmit = async () => {
  208. try {
  209. const params = await validate();
  210. console.log('res', params);
  211. const res = await setAuthType({num:numRef.value,...params});
  212. console.log('res', res);
  213. closeModal();
  214. resetFields();
  215. createMessage.success('权限设置成功');
  216. emit('update');
  217. } catch (error) {
  218. console.log('not passing', error);
  219. }
  220. };
  221. function addPowes() {
  222. openDetaileModal(true, { num: modelRef.value.num});
  223. }
  224. function handleEdit(record: Recordable) {
  225. openDetaileModal(true, record);
  226. }
  227. async function handleDelete(record: Recordable) {
  228. createConfirm({
  229. title: '删除',
  230. content: `确定要删除 ${record.ryNickName} 吗?`,
  231. onOk: async () => {
  232. await delAuth({ id: record.id })
  233. createMessage.success('删除成功');
  234. reload();
  235. },
  236. });
  237. }
  238. return {
  239. register,
  240. schemas,
  241. registerForm,
  242. model: modelRef,
  243. fileFlow,
  244. handleSubmit,
  245. addListFunc,
  246. resetFields,
  247. t,
  248. getCheckPerm,
  249. handleEdit,
  250. handleDelete,
  251. registerTable,
  252. registerDetail,
  253. openDetaileModal,
  254. addPowes,
  255. reload,
  256. userName,
  257. };
  258. },
  259. });
  260. </script>
  261. <style lang="less" scoped>
  262. .powesrTable {
  263. }
  264. </style>